From 6d17e863254998b6fb8a8a05d2efd8d8cd9cea29 Mon Sep 17 00:00:00 2001 From: Wickedness Date: Sun, 5 Jul 2026 11:06:01 +0900 Subject: [PATCH] Normalize explicit campaign slot reads --- .../verify-campaign-save-normalization.mjs | 27 +++++++++++++++++++ src/game/state/campaignState.ts | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/verify-campaign-save-normalization.mjs b/scripts/verify-campaign-save-normalization.mjs index 6915eeb..85b0874 100644 --- a/scripts/verify-campaign-save-normalization.mjs +++ b/scripts/verify-campaign-save-normalization.mjs @@ -679,6 +679,33 @@ try { const fallback = loadCampaignState(); assert(fallback.step === 'second-camp' && fallback.activeSaveSlot === 2, `Expected valid slotted save fallback: ${JSON.stringify(fallback)}`); + storage.clear(); + storage.set( + campaignStorageKey, + JSON.stringify({ + version: 1, + updatedAt: '2026-07-01T00:00:00.000Z', + step: 'first-camp', + activeSaveSlot: 1, + gold: 100 + }) + ); + storage.set( + `${campaignStorageKey}:slot-1`, + JSON.stringify({ + version: 1, + updatedAt: '2026-07-02T00:00:00.000Z', + step: 'second-camp', + activeSaveSlot: 1, + gold: 200 + }) + ); + const normalizedSlotFallback = loadCampaignState(0); + assert( + normalizedSlotFallback.step === 'second-camp' && normalizedSlotFallback.gold === 200, + `Expected explicit slot boundary values to normalize to slot 1 instead of base save: ${JSON.stringify(normalizedSlotFallback)}` + ); + storage.clear(); storage.set(campaignStorageKey, JSON.stringify({ version: 99, step: 'sixty-sixth-camp' })); storage.set( diff --git a/src/game/state/campaignState.ts b/src/game/state/campaignState.ts index f8086e9..b98d0ce 100644 --- a/src/game/state/campaignState.ts +++ b/src/game/state/campaignState.ts @@ -1298,7 +1298,7 @@ function readStoredCampaignState(slot?: number) { } function readStoredCampaignStateObject(slot?: number) { - const raw = tryStorage()?.getItem(slot ? campaignSaveSlotKey(slot) : campaignStorageKey); + const raw = tryStorage()?.getItem(slot === undefined ? campaignStorageKey : campaignSaveSlotKey(slot)); if (!raw) { return undefined; }