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
+23
-6
@@ -18,6 +18,7 @@ import { findAsset, findAssetOf, type ObjectHolder, type Project } from '../core
|
||||
import { fontFileOf } from '../core/model/font';
|
||||
import { resolveTexture, type TextureRef } from '../core/model/texture';
|
||||
import type { FrameOutline } from '../core/model/frameOutline';
|
||||
import { liveTilemap, type TileEdits } from '../core/model/liveTilemap';
|
||||
import { colliderFrame } from '../core/properties/collider';
|
||||
import { enabledAlongChain } from '../core/properties/enabled';
|
||||
import { fontOf } from '../core/properties/fonts';
|
||||
@@ -96,9 +97,15 @@ export interface TilemapDraw {
|
||||
* project is at hand, for the same reason a sprite's picture is resolved here: drawing has no
|
||||
* access to it. A hidden layer is left out, in the editor and in the running game alike.
|
||||
*/
|
||||
function resolveTilemap(project: Project, assetId: string, props: PropertyBag): TilemapDraw | null {
|
||||
const asset = findAssetOf(project, assetId, 'tilemap');
|
||||
if (!asset) return null;
|
||||
function resolveTilemap(
|
||||
project: Project,
|
||||
assetId: string,
|
||||
props: PropertyBag,
|
||||
edits: TileEdits | undefined,
|
||||
): TilemapDraw | null {
|
||||
const stored = findAssetOf(project, assetId, 'tilemap');
|
||||
if (!stored) return null;
|
||||
const asset = liveTilemap(stored, edits);
|
||||
const layers: TilemapLayerDraw[] = [];
|
||||
const used = new Map<string, TilemapTile>();
|
||||
for (const layer of asset.layers) {
|
||||
@@ -140,12 +147,14 @@ function wearsPicture(type: AssetType): boolean {
|
||||
/**
|
||||
* A scene or a container template, in tree order – the tie-break for equal `z` – at the editor
|
||||
* positions, with the content of placed containers resolved in. A container has no background of
|
||||
* its own, so it keeps the fallback.
|
||||
* its own, so it keeps the fallback. `run` is the editor run on that scene: the tiles its behaviors
|
||||
* set are shown on the maps, though they never reach the model (#135).
|
||||
*/
|
||||
export function collectHolderItems(
|
||||
project: Project,
|
||||
holder: ObjectHolder | undefined,
|
||||
fallbackBackground: number,
|
||||
run: World | null = null,
|
||||
): DrawList {
|
||||
if (!holder) return { items: [], background: fallbackBackground };
|
||||
const view = resolvedHolder(project, holder);
|
||||
@@ -169,7 +178,10 @@ export function collectHolderItems(
|
||||
texture: wearsPicture(asset.type) ? resolveTexture(project, props) : null,
|
||||
font: asset.type === 'text' ? fontFileOf(project, fontOf(props)) : '',
|
||||
particles: asset.type === 'particles' ? asset : null,
|
||||
tilemap: asset.type === 'tilemap' ? resolveTilemap(project, asset.id, props) : null,
|
||||
tilemap:
|
||||
asset.type === 'tilemap'
|
||||
? resolveTilemap(project, asset.id, props, liveEdits(run, holder, object.id))
|
||||
: null,
|
||||
emits: 0,
|
||||
frame: asset.type === 'collider' ? colliderFrame(project, props) : null,
|
||||
});
|
||||
@@ -184,6 +196,11 @@ export function collectHolderItems(
|
||||
return { items, background: Number(holder.props.backgroundColor ?? fallbackBackground) };
|
||||
}
|
||||
|
||||
/** What a run changed on a placed tilemap of the holder shown, if the run is on that holder. */
|
||||
function liveEdits(run: World | null, holder: ObjectHolder, objectId: string): TileEdits | undefined {
|
||||
return run?.sceneId === holder.id ? run.findByObjectId(objectId)?.tileEdits : undefined;
|
||||
}
|
||||
|
||||
/** The running world: scene content only, since symbols are editor-only. */
|
||||
export function collectWorldItems(world: World): DrawList {
|
||||
const items = world.entities
|
||||
@@ -207,7 +224,7 @@ export function collectWorldItems(world: World): DrawList {
|
||||
texture: wearsPicture(e.type) ? resolveTexture(world.project, e.props) : null,
|
||||
font: e.type === 'text' ? fontFileOf(world.project, fontOf(e.props)) : '',
|
||||
particles: e.type === 'particles' ? (findAssetOf(world.project, e.assetId, 'particles') ?? null) : null,
|
||||
tilemap: e.type === 'tilemap' ? resolveTilemap(world.project, e.assetId, e.props) : null,
|
||||
tilemap: e.type === 'tilemap' ? resolveTilemap(world.project, e.assetId, e.props, e.tileEdits) : null,
|
||||
emits: e.emits ?? 0,
|
||||
frame: e.wornFrame?.() ?? null,
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user