[PR #6370] [MERGED] feat(game): a ruleset can offer layers that a game turns on in the setup wizard #7153

Closed
opened 2026-10-23 04:17:00 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6370
Author: @kolacheee
Created: 9/19/2026
Status: ✅ Merged
Merged: 9/19/2026
Merged by: @kolacheee

Base: staging ← Head: feat/rulesets-layers


📝 Commits (10+)

  • fce2efe feat(rulesets): a ruleset may ship layers, and a base ruleset may guide world generation
  • 655cd4e feat(game): resolve a game's ruleset with its layers, freeze the choice into the pin and guide world generation
  • 3569720 docs(rulesets): layers in the authoring guide, the setup guide, the capability list and the plan
  • a5b939b chore(rulesets): regenerate the published ruleset JSON Schema
  • d805217 docs(rulesets): record layers L1 in the plan status line and drop an em dash
  • 192f8ef feat(game): the setup wizard offers a ruleset's layers and the game plays by them
  • 020b760 test(game): pin the wizard's layer toggles and the picker hiding layered catalog entries
  • fdc3695 docs(rulesets): record that layers L1 is built on the client too
  • 0ba0427 fix(game): the wizard sends only the layers the chosen ruleset still declares
  • 58b75a6 fix(game): a layer cannot remove a value a hide rule reads, and the editor schema asks for one hide comparison

📊 Changes

38 files changed (+2427 additions, -71 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/development/game-rulesets-and-sheets-implementation.md (+19 -2)
📝 docs/development/optional-agent-packages.md (+26 -0)
📝 docs/development/ruleset-5e-2014.example.json (+25 -1)
📝 docs/examples/rulesets/ember-roads.json (+20 -1)
📝 docs/examples/rulesets/gravewatch.json (+19 -1)
📝 docs/extending/ruleset.schema.json (+232 -0)
📝 docs/extending/writing-rulesets.md (+70 -0)
📝 docs/game/getting-started.md (+2 -0)
📝 packages/client/src/components/game/GameCharacterSheet.tsx (+14 -1)
📝 packages/client/src/components/game/GameRulesetSheet.tsx (+24 -2)
📝 packages/client/src/components/game/GameSetupRulesChooser.tsx (+46 -0)
📝 packages/client/src/components/game/GameSetupWizard.tsx (+25 -1)
📝 packages/client/src/components/game/GameSurface.tsx (+4 -0)
📝 packages/client/src/components/rulesets/RulesetCatalogPicker.tsx (+13 -1)
📝 packages/client/src/components/rulesets/RulesetSheetEditor.tsx (+7 -0)
📝 packages/client/src/hooks/use-game-ruleset.ts (+36 -4)
📝 packages/client/src/hooks/use-game.ts (+22 -4)
📝 packages/client/src/lib/game-setup-share.ts (+4 -1)
📝 packages/client/src/lib/ruleset-catalog.ts (+20 -0)

...and 18 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

Part of #6314 (ruleset layers, first slice; it does not close the issue). Builds on #6368 (dice pools, merged).

Why this change

  • A table rarely plays a system exactly as printed. "Low magic", "gritty winter", "no firearms" are choices made per campaign, and today the only way to get one is to fork the whole ruleset file. The plan reserved layers for this (open decision 5): data that sits on top of the one ruleset a game pins, chosen in the wizard and frozen into the pin's options record, which has existed and stayed empty since slice 1.
  • This is the first slice: layers a ruleset ships inside its own file. They can never go missing for a pinned game, need no storage and no new import lane. Layers from other authors (a package asset, the community lanes) reuse this format and are a later slice; the plan says so.

What changed

  • Format. An optional layers array in ruleset.json (up to 12). A layer has an id, a label, a summary, optional conflicts, and effects from a closed list: Game Master guidance and world-generation guidance (appended), enum field values removed (never added, with a replacement default when the default goes), the difficulty ladder replaced, and catalog entries hidden from the picker by one comparison on a declared filter. Base rulesets gain the gm.worldGuidance slot too, which they lacked.
  • Cross-checks. Conflicts name real layers; a narrowed field is an enum, keeps at least one value and a valid default, and may not lose a value that a hideWhen rule on the sheet reads; a layer's ladder has the shape of the base kind's and passes that kind's own checks; a hidden-entry rule names a real catalog and filter and compares it the way its type allows.
  • One place applies them. applyRulesetLayers(definition, options) in shared is pure, returns the same object when no layer is on, re-validates its result, and falls back layer by layer so a game can never lose its ruleset to a layer. resolveGameRuleset returns that effective definition (plus the base one and the active layers' labels), so the check resolver, the Game Master prompt, the sheet block, sheet commands and the battle bridge all play by the layered rules with no change of their own. useGameRuleset does the same on the client.
  • Setup. The wizard shows one checkbox per layer under the chosen ruleset, disables a conflicting one with the reason, and says layers are fixed once the game starts. /game/create validates the selection (ruleset_layer_unknown, ruleset_layer_conflict, both 400) and freezes it into the pin. A shared setup file keeps the chosen layers, and ids the installed ruleset no longer has are dropped.
  • In play. World generation reads the ruleset's (layered) world guidance as its own context section, the in-game sheet names the ruleset "with" its layers, and the catalog picker leaves out what a layer hides while Refresh and scaled rows still see rows that were picked before.
  • Capability API 1.25 gates layers and gm.worldGuidance for packages.
  • Docs: the authoring guide (Layers), docs/game/getting-started.md, docs/development/optional-agent-packages.md, the plan (what layers L1 settled, L2 open), the generated schema, and a layer on each of the three example rulesets (Ember Roads "Hard winter", Gravewatch "The long night", the 5e example "Low magic" with a conflicting "High magic").
  • Regressions: game-ruleset-layers (schema refusals, application order, conflicts, unknown options ignored, same reference with none on, a layer that would not validate is skipped, /game/create refusals and the frozen pin, the prompt text, the 1.25 gate) and the client lane ruleset-layers-client (toggle logic, restore, the picker hiding entries).

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

Commands run locally by the agent: pnpm check (exit 0), pnpm localization:check, the full node regression lane (pnpm regression:node, 325 of 326: the one that did not pass is image-dimension-limit.regression.ts, which prints that it passed and then does not exit on this machine while it is under load; it is the same pino-pretty worker lifetime that #6359 worked around for the storage shutdown regression, this PR does not touch it, and CI's node lane has passed it on every ruleset PR), and the new regressions. Three complete local CodeRabbit sweeps were run before opening (3, 1 and 0 findings). Fixed: a layer may not remove an enum value that a hideWhen rule on the sheet reads, the editor schema asks for exactly one hide comparison, and the merged guidance cap counts its separators. One suggestion was declined and the reason is now a comment in the code: caching the layered resolution has nothing stable to key on, because the ruleset registry is deliberately re-read on every call so that install, update and import need no invalidation. The e2e suite was checked by reading it: no spec mentions a ruleset or mocks the ruleset routes, the one unnamed checkbox count in the suite runs on a wizard step where the rules chooser is not mounted, and the specs that create games send no ruleset. Playwright was not run locally.

The agent drove a scratch server on port 7820 with a fresh data folder through its API: imported the Ember Roads and 5e examples, and created games. A selection naming a layer the ruleset does not have was refused with ruleset_layer_unknown, "Low magic" together with "High magic" was refused with ruleset_layer_conflict, a game created with "Hard winter" carried options: { "layer.hard_winter": true } in its pin, and a game created without layers carried an empty record as before. The agent could not drive the wizard itself in its browser, so nothing visual below was seen.

Still to verify by hand:

  • Manually create a game in the wizard on a ruleset with layers: the checkboxes, the disabled conflicting layer and its reason, the note, and the two refusal messages.
  • Manually open the in-game sheet of a layered game: the header names the layers, a removed enum value is not offered, and a sheet that already holds it still shows it.
  • Manually open the catalog picker in a layered game and confirm hidden entries are gone from the list, the count and the filter options, while an earlier pick of a hidden entry still refreshes.
  • Manually run world generation with a real model and look for the ruleset's world guidance in the debug prompt log.
  • Manually confirm a ruleset without layers, and a game with none chosen, behave exactly as before.
  • Manually verify light mode and a phone-width viewport for the wizard step.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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)

Docs touched: CHANGELOG.md, docs/extending/writing-rulesets.md, docs/game/getting-started.md, docs/development/optional-agent-packages.md, the plan, the three example rulesets and the generated schema. The [docs-i18n] follow-up is batched for the ruleset slices.

UI evidence (if applicable)

To be added by a human: the wizard's layer toggles with a conflicting layer disabled, and the in-game sheet header of a layered game.

Summary by CodeRabbit

  • New Features
    • Added selectable ruleset layers for game setup, with variants that can adjust difficulty, character-sheet choices, catalog visibility, and Game Master guidance.
    • Layer selections are fixed for the game, with incompatible choices identified during setup.
    • World generation now supports ruleset-specific guidance.
    • Added layer support to shared game setup files and character sheets; existing character values remain unchanged.
  • Documentation
    • Updated ruleset authoring guidance, schemas, examples, and getting-started documentation.
    • Ruleset layers and world guidance require Capability API 1.25.

🔄 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/6370 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/19/2026 **Status:** ✅ Merged **Merged:** 9/19/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/rulesets-layers` --- ### 📝 Commits (10+) - [`fce2efe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fce2efe19147c8bd367108b3903bab9995993ad8) feat(rulesets): a ruleset may ship layers, and a base ruleset may guide world generation - [`655cd4e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/655cd4efd75b7119f03a886481105e3c171946ab) feat(game): resolve a game's ruleset with its layers, freeze the choice into the pin and guide world generation - [`3569720`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3569720f3e2f05ae24f66a1a9919c030ec5a8889) docs(rulesets): layers in the authoring guide, the setup guide, the capability list and the plan - [`a5b939b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a5b939b17f5a55fd3bafcd812c08387b0f5ea079) chore(rulesets): regenerate the published ruleset JSON Schema - [`d805217`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d8052175ae74692cb68616ff8fe3e1fe506e2f10) docs(rulesets): record layers L1 in the plan status line and drop an em dash - [`192f8ef`](https://github.com/Pasta-Devs/Marinara-Engine/commit/192f8ef1b56a1cf57c54a94fee975341560c281d) feat(game): the setup wizard offers a ruleset's layers and the game plays by them - [`020b760`](https://github.com/Pasta-Devs/Marinara-Engine/commit/020b760dd9124ea67435ea1fbfaea6a7f0049a9c) test(game): pin the wizard's layer toggles and the picker hiding layered catalog entries - [`fdc3695`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fdc36954121e43e4abd6f97c00bd3cff7cde8571) docs(rulesets): record that layers L1 is built on the client too - [`0ba0427`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0ba0427c766c063d57793a34b8a278e6d538a376) fix(game): the wizard sends only the layers the chosen ruleset still declares - [`58b75a6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/58b75a649883a10943a0113f1adee98565241f9a) fix(game): a layer cannot remove a value a hide rule reads, and the editor schema asks for one hide comparison ### 📊 Changes **38 files changed** (+2427 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/development/game-rulesets-and-sheets-implementation.md` (+19 -2) 📝 `docs/development/optional-agent-packages.md` (+26 -0) 📝 `docs/development/ruleset-5e-2014.example.json` (+25 -1) 📝 `docs/examples/rulesets/ember-roads.json` (+20 -1) 📝 `docs/examples/rulesets/gravewatch.json` (+19 -1) 📝 `docs/extending/ruleset.schema.json` (+232 -0) 📝 `docs/extending/writing-rulesets.md` (+70 -0) 📝 `docs/game/getting-started.md` (+2 -0) 📝 `packages/client/src/components/game/GameCharacterSheet.tsx` (+14 -1) 📝 `packages/client/src/components/game/GameRulesetSheet.tsx` (+24 -2) 📝 `packages/client/src/components/game/GameSetupRulesChooser.tsx` (+46 -0) 📝 `packages/client/src/components/game/GameSetupWizard.tsx` (+25 -1) 📝 `packages/client/src/components/game/GameSurface.tsx` (+4 -0) 📝 `packages/client/src/components/rulesets/RulesetCatalogPicker.tsx` (+13 -1) 📝 `packages/client/src/components/rulesets/RulesetSheetEditor.tsx` (+7 -0) 📝 `packages/client/src/hooks/use-game-ruleset.ts` (+36 -4) 📝 `packages/client/src/hooks/use-game.ts` (+22 -4) 📝 `packages/client/src/lib/game-setup-share.ts` (+4 -1) 📝 `packages/client/src/lib/ruleset-catalog.ts` (+20 -0) _...and 18 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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Part of #6314 (ruleset layers, first slice; it does not close the issue). Builds on #6368 (dice pools, merged). ## Why this change - A table rarely plays a system exactly as printed. "Low magic", "gritty winter", "no firearms" are choices made per campaign, and today the only way to get one is to fork the whole ruleset file. The plan reserved layers for this (open decision 5): data that sits on top of the one ruleset a game pins, chosen in the wizard and frozen into the pin's `options` record, which has existed and stayed empty since slice 1. - This is the first slice: layers a ruleset ships **inside its own file**. They can never go missing for a pinned game, need no storage and no new import lane. Layers from other authors (a package asset, the community lanes) reuse this format and are a later slice; the plan says so. ## What changed - **Format.** An optional `layers` array in `ruleset.json` (up to 12). A layer has an id, a label, a summary, optional `conflicts`, and effects from a closed list: Game Master guidance and world-generation guidance (appended), enum field values **removed** (never added, with a replacement default when the default goes), the difficulty ladder **replaced**, and catalog entries **hidden** from the picker by one comparison on a declared filter. Base rulesets gain the `gm.worldGuidance` slot too, which they lacked. - **Cross-checks.** Conflicts name real layers; a narrowed field is an enum, keeps at least one value and a valid default, and may not lose a value that a `hideWhen` rule on the sheet reads; a layer's ladder has the shape of the base kind's and passes that kind's own checks; a hidden-entry rule names a real catalog and filter and compares it the way its type allows. - **One place applies them.** `applyRulesetLayers(definition, options)` in shared is pure, returns the same object when no layer is on, re-validates its result, and falls back layer by layer so a game can never lose its ruleset to a layer. `resolveGameRuleset` returns that effective definition (plus the base one and the active layers' labels), so the check resolver, the Game Master prompt, the sheet block, sheet commands and the battle bridge all play by the layered rules with no change of their own. `useGameRuleset` does the same on the client. - **Setup.** The wizard shows one checkbox per layer under the chosen ruleset, disables a conflicting one with the reason, and says layers are fixed once the game starts. `/game/create` validates the selection (`ruleset_layer_unknown`, `ruleset_layer_conflict`, both 400) and freezes it into the pin. A shared setup file keeps the chosen layers, and ids the installed ruleset no longer has are dropped. - **In play.** World generation reads the ruleset's (layered) world guidance as its own context section, the in-game sheet names the ruleset "with" its layers, and the catalog picker leaves out what a layer hides while Refresh and scaled rows still see rows that were picked before. - **Capability API 1.25** gates `layers` and `gm.worldGuidance` for packages. - Docs: the authoring guide (Layers), `docs/game/getting-started.md`, `docs/development/optional-agent-packages.md`, the plan (what layers L1 settled, L2 open), the generated schema, and a layer on each of the three example rulesets (Ember Roads "Hard winter", Gravewatch "The long night", the 5e example "Low magic" with a conflicting "High magic"). - Regressions: `game-ruleset-layers` (schema refusals, application order, conflicts, unknown options ignored, same reference with none on, a layer that would not validate is skipped, `/game/create` refusals and the frozen pin, the prompt text, the 1.25 gate) and the client lane `ruleset-layers-client` (toggle logic, restore, the picker hiding entries). ## 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 Commands run locally by the agent: `pnpm check` (exit 0), `pnpm localization:check`, the full node regression lane (`pnpm regression:node`, 325 of 326: the one that did not pass is `image-dimension-limit.regression.ts`, which prints that it passed and then does not exit on this machine while it is under load; it is the same pino-pretty worker lifetime that #6359 worked around for the storage shutdown regression, this PR does not touch it, and CI's node lane has passed it on every ruleset PR), and the new regressions. Three complete local CodeRabbit sweeps were run before opening (3, 1 and 0 findings). Fixed: a layer may not remove an enum value that a `hideWhen` rule on the sheet reads, the editor schema asks for exactly one `hide` comparison, and the merged guidance cap counts its separators. One suggestion was declined and the reason is now a comment in the code: caching the layered resolution has nothing stable to key on, because the ruleset registry is deliberately re-read on every call so that install, update and import need no invalidation. The e2e suite was checked by reading it: no spec mentions a ruleset or mocks the ruleset routes, the one unnamed checkbox count in the suite runs on a wizard step where the rules chooser is not mounted, and the specs that create games send no ruleset. Playwright was not run locally. The agent drove a scratch server on port 7820 with a fresh data folder through its API: imported the Ember Roads and 5e examples, and created games. A selection naming a layer the ruleset does not have was refused with `ruleset_layer_unknown`, "Low magic" together with "High magic" was refused with `ruleset_layer_conflict`, a game created with "Hard winter" carried `options: { "layer.hard_winter": true }` in its pin, and a game created without layers carried an empty record as before. The agent could not drive the wizard itself in its browser, so nothing visual below was seen. Still to verify by hand: - Manually create a game in the wizard on a ruleset with layers: the checkboxes, the disabled conflicting layer and its reason, the note, and the two refusal messages. - Manually open the in-game sheet of a layered game: the header names the layers, a removed enum value is not offered, and a sheet that already holds it still shows it. - Manually open the catalog picker in a layered game and confirm hidden entries are gone from the list, the count and the filter options, while an earlier pick of a hidden entry still refreshes. - Manually run world generation with a real model and look for the ruleset's world guidance in the debug prompt log. - Manually confirm a ruleset without layers, and a game with none chosen, behave exactly as before. - Manually verify light mode and a phone-width viewport for the wizard step. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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) Docs touched: `CHANGELOG.md`, `docs/extending/writing-rulesets.md`, `docs/game/getting-started.md`, `docs/development/optional-agent-packages.md`, the plan, the three example rulesets and the generated schema. The `[docs-i18n]` follow-up is batched for the ruleset slices. ## UI evidence (if applicable) To be added by a human: the wizard's layer toggles with a conflicting layer disabled, and the in-game sheet header of a layered game. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added selectable ruleset layers for game setup, with variants that can adjust difficulty, character-sheet choices, catalog visibility, and Game Master guidance. * Layer selections are fixed for the game, with incompatible choices identified during setup. * World generation now supports ruleset-specific guidance. * Added layer support to shared game setup files and character sheets; existing character values remain unchanged. * **Documentation** * Updated ruleset authoring guidance, schemas, examples, and getting-started documentation. * Ruleset layers and world guidance require Capability API 1.25. <!-- 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-23 04:17:00 +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#7153
No description provided.