[PR #1644] [MERGED] Normalize legacy activeQuests shapes in one shared quest-merge helper #5176

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/quest-merge-normalize


📝 Commits (4)

  • ee061de Normalize legacy activeQuests shapes in one shared quest-merge helper
  • cfbb107 Make quest-collection normalization lossless for nested/keyed shapes
  • 7232c9d Format quest-merge files to repository Prettier style
  • d96d332 Don't promote a non-quest keyed record to a phantom quest

📊 Changes

4 files changed (+551 additions, -268 deletions)

View changed files

📝 src/engine/generation/tracker-snapshots.ts (+7 -233)
➕ src/engine/shared/game-state/player-stats.test.ts (+240 -0)
➕ src/engine/shared/game-state/player-stats.ts (+297 -0)
📝 src/features/runtime/generation/hooks/use-generate.ts (+7 -35)

📄 Description

Why this change

Two quest-merge code paths existed and neither restored the pre-rewrite tolerance for non-array activeQuests shapes (keyed quest maps, grouped containers, nested collections):

  • The engine tracker-snapshot path (tracker-snapshots.ts) normalized objectives and auto-removed completed quests, but clonePlayerStats dropped any keyed/grouped activeQuests to [].
  • The UI optimistic Quest Board path (use-generate.ts applyQuestUpdates) was an entirely separate, simpler merge: it matched quests by name only, passed objectives through raw, did no completed-removal, and also dropped non-array shapes.

So legacy/imported saves silently lost quests, and the optimistic and persisted merges diverged.

What changed

  • New src/engine/shared/game-state/player-stats.ts (mode-neutral deterministic helper) owns player-stats normalization, including the new normalizeActiveQuestCollection: handles plain arrays, keyed quest maps ({ questId: quest }), grouped/wrapper containers ({ quests | groups | items | activeQuests | children: [...] }), and nested collections, depth-guarded.
  • tracker-snapshots.ts and the UI Quest Board path now both call the same applyQuestUpdatesToPlayerStats, so optimistic and persisted merges are byte-identical (match by questEntryId then name, normalized objectives, completed-empty-objective removal).
  • Consolidating the helper removed ~70 lines of player-stats parsing (parseStat/parseInventoryItem/parseCustomTrackerField/clonePlayerStats/…) that had been duplicated across the two files. Dependency direction stays one-way (tracker-snapshots → player-stats, use-generate → player-stats); no import cycle.

Verification

  • pnpm check passes (architecture + frontend tsc + cargo check + docs).
  • New player-stats.test.ts (12 tests) covers keyed maps, grouped containers, object- and nested-shaped objectives, completed-empty-objective removal, create/update/fail matching by id and name, and the changed-flag semantics.
  • Adjacent engine suites (src/engine/generation, src/engine/shared, 229 tests) green.

Risk / behavior note

The UI optimistic path now matches by questEntryId | name (was name-only) and auto-removes completed-empty quests, matching the persisted path. This is the intended parity but is a visible delta: a completed quest that the optimistic UI previously kept on screen until the next storage refresh now disappears immediately. Worth a quick look in pnpm tauri dev against a real imported save before merge.

Linked issue

Closes #1530.


🔄 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/1644 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/30/2026 **Status:** ✅ Merged **Merged:** 5/30/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/quest-merge-normalize` --- ### 📝 Commits (4) - [`ee061de`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ee061de3863a3106a30a3953f86e7d8b078273fe) Normalize legacy activeQuests shapes in one shared quest-merge helper - [`cfbb107`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cfbb107f8f69fb94b1c3e5402bc699b4bdf98761) Make quest-collection normalization lossless for nested/keyed shapes - [`7232c9d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7232c9d8ff183170cbbe1af53ae88b5ce0f390df) Format quest-merge files to repository Prettier style - [`d96d332`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d96d332beece46c37321da9887867d83aab0ec10) Don't promote a non-quest keyed record to a phantom quest ### 📊 Changes **4 files changed** (+551 additions, -268 deletions) <details> <summary>View changed files</summary> 📝 `src/engine/generation/tracker-snapshots.ts` (+7 -233) ➕ `src/engine/shared/game-state/player-stats.test.ts` (+240 -0) ➕ `src/engine/shared/game-state/player-stats.ts` (+297 -0) 📝 `src/features/runtime/generation/hooks/use-generate.ts` (+7 -35) </details> ### 📄 Description ## Why this change Two quest-merge code paths existed and neither restored the pre-rewrite tolerance for non-array `activeQuests` shapes (keyed quest maps, grouped containers, nested collections): - The **engine tracker-snapshot** path (`tracker-snapshots.ts`) normalized objectives and auto-removed completed quests, but `clonePlayerStats` dropped any keyed/grouped `activeQuests` to `[]`. - The **UI optimistic Quest Board** path (`use-generate.ts applyQuestUpdates`) was an entirely separate, simpler merge: it matched quests by `name` only, passed objectives through raw, did no completed-removal, and also dropped non-array shapes. So legacy/imported saves silently lost quests, and the optimistic and persisted merges diverged. ## What changed - New `src/engine/shared/game-state/player-stats.ts` (mode-neutral deterministic helper) owns player-stats normalization, including the new `normalizeActiveQuestCollection`: handles plain arrays, keyed quest maps (`{ questId: quest }`), grouped/wrapper containers (`{ quests | groups | items | activeQuests | children: [...] }`), and nested collections, depth-guarded. - `tracker-snapshots.ts` and the UI Quest Board path now both call the same `applyQuestUpdatesToPlayerStats`, so optimistic and persisted merges are byte-identical (match by `questEntryId` then `name`, normalized objectives, completed-empty-objective removal). - Consolidating the helper removed ~70 lines of player-stats parsing (`parseStat`/`parseInventoryItem`/`parseCustomTrackerField`/`clonePlayerStats`/…) that had been duplicated across the two files. Dependency direction stays one-way (`tracker-snapshots → player-stats`, `use-generate → player-stats`); no import cycle. ## Verification - `pnpm check` passes (architecture + frontend tsc + cargo check + docs). - New `player-stats.test.ts` (12 tests) covers keyed maps, grouped containers, object- and nested-shaped objectives, completed-empty-objective removal, create/update/fail matching by id and name, and the changed-flag semantics. - Adjacent engine suites (`src/engine/generation`, `src/engine/shared`, 229 tests) green. ## Risk / behavior note The UI optimistic path now matches by `questEntryId | name` (was name-only) and auto-removes completed-empty quests, matching the persisted path. This is the intended parity but is a visible delta: a completed quest that the optimistic UI previously kept on screen until the next storage refresh now disappears immediately. Worth a quick look in `pnpm tauri dev` against a real imported save before merge. ## Linked issue Closes #1530. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:13:58 +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#5176
No description provided.