Let behaviors read and set tilemap cells while the game runs (#135)
A behavior could move sprites around but had no way to look at or
change the tilemap it was standing on. Doors, breakable blocks and
"is there ground ahead?" checks all need that.
- New nodes Tile at, Set tile, World to cell and Cell to world. The
conversion honours position, rotation, scale and mirroring of the
placed map. A small Tile literal node lets a graph compare what it
read against a fixed tile.
- The layer is picked by name from all tilemap layers in the project
through a new field kind. "First layer" takes the map's first one.
Because layer is an input, a text can also be wired in.
- Each placement keeps only its edited cells in liveTilemap.ts,
layered over the asset's cells. A second placement of the same map
stays untouched, and the asset itself is never written.
- A read sees a Set tile from earlier in the same flow. Drawing picks
up the edit at once and neighbouring autotile edges adapt.
- Solids see the edits straight away, so a Move in the same frame
already hits the new cell. Rapier rebuilds its shapes on the next
step.
- After Stop the map is back to what was painted. The editor run shows
the edit in the scene view while it lasts and does not touch the
project.
- An unwired tilemap input means no map, like Get position. Cells
outside the grid are refused and done reports false.
Tests:
- ./check.sh: 155 files, 2271 tests, CHECK EXIT 0 (before 2245).
- tests/core/tile-access.test.ts (14), one physics test for a floor
set at runtime, catalog entries for the five nodes.
- e2e 39,40: all passed, 86 checks (before 81), five new in 40s.
- Counter-checks: collision ignoring edits fails 3 unit tests, the
solids cache missing same-tick edits fails only the "at once" test,
drawing ignoring edits fails the 2 drawing checks, the editor run
not reporting a new tile fails only its check.
- 40s uses a still tile. The animated fixture tile redraws every frame
and hid the last counter-check at first.
- Check total 1351 + 5 = 1356, computed. CI confirmed 1351 at cb32b4b.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb32b4bc23
commit
d444b27fae
22 files changed
+848
-20
No files matched your search
@@ -106,6 +106,8 @@ const physicsDouble = (): PhysicsDouble => {
|
||||
};
|
||||
const physicsCalls = (ctx: FakeContext) => (ctx.physics as PhysicsDouble).calls;
|
||||
const crate = fakeEntity('crate');
|
||||
/** A tilemap of 4 x 2 cells of 10 units, placed at (100, 50). */
|
||||
const map = { ...fakeEntity('map', 100), y: 50, props: { columns: 4, rows: 2, tileSize: 10 } };
|
||||
|
||||
const pointer = (overrides: Partial<NodeContext['pointer']>): Partial<NodeContext> => ({
|
||||
pointer: { ...NO_POINTER, ...overrides },
|
||||
@@ -1157,6 +1159,76 @@ const CASES: Record<string, Case[]> = {
|
||||
},
|
||||
{ name: 'no object is a no-op that continues', inputs: { object: null, seconds: 1 }, next: 'exec' },
|
||||
],
|
||||
TileAt: [
|
||||
{
|
||||
name: 'asks the context for the cell, floored to whole cells, and says what lies there (#135)',
|
||||
inputs: { tilemap: map, layer: 'Ground', cellX: 2.7, cellY: 1 },
|
||||
context: {
|
||||
tileAt: (target, layer, cell) => {
|
||||
expect([target.id, layer, cell]).toEqual(['map', 'Ground', { x: 2, y: 1 }]);
|
||||
return 'grass';
|
||||
},
|
||||
},
|
||||
outputs: { tile: 'grass', empty: false },
|
||||
},
|
||||
{
|
||||
name: 'an empty cell, and one the context cannot answer, both read as empty',
|
||||
inputs: { tilemap: map, layer: '', cellX: 0, cellY: 0 },
|
||||
context: { tileAt: () => null },
|
||||
outputs: { tile: '', empty: true },
|
||||
},
|
||||
{ name: 'no tilemap is an empty cell', inputs: { tilemap: null }, outputs: { tile: '', empty: true } },
|
||||
],
|
||||
SetTile: [
|
||||
{
|
||||
name: 'hands the cell and the tile to the context and says whether it took them',
|
||||
inputs: { tilemap: map, layer: 'Ground', cellX: 3, cellY: 4.5, tile: 'door' },
|
||||
context: {
|
||||
setTile: (target, layer, cell, tile) => {
|
||||
expect([target.id, layer, cell, tile]).toEqual(['map', 'Ground', { x: 3, y: 4 }, 'door']);
|
||||
return true;
|
||||
},
|
||||
},
|
||||
next: 'exec',
|
||||
outputs: { done: true },
|
||||
},
|
||||
{
|
||||
name: 'no tilemap sets nothing and continues',
|
||||
inputs: { tilemap: null },
|
||||
next: 'exec',
|
||||
outputs: { done: false },
|
||||
},
|
||||
],
|
||||
WorldToCell: [
|
||||
{
|
||||
name: 'finds the cell under a world point of a moved map, and whether it is on the grid',
|
||||
// 4 x 2 cells of 10 around (100, 50): the grid runs from (80, 40) to (120, 60).
|
||||
inputs: { tilemap: map, x: 95, y: 55 },
|
||||
context: { isTilemap: () => true },
|
||||
outputs: { cellX: 1, cellY: 1, inside: true },
|
||||
},
|
||||
{
|
||||
name: 'a point off the grid still names a cell, but not an inside one',
|
||||
inputs: { tilemap: map, x: 75, y: 45 },
|
||||
context: { isTilemap: () => true },
|
||||
outputs: { cellX: -1, cellY: 0, inside: false },
|
||||
},
|
||||
{
|
||||
name: 'something that is no tilemap has no cells',
|
||||
inputs: { tilemap: map, x: 95, y: 55 },
|
||||
outputs: { cellX: 0, cellY: 0, inside: false },
|
||||
},
|
||||
],
|
||||
CellToWorld: [
|
||||
{
|
||||
name: 'puts out the middle of the cell in world units',
|
||||
inputs: { tilemap: map, cellX: 1, cellY: 1 },
|
||||
context: { isTilemap: () => true },
|
||||
outputs: { x: 95, y: 55 },
|
||||
},
|
||||
{ name: 'no tilemap answers the origin', inputs: { tilemap: null, cellX: 1 }, outputs: { x: 0, y: 0 } },
|
||||
],
|
||||
Tile: [{ name: 'hands out the tile chosen', params: { value: 'door' }, outputs: { value: 'door' } }],
|
||||
Spawn: [
|
||||
{
|
||||
name: 'no asset chosen logs a hint and continues with no object',
|
||||
|
||||
Reference in new issue
Block a user