Let behaviors read and set tilemap cells while the game runs (#135)
game-maker / gate (push) Successful in 2m59s
game-maker / suite (push) Successful in 9m22s

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:
adminandClaude Opus 5.5 committed 2026-09-23 20:45:29 +02:00
1 parent cb32b4bc23
commit d444b27fae
22 files changed
+848 -20

No files matched your search

+12
View File
@@ -179,6 +179,18 @@ export interface NodeContext {
): RayOutcome[];
/** Lets `target` fall through one-way colliders and tiles for `seconds` (#155). */
ignoreOneWay(target: EntityHandle, seconds: number): void;
/** Whether `target` is a placed tilemap – what the tile nodes act on (#135). */
isTilemap(target: EntityHandle): boolean;
/**
* The tile id in a cell of a placed tilemap, `''` for an empty one; null when `target` is no
* tilemap, has no layer of that name (`''` = its first) or the cell lies outside its grid.
*/
tileAt(target: EntityHandle, layer: string, cell: { x: number; y: number }): string | null;
/**
* Puts a tile into that cell, `''` empties it; false where `tileAt` answers null or the id is no
* tile. Only this placement changes, and only for the run (see `model/liveTilemap.ts`).
*/
setTile(target: EntityHandle, layer: string, cell: { x: number; y: number }, tileId: string): boolean;
/** Absent where nothing is simulated: the editor run, and a test double that does not ask for it. */
physics?: PhysicsControl;
log(message: string): void;
+125
View File
@@ -0,0 +1,125 @@
/**
* A placed tilemap read and changed by a behavior (#135). The cells a node sets belong to that one
* placement and to the run: they are drawn and block at once, and after Stop the map is the one
* that was painted (see `model/liveTilemap.ts`).
*/
import { cellToWorld, worldToCell } from '../../../model/liveTilemap';
import { worldMatrixOf } from '../../NodeContext';
import type { NodeDef, PortDef } from '../../NodeRegistry';
import { asEntity, asNumber, asString, type Value } from '../../values';
import { bool, exec, int, num, obj } from '../shared';
/** The layer by name, picked from the layers of every map in the project; none = the first. */
const layerPort = (): PortDef => ({
key: 'layer',
label: 'layer',
type: 'string',
field: { key: 'layer', label: 'Layer', kind: 'tileLayer', default: '' },
});
/** A tile asset; unconnected, it shows the tile picker, and none chosen empties the cell. */
const tilePort = (key = 'tile', label = key): PortDef => ({
key,
label,
type: 'string',
field: { key, label: 'Tile', kind: 'asset', default: '', assetTypes: ['tile'] },
});
const CELL_INPUTS: readonly PortDef[] = [int('cellX', 0, 'cell x'), int('cellY', 0, 'cell y')];
/** A cell counts in whole columns and rows, so a fraction arriving over an edge is floored. */
const cellOf = (x: Value | undefined, y: Value | undefined) => ({
x: Math.floor(asNumber(x)),
y: Math.floor(asNumber(y)),
});
export const TileAt: NodeDef = {
type: 'TileAt',
label: 'Tile at',
category: 'data',
description:
'The tile in a cell of a placed tilemap, read the moment it is asked for, so a "Set tile" earlier in ' +
'the same flow is already seen. The layer is picked by name ("First layer" is the first of the map). ' +
'"empty" is true for a cell without a tile, and for one outside the grid or on a layer the map does ' +
'not have.',
inputs: [obj('tilemap'), layerPort(), ...CELL_INPUTS],
outputs: [tilePort(), bool('empty')],
params: [],
read: (ctx, _params, input) => {
const target = asEntity(input('tilemap'));
const tile = target
? ctx.tileAt(target, asString(input('layer')), cellOf(input('cellX'), input('cellY')))
: null;
return { tile: tile ?? '', empty: !tile };
},
};
export const SetTile: NodeDef = {
type: 'SetTile',
label: 'Set tile',
category: 'action',
description:
'Puts a tile into a cell of a placed tilemap, or empties the cell when no tile is given. The autotile ' +
'edges of the cells around it follow, and so do its collision shapes. Only this placement of the map ' +
'changes, and only while the game runs. "done" is false when nothing could be set: no tilemap, no ' +
'such layer, a cell outside the grid, or something that is not a tile.',
inputs: [exec(), obj('tilemap'), layerPort(), ...CELL_INPUTS, tilePort()],
outputs: [exec(), bool('done')],
params: [],
run: (ctx, inputs) => {
const target = asEntity(inputs.tilemap);
const cell = cellOf(inputs.cellX, inputs.cellY);
const done = target ? ctx.setTile(target, asString(inputs.layer), cell, asString(inputs.tile)) : false;
return { outputs: { done }, next: 'exec' };
},
};
export const WorldToCell: NodeDef = {
type: 'WorldToCell',
label: 'World to cell',
category: 'data',
description:
'The cell of a placed tilemap a world point falls into – moved, turned, scaled or mirrored maps ' +
'included. Cell 0,0 is the top-left corner. "inside" says whether that cell is on the grid.',
inputs: [obj('tilemap'), num('x'), num('y')],
outputs: [num('cellX', 'cell x'), num('cellY', 'cell y'), bool('inside')],
params: [],
run: (ctx, inputs) => {
const target = asEntity(inputs.tilemap);
if (!target || !ctx.isTilemap(target)) return { outputs: { cellX: 0, cellY: 0, inside: false } };
const cell = worldToCell(target.props, worldMatrixOf(target), {
x: asNumber(inputs.x),
y: asNumber(inputs.y),
});
return { outputs: { cellX: cell.x, cellY: cell.y, inside: cell.inside } };
},
};
export const CellToWorld: NodeDef = {
type: 'CellToWorld',
label: 'Cell to world',
category: 'data',
description:
'The middle of a cell of a placed tilemap in world units – where to put something that stands on ' +
'that cell. Cells off the grid are answered too, continuing its rows and columns.',
inputs: [obj('tilemap'), ...CELL_INPUTS],
outputs: [num('x'), num('y')],
params: [],
run: (ctx, inputs) => {
const target = asEntity(inputs.tilemap);
if (!target || !ctx.isTilemap(target)) return { outputs: { x: 0, y: 0 } };
const at = cellToWorld(target.props, worldMatrixOf(target), cellOf(inputs.cellX, inputs.cellY));
return { outputs: { x: at.x, y: at.y } };
},
};
export const TileLiteral: NodeDef = {
type: 'Tile',
label: 'Tile',
category: 'data',
description: 'A constant tile, for a "Set tile" to put down or to compare what a "Tile at" reads with.',
inputs: [],
outputs: [tilePort('value')],
params: [{ key: 'value', label: 'Value', kind: 'asset', default: '', assetTypes: ['tile'] }],
run: (_ctx, _inputs, params) => ({ outputs: { value: asString(params.value ?? '') } }),
};
+6
View File
@@ -23,6 +23,7 @@ import { SetPosition } from './action/SetPosition';
import { Spawn } from './action/Spawn';
import { StopGame } from './action/StopGame';
import { StopSound } from './action/StopSound';
import { CellToWorld, SetTile, TileAt, TileLiteral, WorldToCell } from './action/tileNodes';
import { Abs } from './data/Abs';
import { Add } from './data/Add';
import { And } from './data/And';
@@ -227,6 +228,11 @@ export const BUILT_IN_NODES: readonly NodeDef[] = [
Raycast,
RaycastAll,
IgnoreOneWay,
TileAt,
SetTile,
WorldToCell,
CellToWorld,
TileLiteral,
Spawn,
Destroy,
Emit,