Recover legacy campaign saves
This commit is contained in:
@@ -780,8 +780,11 @@ function ensureCampaignState() {
|
||||
return campaignState;
|
||||
}
|
||||
|
||||
function normalizeCampaignState(state: CampaignState): CampaignState {
|
||||
const normalized = cloneCampaignState(state);
|
||||
function normalizeCampaignState(state: Partial<CampaignState>): CampaignState {
|
||||
const normalized = {
|
||||
...createInitialCampaignState(),
|
||||
...cloneCampaignState(state as CampaignState)
|
||||
};
|
||||
normalized.version = 1;
|
||||
normalized.updatedAt = normalized.updatedAt || new Date().toISOString();
|
||||
normalized.activeSaveSlot = normalizeSlot(normalized.activeSaveSlot);
|
||||
@@ -837,8 +840,11 @@ function readStoredCampaignState(slot?: number) {
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(raw) as CampaignState;
|
||||
if (!parsed || parsed.version !== 1) {
|
||||
const parsed = JSON.parse(raw) as Partial<CampaignState> | null;
|
||||
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
||||
return undefined;
|
||||
}
|
||||
if (parsed.version !== undefined && parsed.version !== 1) {
|
||||
return undefined;
|
||||
}
|
||||
return normalizeCampaignState(parsed);
|
||||
|
||||
Reference in New Issue
Block a user