[PR #7773] [MERGED] feat(game): Game data in the State Editor, part 2 (#7743, slices 3-6) #7922

Closed
opened 2026-10-24 04:08:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7773
Author: @ylli-selmani
Created: 10/17/2026
Status: ✅ Merged
Merged: 10/18/2026
Merged by: @ylli-selmani

Base: staging ← Head: feat/game-data-state-editor-b


📝 Commits (10+)

  • 4d149f0 fix(game): a saved game data edit stays saved when reading it back fails (#7743)
  • 8ae96f4 feat(game): edit the inventory in the Game data editor (#7743 slice 3)
  • 3c6bb4d feat(game): edit the world's edits layer in the Game data editor (#7743 slice 4)
  • c844aec feat(game): save the story script, party sheet and widgets from the State Editor (#7743 slice 5)
  • 7b9dbbf feat(game): checkpoint before every State Editor save, and a Checkpoints list (#7743 slice 6)
  • dff723b fix(game): the checkpoints list loads the restored game, one at a time (#7743)
  • 5ef8cbe Merge remote-tracking branch 'origin/staging' into feat/game-data-state-editor-b
  • 03ede02 fix(game): save world edits and the story only over what the editor opened (#7743)
  • b54c5af fix(game): a stale world-edits save skips the snapshot (#7743)
  • 3b0f845 fix(game): the State Editor saves HUD widgets only over what it opened (#7743)

📊 Changes

22 files changed (+1434 additions, -82 deletions)

View changed files

📝 docs/game/sessions-and-saves.md (+5 -1)
📝 packages/client/src/components/game/GameSurface.tsx (+12 -33)
📝 packages/client/src/components/layout/ModalRenderer.tsx (+6 -0)
➕ packages/client/src/components/modals/GameCheckpointsModal.tsx (+178 -0)
📝 packages/client/src/components/modals/GameDataEditorModal.tsx (+271 -11)
📝 packages/client/src/hooks/use-game.ts (+6 -2)
📝 packages/client/src/lib/game-inventory-refusal.ts (+42 -0)
📝 packages/client/src/lib/state-editor/game-data-editor-source.ts (+56 -9)
➕ packages/client/src/lib/state-editor/game-data-inventory.ts (+155 -0)
📝 packages/client/src/localization/locales/en.json (+43 -2)
📝 packages/server/src/db/schema/checkpoints.ts (+10 -1)
📝 packages/server/src/routes/game-inventory.routes.ts (+27 -1)
📝 packages/server/src/routes/game.routes.ts (+67 -8)
📝 packages/server/src/services/game/checkpoint.service.ts (+44 -9)
📝 packages/shared/src/types/game.ts (+8 -1)
📝 packages/shared/src/utils/game-inventory-ops.ts (+6 -0)
📝 scripts/regressions/game-checkpoint-metadata.regression.ts (+59 -4)
➕ scripts/regressions/game-data-checkpoints.regression.ts (+123 -0)
➕ scripts/regressions/game-data-inventory.regression.ts (+218 -0)
📝 scripts/regressions/state-editor.regression.ts (+56 -0)

...and 2 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7743 (slices 3 to 6). Stacked on #7766 (slices 1 and 2), now merged; this diff is slices 3 to 6 alone.

Why this change

#7766 made the game's own data visible and editable in the State Editor, through a checked route. This PR covers the rest of the issue: the data that already has its own routes (inventory, world, story script, party sheet, HUD widgets), a checkpoint before every save, and a way to load a checkpoint.

What changed

  • Inventory is editable. There is no replace-all op, so an edit becomes the ops POST /api/game/inventory already applies (set, rename, give, equip, …), matched by stack id. Fields no op changes, unknown ids and bad quantities are refused before anything is sent. The route has no stale check of its own, so the stacks an edit touches are compared with what is stored right before sending.
  • World Edits shows the hand-edits layer over the game's world (gameWorld.edits) and saves it through PUT /api/game/:chatId/world/edits, which checks it against the world, its towns and its story. The world itself is never written.
  • Story Script, Party Sheet and HUD Widgets save through their own routes, reusing the client's existing paths where there is one: the story route's PUT/DELETE, the party sheet hook (on the revision the editor opened, so a stale save is refused with the game's own sheet), and useUpdateGameWidgets (so the HUD updates at once).
  • When a save spans several routes and a later one fails, the editor moves its baseline to what is stored: the saved sections read clean and only the refused one keeps its draft, so a retry doesn't resend saved keys.
  • A checkpoint before every save: a new automatic state_editor_save trigger, pruned to the newest 5 like the other automatic triggers, taken after the checks and before any write. A game too new to have a snapshot has nothing to checkpoint, and that never blocks a save.
  • Game controls → Checkpoints: the game's checkpoints newest first, each with its label, what took it and when, a confirmed Load (restores the tracker, map and story; reloads the chat, messages and game caches) and a confirmed Delete.
  • docs/game/sessions-and-saves.md said there was no screen to browse or restore checkpoints; it now describes the screen.
  • Known gap: a checkpoint load restores every section the editor writes except World Edits, which lives inside gameWorld and needs the world write path to restore safely. The section and the doc say so; tracked in #7783.

Commits

  • 8ae96f4a1 slice 3: inventory through ops
  • 3c6bb4d83 slice 4: the world's edits layer
  • c844aeca9 slice 5: story script, party sheet and HUD widgets
  • 7b9dbbf4f slice 6: checkpoint before save, and the Checkpoints list
  • dff723b38 review fixes (the game state store on load; one request at a time; the regression's own store)
  • 5ef8cbe3f merge of staging after #7766 landed

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Ran a seeded game on a local server.

  • Inventory: raised a stack's quantity and saved: stored as edited, toast "Game data saved". Then edited the JSON to raise one quantity and mark a potion equipped: the rope quantity saved, the equip was refused, and the warning toast named the potion ("Healing Potion cannot be equipped") — the save-what-fits path.
  • A game saved before stacks had ids: the stacks gained ids on the first save, and a regression proves the ids the client works out are the ones the server applies the ops to (no duplicate stacks).
  • HUD Widgets: added a progress bar through the JSON view and saved. The server added startingValue and turned custom widgets on, as it does for in-game edits, and the widget appeared on the HUD under its own label without a page reload.
  • Checkpoints: the list reads "No checkpoints yet" for a game without a snapshot; the editor's checkpoint call is refused ("No game state snapshot to checkpoint", visible in the server log) and the save still lands, which is the intended best-effort path. A regression covers the list, the new trigger, pruning to 5 per trigger, manual ones surviving, and delete.
  • Stale and error paths: a failed save keeps its draft and says which section; a save that spans routes and fails later reloads the baseline so saved sections read clean.

Not covered manually: a real world's edits layer (needs a generated world; the route is covered by world-edits.regression.ts), a real ruleset party sheet save (needs a ruleset game), and the light/SillyTavern themes.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

A game without a world or a story script doesn't show those two sections, so the editor below has neither.

Game Data Checkpoints
Game Data Checkpoints
Editor Inventory
Party Cards Inventory
HUD Widgets
HUD Widgets

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Browse, load, and permanently delete game checkpoints from Game controls → Checkpoints. Checkpoints are captured at key game moments and before eligible Game data editor saves.
    • Checkpoint restores include story and HUD widget settings. World Edits are not reverted when loading a checkpoint.
    • Edit inventory stacks and additional game data sections through the Game data editor, with clearer validation and inventory messages.
  • Bug Fixes

    • Saves detect when relevant game data has changed since editing began, helping prevent newer changes from being overwritten.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7773 **Author:** [@ylli-selmani](https://github.com/ylli-selmani) **Created:** 10/17/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ylli-selmani](https://github.com/ylli-selmani) **Base:** `staging` ← **Head:** `feat/game-data-state-editor-b` --- ### 📝 Commits (10+) - [`4d149f0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4d149f013db370d0dc81861e9bf8d46f6abfb4e3) fix(game): a saved game data edit stays saved when reading it back fails (#7743) - [`8ae96f4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ae96f4a1a918d80320298540cb64977ccabdef4) feat(game): edit the inventory in the Game data editor (#7743 slice 3) - [`3c6bb4d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3c6bb4d8386b24a9caa3f20c9b8d45665019c5ff) feat(game): edit the world's edits layer in the Game data editor (#7743 slice 4) - [`c844aec`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c844aeca986ce9dbba223122f5b10ded2d51f586) feat(game): save the story script, party sheet and widgets from the State Editor (#7743 slice 5) - [`7b9dbbf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7b9dbbf4f79c234d980c0231ddffaa439e4baf92) feat(game): checkpoint before every State Editor save, and a Checkpoints list (#7743 slice 6) - [`dff723b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dff723b3857be7a99bcef56c8a9e525a87d2500b) fix(game): the checkpoints list loads the restored game, one at a time (#7743) - [`5ef8cbe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5ef8cbe3f11de00fd64e74c318a4f129cd245ca7) Merge remote-tracking branch 'origin/staging' into feat/game-data-state-editor-b - [`03ede02`](https://github.com/Pasta-Devs/Marinara-Engine/commit/03ede0298b348d38e10713fa78411554fd4e32eb) fix(game): save world edits and the story only over what the editor opened (#7743) - [`b54c5af`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b54c5afec7ce931b898c37e8eadf200a0925858f) fix(game): a stale world-edits save skips the snapshot (#7743) - [`3b0f845`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3b0f8454972887c4252f1e2a544cdea1c1f5c786) fix(game): the State Editor saves HUD widgets only over what it opened (#7743) ### 📊 Changes **22 files changed** (+1434 additions, -82 deletions) <details> <summary>View changed files</summary> 📝 `docs/game/sessions-and-saves.md` (+5 -1) 📝 `packages/client/src/components/game/GameSurface.tsx` (+12 -33) 📝 `packages/client/src/components/layout/ModalRenderer.tsx` (+6 -0) ➕ `packages/client/src/components/modals/GameCheckpointsModal.tsx` (+178 -0) 📝 `packages/client/src/components/modals/GameDataEditorModal.tsx` (+271 -11) 📝 `packages/client/src/hooks/use-game.ts` (+6 -2) 📝 `packages/client/src/lib/game-inventory-refusal.ts` (+42 -0) 📝 `packages/client/src/lib/state-editor/game-data-editor-source.ts` (+56 -9) ➕ `packages/client/src/lib/state-editor/game-data-inventory.ts` (+155 -0) 📝 `packages/client/src/localization/locales/en.json` (+43 -2) 📝 `packages/server/src/db/schema/checkpoints.ts` (+10 -1) 📝 `packages/server/src/routes/game-inventory.routes.ts` (+27 -1) 📝 `packages/server/src/routes/game.routes.ts` (+67 -8) 📝 `packages/server/src/services/game/checkpoint.service.ts` (+44 -9) 📝 `packages/shared/src/types/game.ts` (+8 -1) 📝 `packages/shared/src/utils/game-inventory-ops.ts` (+6 -0) 📝 `scripts/regressions/game-checkpoint-metadata.regression.ts` (+59 -4) ➕ `scripts/regressions/game-data-checkpoints.regression.ts` (+123 -0) ➕ `scripts/regressions/game-data-inventory.regression.ts` (+218 -0) 📝 `scripts/regressions/state-editor.regression.ts` (+56 -0) _...and 2 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #7743 (slices 3 to 6). Stacked on #7766 (slices 1 and 2), now merged; this diff is slices 3 to 6 alone. ## Why this change #7766 made the game's own data visible and editable in the State Editor, through a checked route. This PR covers the rest of the issue: the data that already has its own routes (inventory, world, story script, party sheet, HUD widgets), a checkpoint before every save, and a way to load a checkpoint. ## What changed - **Inventory** is editable. There is no replace-all op, so an edit becomes the ops `POST /api/game/inventory` already applies (set, rename, give, equip, …), matched by stack id. Fields no op changes, unknown ids and bad quantities are refused before anything is sent. The route has no stale check of its own, so the stacks an edit touches are compared with what is stored right before sending. - **World Edits** shows the hand-edits layer over the game's world (`gameWorld.edits`) and saves it through `PUT /api/game/:chatId/world/edits`, which checks it against the world, its towns and its story. The world itself is never written. - **Story Script**, **Party Sheet** and **HUD Widgets** save through their own routes, reusing the client's existing paths where there is one: the story route's PUT/DELETE, the party sheet hook (on the revision the editor opened, so a stale save is refused with the game's own sheet), and `useUpdateGameWidgets` (so the HUD updates at once). - When a save spans several routes and a later one fails, the editor moves its baseline to what is stored: the saved sections read clean and only the refused one keeps its draft, so a retry doesn't resend saved keys. - **A checkpoint before every save**: a new automatic `state_editor_save` trigger, pruned to the newest 5 like the other automatic triggers, taken after the checks and before any write. A game too new to have a snapshot has nothing to checkpoint, and that never blocks a save. - **Game controls → Checkpoints**: the game's checkpoints newest first, each with its label, what took it and when, a confirmed Load (restores the tracker, map and story; reloads the chat, messages and game caches) and a confirmed Delete. - `docs/game/sessions-and-saves.md` said there was no screen to browse or restore checkpoints; it now describes the screen. - **Known gap:** a checkpoint load restores every section the editor writes except **World Edits**, which lives inside `gameWorld` and needs the world write path to restore safely. The section and the doc say so; tracked in #7783. ### Commits - [x] `8ae96f4a1` slice 3: inventory through ops - [x] `3c6bb4d83` slice 4: the world's edits layer - [x] `c844aeca9` slice 5: story script, party sheet and HUD widgets - [x] `7b9dbbf4f` slice 6: checkpoint before save, and the Checkpoints list - [x] `dff723b38` review fixes (the game state store on load; one request at a time; the regression's own store) - [x] `5ef8cbe3f` merge of `staging` after #7766 landed ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes Ran a seeded game on a local server. - **Inventory**: raised a stack's quantity and saved: stored as edited, toast "Game data saved". Then edited the JSON to raise one quantity and mark a potion equipped: the rope quantity saved, the equip was refused, and the warning toast named the potion ("Healing Potion cannot be equipped") — the save-what-fits path. - **A game saved before stacks had ids**: the stacks gained ids on the first save, and a regression proves the ids the client works out are the ones the server applies the ops to (no duplicate stacks). - **HUD Widgets**: added a progress bar through the JSON view and saved. The server added `startingValue` and turned custom widgets on, as it does for in-game edits, and the widget appeared on the HUD under its own label without a page reload. - **Checkpoints**: the list reads "No checkpoints yet" for a game without a snapshot; the editor's checkpoint call is refused ("No game state snapshot to checkpoint", visible in the server log) and the save still lands, which is the intended best-effort path. A regression covers the list, the new trigger, pruning to 5 per trigger, manual ones surviving, and delete. - **Stale and error paths**: a failed save keeps its draft and says which section; a save that spans routes and fails later reloads the baseline so saved sections read clean. Not covered manually: a real world's edits layer (needs a generated world; the route is covered by `world-edits.regression.ts`), a real ruleset party sheet save (needs a ruleset game), and the light/SillyTavern themes. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README) as needed - [x] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) A game without a world or a story script doesn't show those two sections, so the editor below has neither. | Game Data | Checkpoints | | --- | --- | | ![Game Data](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/7773-01-game.png) | ![Checkpoints](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/7773-02-checkpoints.png) | | Editor | Inventory | | --- | --- | | ![Party Cards](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/7773-03-editor-open.png) | ![Inventory](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/7773-04-inventory.png) | | HUD Widgets | | --- | | ![HUD Widgets](https://raw.githubusercontent.com/ylli-selmani/Marinara-Engine-Ylli-Edits/pr-assets/pr-assets/7773-07-widgets.png) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Browse, load, and permanently delete game checkpoints from **Game controls → Checkpoints**. Checkpoints are captured at key game moments and before eligible Game data editor saves. * Checkpoint restores include story and HUD widget settings. World Edits are not reverted when loading a checkpoint. * Edit inventory stacks and additional game data sections through the Game data editor, with clearer validation and inventory messages. * **Bug Fixes** * Saves detect when relevant game data has changed since editing began, helping prevent newer changes from being overwritten. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:08:51 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7922
No description provided.