Recover battle history keys by id

This commit is contained in:
2026-07-05 09:41:40 +09:00
parent 7185566b5d
commit 5c7cfed12e
2 changed files with 7 additions and 6 deletions

View File

@@ -164,7 +164,7 @@ try {
updatedAt: '2026-07-04T01:00:00.000Z', updatedAt: '2026-07-04T01:00:00.000Z',
step: 'fifth-camp', step: 'fifth-camp',
battleHistory: { battleHistory: {
'first-battle-zhuo-commandery': { 'wrong-history-key': {
battleId: 'first-battle-zhuo-commandery', battleId: 'first-battle-zhuo-commandery',
battleTitle: 'Zhuo Commandery', battleTitle: 'Zhuo Commandery',
outcome: 'victory', outcome: 'victory',
@@ -220,8 +220,9 @@ try {
const malformedHistory = loadCampaignState(); const malformedHistory = loadCampaignState();
assert( assert(
Object.keys(malformedHistory.battleHistory).length === 1 && Object.keys(malformedHistory.battleHistory).length === 1 &&
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.rewardGold === 120, malformedHistory.battleHistory['first-battle-zhuo-commandery']?.rewardGold === 120 &&
`Expected malformed battle history entries to be filtered while keeping valid settlements: ${JSON.stringify(malformedHistory)}` malformedHistory.battleHistory['wrong-history-key'] === undefined,
`Expected malformed battle history entries to be filtered while valid settlements are keyed by battleId: ${JSON.stringify(malformedHistory)}`
); );
assert( assert(
malformedHistory.battleHistory['first-battle-zhuo-commandery']?.itemRewards.length === 1 && malformedHistory.battleHistory['first-battle-zhuo-commandery']?.itemRewards.length === 1 &&
@@ -263,7 +264,7 @@ 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)}`);
console.log('Verified campaign save normalization, malformed-field/bond/sortie-item/history-detail recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.'); console.log('Verified campaign save normalization, malformed-field/bond/sortie-item/history-key/detail recovery, unknown-step/report/history recovery, unsupported-version rejection, and slotted fallback.');
} finally { } finally {
await server.close(); await server.close();
} }

View File

@@ -852,13 +852,13 @@ function normalizeInventory(value: unknown) {
} }
function normalizeBattleHistory(value: unknown) { function normalizeBattleHistory(value: unknown) {
return Object.entries(recordOrEmpty<unknown>(value)).reduce<Record<string, CampaignBattleSettlement>>((history, [key, settlement]) => { return Object.entries(recordOrEmpty<unknown>(value)).reduce<Record<string, CampaignBattleSettlement>>((history, [, settlement]) => {
const normalizedSettlement = normalizeCampaignBattleSettlement(settlement); const normalizedSettlement = normalizeCampaignBattleSettlement(settlement);
if (!normalizedSettlement) { if (!normalizedSettlement) {
return history; return history;
} }
history[key] = normalizedSettlement; history[normalizedSettlement.battleId] = normalizedSettlement;
return history; return history;
}, {}); }, {});
} }