Normalize explicit campaign slot reads
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user