Normalize explicit campaign slot reads

This commit is contained in:
2026-07-05 11:06:01 +09:00
parent 5c9983b2d7
commit 6d17e86325
2 changed files with 28 additions and 1 deletions

View File

@@ -679,6 +679,33 @@ try {
const fallback = loadCampaignState(); const fallback = loadCampaignState();
assert(fallback.step === 'second-camp' && fallback.activeSaveSlot === 2, `Expected valid slotted save fallback: ${JSON.stringify(fallback)}`); 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.clear();
storage.set(campaignStorageKey, JSON.stringify({ version: 99, step: 'sixty-sixth-camp' })); storage.set(campaignStorageKey, JSON.stringify({ version: 99, step: 'sixty-sixth-camp' }));
storage.set( storage.set(

View File

@@ -1298,7 +1298,7 @@ function readStoredCampaignState(slot?: number) {
} }
function readStoredCampaignStateObject(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) { if (!raw) {
return undefined; return undefined;
} }