Skip to content

feat(engine): split the save record into world and players - #425

Merged
JumpLink merged 2 commits into
mainfrom
feat/world-player-record
Nov 24, 2026
Merged

JumpLink merged 2 commits into
mainfrom
feat/world-player-record

Conversation

@JumpLink

Copy link
Copy Markdown
Contributor

What

A flag with scope: thing used to land in one global bag, so opening one chest opened every chest that shared the flag. The save state becomes a record instead:

{ schemaVersion, world: { flags, thingFlags: { [placementId]: flags }, removedThings },
  players: { [playerId]: { mapId, tileX, tileY, facing } } }

world is the host's; each player owns their own entry. Bag and stats get a typed place in PlayerRecord later (M5), and writing the record to disk is M8 — this one keeps it in memory.

How

  • A scope: thing write resolves against the placement that ran the action, keyed by PlacementIdComponent.id (= ObjectPlacement.id, never an Excalibur entity id). With no placement in reach it falls back to world.flags.
  • evaluateCondition stays pure: resolvedFlagView(record, placementId) builds the view and hands it in, so conditions never reach into the ECS.
  • The player id comes from the host — GSettings key player-id, empty by default and filled on first read — threaded Engine.setLocalPlayerId → loader → scene → system. It is stored, not derived, and it is never generatePeerId(): a rejoin must find the same player.
  • migrateSaveRecord lifts an old flat flag bag into world.flags and leaves everything else empty — lossless, and existing projects (Kokiri Forest) load unchanged.
  • RuntimeSnapshot now extends SaveSnapshot: flags stays the flat game-scoped bag it always was, joined by thingFlags, removedThings, players and localPlayerId, so GetStatus → runtime keeps working and says more.

Editor

scope: thing was not reachable from the UI, so the new-flag dialog grew a "Remembered by" choice — two radio rows ("The whole game" / "Each thing on its own") rather than a dropdown, because at phone width a combo ellipsised its own value away. German strings in de.po.

Verified

Two chests sharing one thing-scoped flag, played through the running app and read back over D-Bus:

step flags['chest-open'] thingFlags
start false {}
touch A false { 'p-chest-a': { 'chest-open': true } }
touch B false { 'p-chest-a': …, 'p-chest-b': { 'chest-open': true } }

found-a-chest (game scope) flips to true on the first touch and stays. players carries the local player's map and tile.

Specs cover two players in one world, a thing-scoped flag on two placements, removed markers, the migration and the snapshot shape.

A flag with `scope: thing` used to land in one global bag, so opening
one chest opened every chest that shared the flag. The save state is now
a record: `world` holds game-scoped values, per-placement values keyed by
placement id, and removed-thing markers; `players[playerId]` holds each
player's position and map, with room for bag and stats later.

A `scope: thing` write resolves against the placement that ran the
action (`PlacementIdComponent.id`), falling back to `world` when there is
none. `evaluateCondition` stays pure — it reads a resolved view passed
in, never the ECS.

The player id comes from the host (GSettings `player-id`, filled once on
first read), never from a peer id, so it survives a rejoin.

`migrateSaveRecord` lifts an old flat bag into `world.flags` losslessly,
and the runtime snapshot keeps that flat `flags` field while adding
`thingFlags`, `removedThings`, `players` and `localPlayerId`.

Saving at rest is not part of this: the record only lives in memory.
@JumpLink
JumpLink force-pushed the feat/world-player-record branch from b59bf1a to 6dbd4eb Compare November 24, 2026 13:44
@JumpLink
JumpLink merged commit b829a3c into main Nov 24, 2026
2 checks passed
@JumpLink
JumpLink deleted the feat/world-player-record branch November 24, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant