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

+3 -1
View File
@@ -69,7 +69,9 @@ export class EditorRun {
this.commit(write);
// A shared value belongs to no object, so a frame that only moved one writes nothing here and
// the panels would never hear of it. Asking who is looking keeps that to the frames it helps.
if (!write.values && !write.structure && this.showsVariables()) this.state.runtimeTick();
// A set tile writes nothing either, and the maps on screen have to show it (#135).
const tiles = world.takeTileChange();
if (!write.values && !write.structure && (tiles || this.showsVariables())) this.state.runtimeTick();
}
/** Which state each instance of a machine holds in this run; empty when no editor run is on. */
+2
View File
@@ -16,6 +16,7 @@ import {
type Value,
} from '../../core/graph';
import { layerIndexOf, layerMaskOf, layerName, maskLabel } from '../../core/model/collisionLayers';
import { FIRST_TILE_LAYER } from '../../core/model/liveTilemap';
import type { Project } from '../../core/model/Project';
import { isList, type PropertyValue } from '../../core/model/Properties';
import type { PropertyDef } from '../../core/properties/PropertySchema';
@@ -483,6 +484,7 @@ function formatField(def: PropertyDef, value: Value, project: Project | null): s
const layers = project?.collisionLayers ?? [];
if (def.kind === 'layer') return layerName(layers, layerIndexOf(value));
if (def.kind === 'layers') return maskLabel(layerMaskOf(value), layers);
if (def.kind === 'tileLayer') return asString(value) || FIRST_TILE_LAYER;
if (def.kind === 'enum') return def.options.find((o) => o.value === value)?.label ?? formatValue(value);
return referenceLabel(def, project, asString(value)) ?? formatValue(value);
}
+14
View File
@@ -15,6 +15,8 @@ import {
assetRefLabel,
NO_ASSET_LABEL,
} from '../../core/properties/assetRef';
import { FIRST_TILE_LAYER } from '../../core/model/liveTilemap';
import { tilemapLayerNames } from '../../core/model/tilemap';
import { isKindWith, type ReferenceKind } from '../../core/properties/kinds';
import {
emptyFieldValue,
@@ -506,6 +508,18 @@ export function createField(
},
};
}
case 'tileLayer': {
const labelOf = (v: PropertyValue) => textOf(v) || FIRST_TILE_LAYER;
const button = new Dropdown(labelOf(value));
button.onClick = () => {
const names = ['', ...tilemapLayerNames(ctx.project())];
new Menu(
names.map((name) => ({ label: name || FIRST_TILE_LAYER, onSelect: () => handlers.onChange(name) })),
{ searchable: true },
).openBelow(button);
};
return { widget: button, grow: true, setValue: (v) => button.setText(labelOf(v)) };
}
case 'key': {
const button = new KeyCaptureButton(textOf(value), (key) => handlers.onChange(key));
return { widget: button, grow: true, setValue: (v) => button.setKey(textOf(v)) };
+1 -1
View File
@@ -80,7 +80,7 @@ export class GameViewport extends WorldViewport {
}
private modelFrame(): Frame {
return collectHolderItems(this.state.project, this.state.activeScene, LETTERBOX_COLOR);
return collectHolderItems(this.state.project, this.state.activeScene, LETTERBOX_COLOR, this.editorWorld);
}
/** `camera`: object id of the camera the view is through, empty when none is switched on. */
+1 -1
View File
@@ -175,7 +175,7 @@ export class SceneViewport extends FreeViewport {
}
protected override collectFrame(): Frame {
return collectHolderItems(this.state.project, this.holder(), Theme.colors.viewport);
return collectHolderItems(this.state.project, this.holder(), Theme.colors.viewport, this.editorWorld);
}
protected override get baseColor(): number {