From 4267aae45814ca761c721b2b83867d77d09672d7 Mon Sep 17 00:00:00 2001 From: Pascal Garber Date: Tue, 24 Nov 2026 13:04:29 +0100 Subject: [PATCH 1/2] feat(editor): mark the active state during a run --- TODO.md | 2 +- apps/maker-gjs/src/services/live-state.service.ts | 4 ++-- apps/maker-gjs/src/widgets/application-window.ts | 2 +- apps/maker-gjs/src/widgets/scene-editor-view.ts | 5 ++++- packages/engine/src/engine.ts | 11 +++++++++++ .../src/widgets/editor/entity-components-editor.ts | 9 +++++++++ packages/gjs/src/widgets/editor/index.css | 1 + packages/gjs/src/widgets/editor/selected-page.ts | 10 ++++++++++ packages/gjs/src/widgets/editor/state-card.css | 9 +++++++++ 9 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 packages/gjs/src/widgets/editor/state-card.css diff --git a/TODO.md b/TODO.md index 592afd90..afb0536f 100644 --- a/TODO.md +++ b/TODO.md @@ -62,7 +62,7 @@ Conventions: - **Lock enforcement on remote command apply** — layer `locked` now syncs as a `SetLayerLockedCommand`, so both peers' edit-input paths respect a padlock; but `Engine.applyRemoteCommand` itself doesn't re-check the flag, so an op already in flight when the lock landed still applies. Decide whether remote apply should hard-block (and how to reconcile the sender's optimistic apply). *owner: engine, why: race window only — input-side checks cover the common case* - **Two engine components are read by nothing, and a third only for `depth`** — `CollisionComponent`: the shipped "Blocks movement" toggle has no runtime effect, no movement system consults it, so the player walks straight through every chest / sign / door the templates seed. `SpriteRefComponent` (only `depth` is read, by `applyActorDepth`): the placement graphic is built from the DEFINITION (`buildPlacementGraphic(def, …)` finds the `visual` entry itself), so writing the component at runtime does nothing — a runtime sprite/animation swap needs the graphic build routed through it. `CustomDataComponent` is the third and stays one BY DESIGN (the project-script escape hatch). `NpcRouteComponent` left this list when `HostileAiSystem` started walking its waypoints for a `patrol` enemy; the general `NpcMovementSystem` that walks a route with no fight attached is still unbuilt, so a peaceful NPC still stands still. The two still orphaned carry an `orphan-component-ok:` note; `check-orphan-components.mjs` fails the build on a third. *owner: engine* - **Real runtime effect systems (dialogue / inventory / audio)** — the maker host surfaces the `EventActionSystem` effects (`item-picked-up`, `flag-set`, `play-sfx`) as playtest toasts (forwarded engine widget → `EngineController` → `ApplicationWindow._showToast`); `show-text` is no longer one. The **flags store landed** (`GameSaveStateComponent` + `FlagSystem` + `StateSystem`, [`docs/concepts/game-systems.md`](docs/concepts/game-systems.md)) — `flag-set` now gates entity states for real, and the toast stays as the only visible sign a flag flipped. The in-game **dialogue text box** for `show-text` landed (`DialogueSystem` + runtime-only `DialogueStateComponent`, owned by `core`: whole-number `uiScale`, pages rasterised once, typewriter clips, tap/Enter/Space/confirm advance, the sequenced list waits for `DIALOGUE_CLOSED`). **Signs and people speak**: the `dialogue` component (`speaker?`, `lines[]`) is read on the action button by the facing probe and shown through the same box; the 13 Kokiri signs carry EN/DE texts. The **inspector rows** for it landed: "Who speaks" (an entry row) and "What it says" (a generic list-of-texts row: one entry per line, "Add a line", reorder by drag or the row's Move up / Move down, remove); a blank line stays in the data while it is typed into and the game skips it. The **`ask` action** landed (engine side): a prompt in the text box, 2-4 tappable rows above it, keyboard/controller highlight, optional cancel option, the picked list entered on the run's frame stack; the maker's **Ask card** landed too (prompt row, 2-4 answer rows each with its own nested action list one level deep and no `ask` inside, "Antwort beim Abbrechen" combo, drag and Move up/down reorder, one undo step per edit; the answer text is edited for the default language only until H5). Still placeholders: an **inventory bag** for `item-picked-up` (`InventoryComponent` + `item-def` library entities + `INVENTORY_CHANGED`, owned by the `inventory` game system), and an **audio layer** for `play-sfx`. Teleport is the one fully-real effect (engine `loadMap` + spawn override). *owner: engine + project layer* -- **Game memory panel is flags-only and a Test run only** — the panel lists declared flags and, per placement, thing-scoped ones; it does not show the inventory, removed-thing markers or the player record, and an edit is never undoable or sent to collaborators (a run's values are local runtime state, [`save-record.md`](docs/concepts/save-record.md) § Writing a value during a run). The state cards' "active now" badge (branch `feat/state-badge`) still polls every 250 ms and should read `LiveStateService` instead once both land; `placementStates` is already part of `LiveState`. *owner: maker* +- **Game memory panel is flags-only and a Test run only** — the panel lists declared flags and, per placement, thing-scoped ones; it does not show the inventory, removed-thing markers or the player record, and an edit is never undoable or sent to collaborators (a run's values are local runtime state, [`save-record.md`](docs/concepts/save-record.md) § Writing a value during a run). *owner: maker* - **State overlays are actions-only** — `StateSystem` swaps a matched state's `actions` list and nothing else; a state carrying `visual`, `collision` or any other type validates with a warning and stays inert. Visible cost: a door teleports once its flag is set but never *looks* open, and a chest still looks closed after it gave you its item. Doing it properly means rebuilding a live entity's overlaid components through the spawn pipeline mid-frame (sprite swap, collider swap) while keeping runtime companions like `TriggerFiredComponent` alive — the first piece of engine work in this design that rebuilds a spawned entity, so it gets its own round. The "When …" authoring editor landed (flag-is / counter / has-item, all / any / not, `change-counter` action); `has-item` evaluates false until the inventory exists. *owner: engine + gjs* - **`inventory` has no bag yet** — the base system owns `item` and contributes the existing `ItemPickupSystem`, so a pickup fires and the host toasts it, but nothing holds what was picked up: no `InventoryComponent` on the session singleton, no `item-def` library entities, no `INVENTORY_CHANGED`. Lands with the first system that reads a bag. *owner: engine, why: no consumer yet — see [`docs/concepts/game-systems.md`](docs/concepts/game-systems.md) § Reach* - **`combat-action` leaves three gaps** — (a) **no real game over**: a defeated hero is full-healed and given a grace period so a playtest cannot dead-end; a retry / restart flow needs playthrough save-state that survives a scene load, which does not exist. (b) **`stats.speed` is not shipped** — its only reader is `combat-turn`'s speed-sorted `TurnOrderSystem`, and in realtime combat the movement rate is already `movement.tilesPerSec`; it lands with that system. (c) **the Game-rules body has no destructive "Remove data" row** — the switch-off `Adw.AlertDialog` landed in step 6.4 (`confirmRuleSwitchOff`: a plain alert, not a destructive one, counting what goes quiet and saying the settings stay), but the row that would actually delete the dormant data did not. Dormancy is the contract, so a row that deletes what the dialog just promised to keep needs its own decision — what it removes (component data on entities? placements that only exist for that system?), whether it is undoable, and what it does to a peer mid-session. See [`docs/concepts/game-systems.md`](docs/concepts/game-systems.md) § Reach. *owner: engine + maker* diff --git a/apps/maker-gjs/src/services/live-state.service.ts b/apps/maker-gjs/src/services/live-state.service.ts index 44fdcf89..9d876caa 100644 --- a/apps/maker-gjs/src/services/live-state.service.ts +++ b/apps/maker-gjs/src/services/live-state.service.ts @@ -3,14 +3,14 @@ import type { FlagValue } from '@pixelrpg/engine' /** * What a test run currently remembers, as far as the window's panels care. * - * `placementStates` is the active state index per placement id (the + * `placementStates` is the resolved state id per placement id (`null` = base) (the * "active now" badge of the state cards reads it); a source that does not * report it leaves it out. */ export interface LiveState { readonly flags: Readonly> readonly thingFlags: Readonly>>> - readonly placementStates?: Readonly> + readonly placementStates?: Readonly> } /** diff --git a/apps/maker-gjs/src/widgets/application-window.ts b/apps/maker-gjs/src/widgets/application-window.ts index 6a11e948..20099a35 100644 --- a/apps/maker-gjs/src/widgets/application-window.ts +++ b/apps/maker-gjs/src/widgets/application-window.ts @@ -290,7 +290,7 @@ export class ApplicationWindow extends Adw.ApplicationWindow implements EntityDe /** What the running game remembers; the Game memory page reads it, only during a run. */ private readonly _liveState = new LiveStateService(() => { const snap = this._engineCtl.engine?.getRuntimeSnapshot() - return snap ? { flags: snap.flags, thingFlags: snap.thingFlags } : null + return snap ? { flags: snap.flags, thingFlags: snap.thingFlags, placementStates: snap.placementStates } : null }) private _engineCtl = new EngineController( (engine) => { diff --git a/apps/maker-gjs/src/widgets/scene-editor-view.ts b/apps/maker-gjs/src/widgets/scene-editor-view.ts index 7dbd3d25..faee7ff1 100644 --- a/apps/maker-gjs/src/widgets/scene-editor-view.ts +++ b/apps/maker-gjs/src/widgets/scene-editor-view.ts @@ -394,7 +394,10 @@ export class SceneEditorView extends ResponsiveEditorView { this._pages.memory.onProbe = (on) => { this._pages.memory.setProbe(on, this.probeSwitch?.(on) ?? null) } - this._liveOff = service.onChanged(() => this._renderMemory()) + this._liveOff = service.onChanged((live) => { + this._pages.selected.setRuntimeStates(live?.placementStates ?? null) + this._renderMemory() + }) } private _renderMemory(): void { diff --git a/packages/engine/src/engine.ts b/packages/engine/src/engine.ts index fe756920..5a15869a 100644 --- a/packages/engine/src/engine.ts +++ b/packages/engine/src/engine.ts @@ -13,6 +13,8 @@ import { AskStateComponent, PlayerActorComponent, PlayerComponent, + EntityStatesComponent, + PlacementIdComponent, type TouchIntent, TouchInputComponent, } from './components/index.ts' @@ -85,6 +87,8 @@ const FRAME_MARGIN = 0.1 export interface RuntimeSnapshot extends SaveSnapshot { /** The LOCAL player's tile, read off the live actor. */ playerTile: { x: number; y: number } | null + /** The state `StateSystem` resolved per placement id that declares states; `null` = base composition. */ + placementStates: Record /** The open question: option count, highlighted row, rows visible and live. */ /** The hero's facing direction. */ facing: string | null @@ -938,8 +942,15 @@ export class Engine { const ask = SessionState.get(scene, AskStateComponent) const box = SessionState.get(scene, DialogueStateComponent) const src = SessionState.get(scene, InputSourceComponent) + const placementStates: Record = {} + for (const e of scene.world.entities) { + const states = e.get(EntityStatesComponent) + const id = e.get(PlacementIdComponent)?.id + if (states && id) placementStates[id] = states.activeStateId + } return { ...saveSnapshot(save?.record, this._localPlayerId), + placementStates, playerTile: player ? { x: Math.floor(player.pos.x / tw), y: Math.floor(player.pos.y / th) } : null, facing: player?.get(PlayerActorComponent)?.facing ?? null, dialogueOpen: box != null, diff --git a/packages/gjs/src/widgets/editor/entity-components-editor.ts b/packages/gjs/src/widgets/editor/entity-components-editor.ts index fcf48c02..cabb246d 100644 --- a/packages/gjs/src/widgets/editor/entity-components-editor.ts +++ b/packages/gjs/src/widgets/editor/entity-components-editor.ts @@ -92,6 +92,8 @@ export class EntityComponentsEditor extends Adw.Bin { private _editorData: EntityDefinition['editorData'] private _states: EntityDefinition['states'] private _stateCards = new Map() + /** The state the running game resolved; `undefined` outside a run, `null` = base composition. */ + private _activeState: string | null | undefined private _components: ComponentData[] = [] private _refOptions: ComponentRefOptions = {} private _fullView = true @@ -374,6 +376,13 @@ export class EntityComponentsEditor extends Adw.Bin { this._box.insert_child_after(card, this._lastRenderedOrNull()) this._rendered.push(card) }) + this.setActiveState(this._activeState) + } + + /** Mark the card of the state the running game resolved; `undefined` (no run) marks none. */ + setActiveState(stateId: string | null | undefined): void { + this._activeState = stateId + for (const [id, card] of this._stateCards) card.setActive(stateId !== undefined && stateId === id) } private _lastRenderedOrNull(): Gtk.Widget | null { diff --git a/packages/gjs/src/widgets/editor/index.css b/packages/gjs/src/widgets/editor/index.css index b2c36097..461b3c92 100644 --- a/packages/gjs/src/widgets/editor/index.css +++ b/packages/gjs/src/widgets/editor/index.css @@ -1,4 +1,5 @@ @import "./scene-card.css"; +@import "./state-card.css"; @import "./atlas-canvas.css"; @import "./layer-row.css"; @import "./map-selection-bar.css"; diff --git a/packages/gjs/src/widgets/editor/selected-page.ts b/packages/gjs/src/widgets/editor/selected-page.ts index 85991083..0a2f9794 100644 --- a/packages/gjs/src/widgets/editor/selected-page.ts +++ b/packages/gjs/src/widgets/editor/selected-page.ts @@ -205,6 +205,16 @@ export class SelectedPage extends Adw.Bin { this._editor.setRefOptions(options) } + /** + * Reflect a running game's resolved states on the state cards. `null` + * (no run) shows no badge; otherwise `states` maps placement id to the + * state the engine resolved (`null` = base). + */ + setRuntimeStates(states: Readonly> | null): void { + const id = this._placement?.placementId + this._editor.setActiveState(states && id && id in states ? states[id] : undefined) + } + /** * Show one placement, or the empty state for `null`. Driven by the * host from the engine's `PLACEMENT_SELECTED` event and after every diff --git a/packages/gjs/src/widgets/editor/state-card.css b/packages/gjs/src/widgets/editor/state-card.css new file mode 100644 index 00000000..fc857f4d --- /dev/null +++ b/packages/gjs/src/widgets/editor/state-card.css @@ -0,0 +1,9 @@ +/* The "Active now" badge on the state a test run resolved. */ +.state-active-badge { + padding: 2px 8px; + border-radius: 99px; + font-size: 0.8em; + font-weight: bold; + background-color: @accent_bg_color; + color: @accent_fg_color; +} From 511987516036cabf9de169660a55426e987a75f7 Mon Sep 17 00:00:00 2001 From: Pascal Garber Date: Tue, 24 Nov 2026 20:54:13 +0100 Subject: [PATCH 2/2] feat(editor): keep Selected open in a test run --- docs/concepts/runtime-modes.md | 2 +- packages/gjs/src/widgets/editor/right-inspector.ts | 10 +++++----- packages/gjs/src/widgets/editor/scene-editor.ts | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/concepts/runtime-modes.md b/docs/concepts/runtime-modes.md index e0aec4bb..e5ab8d9a 100644 --- a/docs/concepts/runtime-modes.md +++ b/docs/concepts/runtime-modes.md @@ -30,7 +30,7 @@ Combinations are first-class. Each user-facing button picks a marker set: |---|---|---| | Default (open editor) | `EditorMode` | Pure editor — tools work, nothing moves, triggers are visualised but don't execute | | **Play here** ("Live Run") | `EditorMode` + `RuntimeMode` + `SpawnOverride{tileX, tileY = camera focus}` | The current scene starts playing from where the user is editing. The user can keep painting tiles while the player walks around them. Mario-Maker move. **No shipped button produces this marker set yet** — `win.play` spawns at the camera focus but swaps the markers rather than adding to them, so it is a Test run. The gates are written for it (`TileEditorSystem.isEditingLive()` passes when both markers are present); what is missing is a second entry point. | -| **Test run** (no edit) | `RuntimeMode` + `SpawnOverride` | Same in-editor window, but the editing affordances are hidden and the inspector is put away — clean run-through. **This is what `win.play` does in both layouts:** phone hides the bottom bar and the Play FAB and turns the context pill into Stop · Restart; wide drops the editing pill, the tool group, undo/redo and the inspector, keeps ↺ Restart in the context pill, turns the FAB into Stop and frames the canvas in accent. Esc / Stop → drops the runtime marker, back to editor. | +| **Test run** (no edit) | `RuntimeMode` + `SpawnOverride` | Same in-editor window, but the editing affordances are hidden and the inspector is put away — clean run-through. Opening it during the run offers Selected and Game memory (Brush and Layers are gone); the state cards on Selected mark the state the engine resolved with an "active now" badge, read from `LiveStateService` like the memory page. **This is what `win.play` does in both layouts:** phone hides the bottom bar and the Play FAB and turns the context pill into Stop · Restart; wide drops the editing pill, the tool group, undo/redo and the inspector, keeps ↺ Restart in the context pill, turns the FAB into Stop and frames the canvas in accent. Esc / Stop → drops the runtime marker, back to editor. | | **Launch full game** | (new window) `RuntimeMode` only | Game launches in a dedicated window with the project's real `startup.initialMapId` + spawn-point placement. No editor chrome. This is what shipping looks like. | **Collision follows the run.** Tile collision is built only while `RuntimeModeComponent` is present: `applyRuntimeMode` calls `setCollisionActive(scene, active)` (`services/collision-mode.ts`), which flips the physics world and every `PlaneTileMap` (`resource/plane-tile-map.ts`). The editor idles without colliders (5432 → 0 on `kokiri-forest`; update 58 ms → ~3 ms). That call is the one line an "edit while the game runs" mode changes. Wall hatching reads tile data, not colliders, so it is unaffected. diff --git a/packages/gjs/src/widgets/editor/right-inspector.ts b/packages/gjs/src/widgets/editor/right-inspector.ts index 1a115f42..86be0bba 100644 --- a/packages/gjs/src/widgets/editor/right-inspector.ts +++ b/packages/gjs/src/widgets/editor/right-inspector.ts @@ -67,17 +67,17 @@ export class RightInspector extends Adw.Bin { } /** - * Swap the three editing pages for Game memory while a test run is on, - * and put the page the person was on back afterwards. The switcher goes - * too: one page needs no tabs. + * Swap Brush and Layers for Game memory while a test run is on, and put + * the page the person was on back afterwards. Selected stays: its state + * cards carry the "active now" badge, which only means something while + * the game runs. */ set memoryMode(on: boolean) { if (on === (this._pageBeforeMemory !== null)) return - for (const slot of [this._brush_slot, this._layers_slot, this._selected_slot]) { + for (const slot of [this._brush_slot, this._layers_slot]) { this._stack.get_page(slot).set_visible(!on) } this._stack.get_page(this._memory_slot).set_visible(on) - this._switcher.set_visible(!on) if (on) { this._pageBeforeMemory = this.visiblePage this._stack.set_visible_child_name('memory') diff --git a/packages/gjs/src/widgets/editor/scene-editor.ts b/packages/gjs/src/widgets/editor/scene-editor.ts index c4385f00..02096516 100644 --- a/packages/gjs/src/widgets/editor/scene-editor.ts +++ b/packages/gjs/src/widgets/editor/scene-editor.ts @@ -388,15 +388,15 @@ export class SceneEditor extends Adw.Bin { } /** - * Swap the sheet's three editing pages for Game memory during a test - * run, and back. The switcher goes too: one page needs no tabs. + * Swap the sheet's Brush and Layers for Game memory during a test + * run, and back. Selected stays: its state cards carry the "active + * now" badge, which only means something while the game runs. */ set memoryMode(on: boolean) { - for (const slot of [this._brush_slot_sheet, this._layers_slot_sheet, this._selected_slot_sheet]) { + for (const slot of [this._brush_slot_sheet, this._layers_slot_sheet]) { this._sheet_stack.get_page(slot).set_visible(!on) } this._sheet_stack.get_page(this._memory_slot_sheet).set_visible(on) - this._sheet_switcher.set_visible(!on) if (on) this._sheet_stack.set_visible_child_name('memory') }