[PR #514] [MERGED] fix(game-combat): mobile layout, encounter trigger race, refresh restore, persona name in combat #4653

Closed
opened 2026-10-22 04:09:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/514
Author: @Romuromylus
Created: 5/7/2026
Status: ✅ Merged
Merged: 5/7/2026
Merged by: @Romuromylus

Base: main ← Head: fix/game-combat-mobile-and-timing


📝 Commits (8)

  • 4b0b77b fix(game-combat): mobile combat layout, encounter trigger race, refresh restore
  • 6c4d39f fix(game-combat): address CodeRabbit review on PR #514
  • a90f678 fix(encounter): use chat-scoped persona for combat init / resolve / summary prompts
  • 632467a fix(game-combat): self-heal "user" persona name in restored battles
  • cf6584f Merge branch 'main' into fix/game-combat-mobile-and-timing
  • 2602550 fix(game-combat): keepalive on unmount flush + scope narrationDone per message
  • b0aa58f fix(game-combat): apply quality-review must-fixes (narration guard, snapshot validation, persist logging)
  • 85dfac2 Merge branch 'main' into fix/game-combat-mobile-and-timing

📊 Changes

7 files changed (+1004 additions, -29 deletions)

View changed files

📝 packages/client/src/components/game/GameCombatUI.tsx (+719 -0)
📝 packages/client/src/components/game/GameNarration.tsx (+11 -4)
📝 packages/client/src/components/game/GameSurface.tsx (+227 -10)
📝 packages/client/src/lib/api-client.ts (+2 -1)
📝 packages/server/src/routes/encounter.routes.ts (+25 -13)
📝 packages/shared/src/types/chat.ts (+2 -0)
📝 packages/shared/src/types/game.ts (+18 -1)

📄 Description

Linked issue

Closes #513

Why this change

Game Mode combat has four issues that surface during ordinary play; bundling them so the deployment ships them together rather than four round-trips of build + verify:

  1. The encounter overlay races against the typewriter on the GM's pre-fight prose — either skipping the prose entirely (overlay slams open) or stalling for several seconds after the typewriter completes.
  2. The mobile combat UI was a responsive shrink of the desktop layout. Three prior attempts at tightening responsive CSS (sprite size, mechanic-card stacking, max-h caps) did not hold up: player card, enemy line, dialogue cue bubbles, and bottom action panel still overlap once round-2 panels appear.
  3. A page refresh during combat dropped the user back into prose narration — the live combat party/enemies/blueprint lived only in component-local React state.
  4. The player's combatant card showed the literal string "User" / "user" instead of the configured persona name. encounter.routes.ts buildPersonaContext only consulted isActive === "true" and ignored chat.personaId, so a user with a chat-scoped persona ended up named "User" in the encounter prompt and the LLM faithfully echoed that string.

What changed

  • Mobile combat UI is now a separate render path under the sm breakpoint (<640px) via matchMedia("(max-width: 639px)"). The desktop tree is untouched. Mobile uses a compact enemy strip pinned top, a scene area in the middle for narration / impact effects, and a sticky bottom action sheet that always shows the active player and current phase content (action menu / skill / item / custom-action / target-select). Boss mechanics, dialogue cues, the live combat log, and full party HP move into slide-up drawers triggered from a row of toggle buttons. New MobileCombatantChip subcomponent renders the compact enemy chips. Tablet keyboard parity: the mobile custom-action textarea also submits on (meta|ctrl)+Enter, and a global Escape listener closes any open drawer.
  • Encounter-trigger timing race is fixed by tagging narrationDone with the message ID it corresponds to. GameNarration.onNarrationComplete now passes the active segment's source message ID alongside the boolean. GameSurface keeps a narrationDoneMsgIdRef so the three encounter gates (combat encounter, combat generation, QTE) only treat narrationDone === true as authoritative when it matches the current latestAssistantMsg.id — defeating the stale "done" from the previous turn that previously slipped past the gate.
  • Combat state persists across refresh. A GameCombatStateSnapshot (party / enemies / itemEffects / mechanics / dialogueCues / startMessageId) is debounce-persisted to chat metadata while a fight is active and restored on mount before the existing tag-replay path runs. The restore guard is keyed by activeChatId so switching chats inside the same mounted GameSurface still gets a chance to restore. The persist effect's cleanup synchronously flushes the latest pending snapshot so a refresh inside the 800 ms debounce window cannot drop the most recent state. A shared clearCombatSnapshot(chatId) helper is called from both handleCombatEnd and handleReturnToPreCombatTurn, so backing out of an encounter wipes the persisted snapshot the same way a normal combat end does. GameCombatUI's narration prop is also derived from the trigger message's stripped GM prose so the actual setup text becomes the first combat-log entry instead of the placeholder "Combat starts!".
  • Persona name in combat now resolves the same way as the rest of the chat surface: prefer chat.personaId, fall back to the globally active persona, then fall back to "User" only when neither is set. The encounter init / resolve / summary prompt builders all read through the updated buildPersonaContext.

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

Verified on a Docker deployment of this branch:

  1. Mobile combat UI: opened a fight on a <640px viewport. The bottom action sheet stays visible, the enemy strip stays compact at the top, and Mechanics / Cues / Log / Party each open in a slide-up drawer. Desktop layout was unchanged at >=640px.
  2. Encounter-trigger timing: prompted the GM into a [combat:] situation. The overlay now waits for the typewriter to finish revealing the pre-fight prose before opening, and no longer stalls afterward.
  3. Refresh during combat: F5 mid-fight. Party / enemies / HP / mechanics restored to the same state instead of falling back to prose narration.
  4. Persona name in combat: the player's combatant card now shows the configured persona name instead of "user".

Docs and release impact

  • No docs changes needed

UI evidence (if applicable)

image

Desktop UI should be unaffected :
image

Summary by CodeRabbit

  • New Features

    • Optimized mobile combat interface featuring a compact layout with horizontally scrollable enemy display, sticky action menus, and collapsible information drawers (Party, Mechanics, Cues, Log).
  • Bug Fixes

    • Combat now persists across page refreshes during ongoing battles.
    • Fixed race conditions preventing combat from properly initiating after narration completes.
    • Improved player character handling in combat encounters.

🔄 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/514 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/7/2026 **Status:** ✅ Merged **Merged:** 5/7/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/game-combat-mobile-and-timing` --- ### 📝 Commits (8) - [`4b0b77b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4b0b77bf086db9c79dc682ce20d79de47bbfcc62) fix(game-combat): mobile combat layout, encounter trigger race, refresh restore - [`6c4d39f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6c4d39f38faf292ee5891f9a9b21c28afad98447) fix(game-combat): address CodeRabbit review on PR #514 - [`a90f678`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a90f6788a2c5a4afa18acbd4ea5ad33209d625e1) fix(encounter): use chat-scoped persona for combat init / resolve / summary prompts - [`632467a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/632467aa2de33ee9ffff475dcdb51f3f9c8f6b3a) fix(game-combat): self-heal "user" persona name in restored battles - [`cf6584f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cf6584f773978b2662f0413a82233913218a7057) Merge branch 'main' into fix/game-combat-mobile-and-timing - [`2602550`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2602550a10f0e86395065a4bcb1520cd8f1bafd7) fix(game-combat): keepalive on unmount flush + scope narrationDone per message - [`b0aa58f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b0aa58f747b355ab883e8cea26424aae041f22da) fix(game-combat): apply quality-review must-fixes (narration guard, snapshot validation, persist logging) - [`85dfac2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/85dfac2175d2e60aed86dc3041a8ad8572379047) Merge branch 'main' into fix/game-combat-mobile-and-timing ### 📊 Changes **7 files changed** (+1004 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/game/GameCombatUI.tsx` (+719 -0) 📝 `packages/client/src/components/game/GameNarration.tsx` (+11 -4) 📝 `packages/client/src/components/game/GameSurface.tsx` (+227 -10) 📝 `packages/client/src/lib/api-client.ts` (+2 -1) 📝 `packages/server/src/routes/encounter.routes.ts` (+25 -13) 📝 `packages/shared/src/types/chat.ts` (+2 -0) 📝 `packages/shared/src/types/game.ts` (+18 -1) </details> ### 📄 Description ## Linked issue Closes #513 ## Why this change Game Mode combat has four issues that surface during ordinary play; bundling them so the deployment ships them together rather than four round-trips of build + verify: 1. The encounter overlay races against the typewriter on the GM's pre-fight prose — either skipping the prose entirely (overlay slams open) or stalling for several seconds after the typewriter completes. 2. The mobile combat UI was a responsive shrink of the desktop layout. Three prior attempts at tightening responsive CSS (sprite size, mechanic-card stacking, max-h caps) did not hold up: player card, enemy line, dialogue cue bubbles, and bottom action panel still overlap once round-2 panels appear. 3. A page refresh during combat dropped the user back into prose narration — the live combat party/enemies/blueprint lived only in component-local React state. 4. The player's combatant card showed the literal string "User" / "user" instead of the configured persona name. `encounter.routes.ts buildPersonaContext` only consulted `isActive === "true"` and ignored `chat.personaId`, so a user with a chat-scoped persona ended up named "User" in the encounter prompt and the LLM faithfully echoed that string. ## What changed - **Mobile combat UI is now a separate render path** under the `sm` breakpoint (`<640px`) via `matchMedia("(max-width: 639px)")`. The desktop tree is untouched. Mobile uses a compact enemy strip pinned top, a scene area in the middle for narration / impact effects, and a sticky bottom action sheet that always shows the active player and current phase content (action menu / skill / item / custom-action / target-select). Boss mechanics, dialogue cues, the live combat log, and full party HP move into slide-up drawers triggered from a row of toggle buttons. New `MobileCombatantChip` subcomponent renders the compact enemy chips. Tablet keyboard parity: the mobile custom-action textarea also submits on `(meta|ctrl)+Enter`, and a global Escape listener closes any open drawer. - **Encounter-trigger timing race** is fixed by tagging `narrationDone` with the message ID it corresponds to. `GameNarration.onNarrationComplete` now passes the active segment's source message ID alongside the boolean. `GameSurface` keeps a `narrationDoneMsgIdRef` so the three encounter gates (combat encounter, combat generation, QTE) only treat `narrationDone === true` as authoritative when it matches the current `latestAssistantMsg.id` — defeating the stale "done" from the previous turn that previously slipped past the gate. - **Combat state persists across refresh.** A `GameCombatStateSnapshot` (party / enemies / itemEffects / mechanics / dialogueCues / startMessageId) is debounce-persisted to chat metadata while a fight is active and restored on mount before the existing tag-replay path runs. The restore guard is keyed by `activeChatId` so switching chats inside the same mounted `GameSurface` still gets a chance to restore. The persist effect's cleanup synchronously flushes the latest pending snapshot so a refresh inside the 800 ms debounce window cannot drop the most recent state. A shared `clearCombatSnapshot(chatId)` helper is called from both `handleCombatEnd` and `handleReturnToPreCombatTurn`, so backing out of an encounter wipes the persisted snapshot the same way a normal combat end does. `GameCombatUI`'s `narration` prop is also derived from the trigger message's stripped GM prose so the actual setup text becomes the first combat-log entry instead of the placeholder "Combat starts!". - **Persona name in combat** now resolves the same way as the rest of the chat surface: prefer `chat.personaId`, fall back to the globally active persona, then fall back to "User" only when neither is set. The encounter init / resolve / summary prompt builders all read through the updated `buildPersonaContext`. ## Validation - [x] `pnpm check` passes locally - [x] 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 Verified on a Docker deployment of this branch: 1. Mobile combat UI: opened a fight on a `<640px` viewport. The bottom action sheet stays visible, the enemy strip stays compact at the top, and Mechanics / Cues / Log / Party each open in a slide-up drawer. Desktop layout was unchanged at `>=640px`. 2. Encounter-trigger timing: prompted the GM into a `[combat:]` situation. The overlay now waits for the typewriter to finish revealing the pre-fight prose before opening, and no longer stalls afterward. 3. Refresh during combat: F5 mid-fight. Party / enemies / HP / mechanics restored to the same state instead of falling back to prose narration. 4. Persona name in combat: the player's combatant card now shows the configured persona name instead of "user". ## Docs and release impact - [x] No docs changes needed ## UI evidence (if applicable) <img width="481" height="830" alt="image" src="https://github.com/user-attachments/assets/35a662f8-8d63-409e-a970-5b83446fa61b" /> Desktop UI should be unaffected : <img width="1280" height="665" alt="image" src="https://github.com/user-attachments/assets/6931ddf4-f8e6-4993-bd6c-b5fe249558dc" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Optimized mobile combat interface featuring a compact layout with horizontally scrollable enemy display, sticky action menus, and collapsible information drawers (Party, Mechanics, Cues, Log). * **Bug Fixes** * Combat now persists across page refreshes during ongoing battles. * Fixed race conditions preventing combat from properly initiating after narration completes. * Improved player character handling in combat encounters. <!-- 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-22 04:09:30 +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#4653
No description provided.