[PR #6762] [MERGED] feat(game): change an inventory stack by any amount, split it and merge it #7317

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

📋 Pull Request Information

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

Base: staging ← Head: feat/inventory-stacks


📝 Commits (3)

  • 832372f feat(game): change an inventory stack by any amount, split it and merge it
  • 747b9d6 Merge remote-tracking branch 'origin/staging' into feat/inventory-stacks
  • ea894b5 fix(game): stack ids trim dashes without a backtracking pattern, and a fight takes item totals past 10,000

📊 Changes

15 files changed (+1287 additions, -428 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 docs/game/party-and-npcs.md (+11 -0)
➕ e2e/game-inventory-stacks.e2e.ts (+129 -0)
📝 packages/client/src/components/game/GameInventory.tsx (+231 -100)
📝 packages/client/src/components/game/GameSurface.tsx (+244 -271)
➕ packages/client/src/lib/game-inventory-amount.ts (+20 -0)
📝 packages/client/src/localization/locales/en.json (+19 -0)
📝 packages/client/vite.config.ts (+3 -0)
📝 packages/server/src/routes/combat-director.routes.ts (+22 -11)
📝 packages/server/src/routes/game.routes.ts (+2 -38)
📝 packages/server/src/routes/generate.routes.ts (+5 -6)
📝 packages/shared/src/index.ts (+1 -0)
➕ packages/shared/src/utils/game-inventory-stacks.ts (+270 -0)
📝 scripts/regressions/combat-director-route.regression.ts (+22 -2)
➕ scripts/regressions/game-inventory-stacks.regression.ts (+306 -0)

📄 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 #6759

Why this change

Game Mode's inventory could only change a stack one item at a time, so adding or removing 300 of something took 300 clicks, and there was no way to split a pile. Behind that, inventory entries had no id, and every operation found a stack by its name. Two consequences, both fixed here:

  • Adding by name added to every stack with that name (addInventoryUnit). That only worked because two stacks of one name never existed.
  • Starting a new session kept only the first entry of each name. It merged by name (mergeGameInventoryItems), so any second stack would have been silently lost.

This is slice I0 of the ruleset items plan. Per-character bags, ruleset item catalogs, currencies and loot build on stack ids. It needs no ruleset and no Capability API change.

What changed

  • Stacks have ids. A shared module (packages/shared/src/utils/game-inventory-stacks.ts) holds pure helpers the client, the combat director and the session carry-over all use.
    • A saved entry without an id gets one worked out from its name and position, so a saved game reads with the same ids every time. The id is stored with the next change, so no migration is needed.
  • Any amount. The number between - and + is now a field. A number sets the count, and +N or -N adds or takes that many. Setting a stack of more than one to 0 asks first.
  • Split. Split asks how many go into the new stack (1 to one less than the stack). 300 split by 100 leaves 200 and 100 side by side, and the total never changes.
  • Merge. Dropping a stack onto another stack of the same item merges them into the target's place. Dropping onto a different item still swaps the two. Stacks never merge by themselves.
  • Named operations across stacks.
    • The Game Master's [inventory: add] adds to the first stack of that name, or makes a new one.
    • [inventory: remove] takes from the stacks of that name top to bottom and removes the ones it empties. It never takes more than there is, and the notification and journal say how many really went.
    • The per-command bound of 9999 is unchanged.
  • One line per item where a split means nothing. The Game Master's inventory block and the combat director both see totals per item. When a fight is saved, the director takes what it spent across stacks.
  • Renaming renames that stack only. Renaming it to an item you already have adds it to that item's first stack, as renaming always did.
  • The detailed inventory on the game state (playerStats.inventory) keeps one entry per item and follows every change of count. A split, a merge or a reorder leaves it alone.
  • Session carry-over keeps every stack and its id, and adds only the detailed-inventory items no stack holds.
  • Docs. A new "The inventory" section in docs/game/party-and-npcs.md (no page described the inventory screen before), and the CHANGELOG.
  • Refactor. The six inventory handlers in GameSurface now share one save helper (commitInventory) instead of six copies of the save-and-roll-back code. Their fallback error toasts are localized.

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

Run by the agent on 832372fef (this branch's one commit on staging 72cdaeb46): pnpm check exits 0 (localization and the new bundle budget included), pnpm regression:node passes 411/411, and pnpm smoke:ui passes 7/7. pnpm regression:ui e2e/game-inventory-stacks.e2e.ts e2e/game-combat-ai.e2e.ts e2e/game-combat-director.e2e.ts --project=desktop-chromium --workers=1 passed 12/12 twice. A third run passed 11/12: the #6741 style test flaked, because the fight's seed is random and the rats can down Ada before her first turn. That test does not touch the inventory; its fix is a separate PR.

The build now fails any lazy chunk past 500 KiB (added on staging in #6756), and this change took GameSurface 0.09 kB past it. The inventory screen now has its own chunk (game-inventory, 13.7 kB), the way the narration formatter and tag parser already do, which leaves GameSurface at 487 kB.

  • New lane scripts/regressions/game-inventory-stacks.regression.ts covers:
    • stable ids for a saved inventory with none, stored ids reserved first, and a duplicated stored id;
    • adding onto the first stack only (with a new stack for what a full one cannot hold, and broken or oversized counts refused), and taking across stacks, top to bottom and never more than there is;
    • setting a count, splitting (300 by 100, and every refused size), and merging (same item only, the target keeps its place, the bound refused);
    • renaming one stack, and pouring into an existing item;
    • the carry-over keeping both halves of a split, and every detailed entry of a name no stack holds;
    • the amount field's counts, +N, -N and refusals.
  • scripts/regressions/combat-director-route.regression.ts now seeds the potion as two split stacks. It checks that the fight sees one total, and that spending one empties the first stack and keeps the second with its id.
  • New browser test e2e/game-inventory-stacks.e2e.ts, starting from a saved inventory without ids:
    • splits 300 apples by 100 and checks the saved stacks have distinct ids;
    • types +50 into one stack;
    • drags one stack onto the other to merge them;
    • sets 0, declines, then accepts, and checks it was asked exactly once.
  • Eighteen deliberate breaks of these rules, in the helpers, the amount field, its commit guard and the combat director, were each caught.

Local CodeRabbit (coderabbit review --agent --committed), four passes: 1, 2, 5 and 0 findings, all fixed:

  • the inventory handlers read the latest saved inventory rather than the render's, so a second quick action builds on the first;
  • taking by name is no longer held to one stack's bound, so several full stacks can be emptied at once;
  • adding past a full stack starts a new stack instead of dropping the rest;
  • an addition that is not a number, or larger than one stack, is refused;
  • every stored stack id is reserved before any is worked out, so an entry saved without an id can never take a later stack's id;
  • the carry-over counts every detailed entry of a name no stack holds;
  • one commit of the amount field at a time: Enter disables the field while it saves, which blurred it and asked "remove all?" a second time. The browser test now counts the prompts, and fails with two when the guard is removed.

Still to verify by hand (not done by the agent):

  • Open a Game Mode game with an item you have several of, open Inventory, select it, and split some off. Confirm both stacks show the right counts and survive a reload.
  • Type +10, -3 and a plain number into the amount field, and confirm each.
  • Drag one stack onto another of the same item and confirm they merge. Drag onto a different item and confirm they swap.
  • Let the Game Master add and remove an item you have split, and confirm it adds to the first stack and removes across stacks.
  • Use an item from a split stack in a classic fight, and confirm the fight shows one total and the inventory goes down by one afterwards.
  • Start the next session and confirm split stacks carried over.
  • Check the inventory at mobile width and in light mode.

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: docs/game/party-and-npcs.md (carried by docs-i18n) and CHANGELOG.md. Translations are batched: this section joins the next batched [docs-i18n] issue for the items arc, so no per-PR issue is opened.

UI evidence (if applicable)

The browser test saves two screenshots: the split row open with a size typed in, and two stacks of one item after a split and a typed +50.

Summary by CodeRabbit

  • New Features
    • Edit stack quantities with counts or +N/-N adjustments; split, merge matching stacks, reorder items, and rename stacks.
    • Inventory changes are saved and carried into new sessions. Game Master actions and combat display combined item counts across stacks.
    • Confirm before emptying a stack that contains more than one item.
  • Documentation
    • Added a guide to managing inventory, including stack controls and how item counts work during gameplay.

🔄 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/6762 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/27/2026 **Status:** ✅ Merged **Merged:** 9/27/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/inventory-stacks` --- ### 📝 Commits (3) - [`832372f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/832372fefc87abdf93110b782b0ec911ef7fd918) feat(game): change an inventory stack by any amount, split it and merge it - [`747b9d6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/747b9d6bd618507eeb5d551b4c4e67201f86bc1d) Merge remote-tracking branch 'origin/staging' into feat/inventory-stacks - [`ea894b5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ea894b5d0ceceae90ec3ecb2031cf59002dcaf59) fix(game): stack ids trim dashes without a backtracking pattern, and a fight takes item totals past 10,000 ### 📊 Changes **15 files changed** (+1287 additions, -428 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/game/party-and-npcs.md` (+11 -0) ➕ `e2e/game-inventory-stacks.e2e.ts` (+129 -0) 📝 `packages/client/src/components/game/GameInventory.tsx` (+231 -100) 📝 `packages/client/src/components/game/GameSurface.tsx` (+244 -271) ➕ `packages/client/src/lib/game-inventory-amount.ts` (+20 -0) 📝 `packages/client/src/localization/locales/en.json` (+19 -0) 📝 `packages/client/vite.config.ts` (+3 -0) 📝 `packages/server/src/routes/combat-director.routes.ts` (+22 -11) 📝 `packages/server/src/routes/game.routes.ts` (+2 -38) 📝 `packages/server/src/routes/generate.routes.ts` (+5 -6) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `packages/shared/src/utils/game-inventory-stacks.ts` (+270 -0) 📝 `scripts/regressions/combat-director-route.regression.ts` (+22 -2) ➕ `scripts/regressions/game-inventory-stacks.regression.ts` (+306 -0) </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 Closes #6759 ## Why this change Game Mode's inventory could only change a stack one item at a time, so adding or removing 300 of something took 300 clicks, and there was no way to split a pile. Behind that, inventory entries had no id, and every operation found a stack by its name. Two consequences, both fixed here: - **Adding by name added to every stack** with that name (`addInventoryUnit`). That only worked because two stacks of one name never existed. - **Starting a new session kept only the first entry of each name.** It merged by name (`mergeGameInventoryItems`), so any second stack would have been silently lost. This is slice I0 of the ruleset items plan. Per-character bags, ruleset item catalogs, currencies and loot build on stack ids. It needs no ruleset and no Capability API change. ## What changed - **Stacks have ids.** A shared module (`packages/shared/src/utils/game-inventory-stacks.ts`) holds pure helpers the client, the combat director and the session carry-over all use. - A saved entry without an id gets one worked out from its name and position, so a saved game reads with the same ids every time. The id is stored with the next change, so no migration is needed. - **Any amount.** The number between **-** and **+** is now a field. A number sets the count, and `+N` or `-N` adds or takes that many. Setting a stack of more than one to 0 asks first. - **Split.** **Split** asks how many go into the new stack (1 to one less than the stack). 300 split by 100 leaves 200 and 100 side by side, and the total never changes. - **Merge.** Dropping a stack onto another stack of the same item merges them into the target's place. Dropping onto a different item still swaps the two. Stacks never merge by themselves. - **Named operations across stacks.** - The Game Master's `[inventory: add]` adds to the first stack of that name, or makes a new one. - `[inventory: remove]` takes from the stacks of that name top to bottom and removes the ones it empties. It never takes more than there is, and the notification and journal say how many really went. - The per-command bound of 9999 is unchanged. - **One line per item where a split means nothing.** The Game Master's inventory block and the combat director both see totals per item. When a fight is saved, the director takes what it spent across stacks. - **Renaming** renames that stack only. Renaming it to an item you already have adds it to that item's first stack, as renaming always did. - **The detailed inventory** on the game state (`playerStats.inventory`) keeps one entry per item and follows every change of count. A split, a merge or a reorder leaves it alone. - **Session carry-over** keeps every stack and its id, and adds only the detailed-inventory items no stack holds. - **Docs.** A new "The inventory" section in `docs/game/party-and-npcs.md` (no page described the inventory screen before), and the CHANGELOG. - **Refactor.** The six inventory handlers in `GameSurface` now share one save helper (`commitInventory`) instead of six copies of the save-and-roll-back code. Their fallback error toasts are localized. ## 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 Run by the agent on 832372fef (this branch's one commit on staging 72cdaeb46): `pnpm check` exits 0 (localization and the new bundle budget included), `pnpm regression:node` passes 411/411, and `pnpm smoke:ui` passes 7/7. `pnpm regression:ui e2e/game-inventory-stacks.e2e.ts e2e/game-combat-ai.e2e.ts e2e/game-combat-director.e2e.ts --project=desktop-chromium --workers=1` passed 12/12 twice. A third run passed 11/12: the #6741 style test flaked, because the fight's seed is random and the rats can down Ada before her first turn. That test does not touch the inventory; its fix is a separate PR. The build now fails any lazy chunk past 500 KiB (added on staging in #6756), and this change took `GameSurface` 0.09 kB past it. The inventory screen now has its own chunk (`game-inventory`, 13.7 kB), the way the narration formatter and tag parser already do, which leaves `GameSurface` at 487 kB. - New lane `scripts/regressions/game-inventory-stacks.regression.ts` covers: - stable ids for a saved inventory with none, stored ids reserved first, and a duplicated stored id; - adding onto the first stack only (with a new stack for what a full one cannot hold, and broken or oversized counts refused), and taking across stacks, top to bottom and never more than there is; - setting a count, splitting (300 by 100, and every refused size), and merging (same item only, the target keeps its place, the bound refused); - renaming one stack, and pouring into an existing item; - the carry-over keeping both halves of a split, and every detailed entry of a name no stack holds; - the amount field's counts, `+N`, `-N` and refusals. - `scripts/regressions/combat-director-route.regression.ts` now seeds the potion as two split stacks. It checks that the fight sees one total, and that spending one empties the first stack and keeps the second with its id. - New browser test `e2e/game-inventory-stacks.e2e.ts`, starting from a saved inventory without ids: - splits 300 apples by 100 and checks the saved stacks have distinct ids; - types `+50` into one stack; - drags one stack onto the other to merge them; - sets 0, declines, then accepts, and checks it was asked exactly once. - Eighteen deliberate breaks of these rules, in the helpers, the amount field, its commit guard and the combat director, were each caught. Local CodeRabbit (`coderabbit review --agent --committed`), four passes: 1, 2, 5 and 0 findings, all fixed: - the inventory handlers read the latest saved inventory rather than the render's, so a second quick action builds on the first; - taking by name is no longer held to one stack's bound, so several full stacks can be emptied at once; - adding past a full stack starts a new stack instead of dropping the rest; - an addition that is not a number, or larger than one stack, is refused; - every stored stack id is reserved before any is worked out, so an entry saved without an id can never take a later stack's id; - the carry-over counts every detailed entry of a name no stack holds; - one commit of the amount field at a time: Enter disables the field while it saves, which blurred it and asked "remove all?" a second time. The browser test now counts the prompts, and fails with two when the guard is removed. Still to verify by hand (not done by the agent): - Open a Game Mode game with an item you have several of, open **Inventory**, select it, and split some off. Confirm both stacks show the right counts and survive a reload. - Type `+10`, `-3` and a plain number into the amount field, and confirm each. - Drag one stack onto another of the same item and confirm they merge. Drag onto a different item and confirm they swap. - Let the Game Master add and remove an item you have split, and confirm it adds to the first stack and removes across stacks. - Use an item from a split stack in a classic fight, and confirm the fight shows one total and the inventory goes down by one afterwards. - Start the next session and confirm split stacks carried over. - Check the inventory at mobile width and in light mode. ## 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: `docs/game/party-and-npcs.md` (carried by `docs-i18n`) and `CHANGELOG.md`. Translations are batched: this section joins the next batched `[docs-i18n]` issue for the items arc, so no per-PR issue is opened. ## UI evidence (if applicable) The browser test saves two screenshots: the split row open with a size typed in, and two stacks of one item after a split and a typed `+50`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Edit stack quantities with counts or `+N`/`-N` adjustments; split, merge matching stacks, reorder items, and rename stacks. * Inventory changes are saved and carried into new sessions. Game Master actions and combat display combined item counts across stacks. * Confirm before emptying a stack that contains more than one item. * **Documentation** * Added a guide to managing inventory, including stack controls and how item counts work during gameplay. <!-- 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:18:35 +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#7317
No description provided.