Harden sortie item assignment recovery

This commit is contained in:
2026-07-05 12:22:47 +09:00
parent 81bc2461ed
commit 8a73169263
2 changed files with 33 additions and 7 deletions

View File

@@ -45,9 +45,11 @@ try {
const normalizedLaunchSupplies = normalizeCampaignSortieItemAssignments(
{
'liu-bei': { bean: '9', salve: '2', stone: '4' },
'liu-bei': { ' bean ': '9', salve: '2', stone: '4', ['x'.repeat(97)]: '1' },
' liu-bei ': { wine: '1' },
'guan-yu': { wine: '3' },
'ghost-unit': { bean: '1' },
['x'.repeat(97)]: { bean: '1' },
'': { bean: '1' }
},
new Set(['liu-bei', 'guan-yu'])
@@ -56,10 +58,21 @@ try {
normalizedLaunchSupplies['liu-bei']?.bean === 2 &&
normalizedLaunchSupplies['liu-bei']?.salve === 1 &&
normalizedLaunchSupplies['liu-bei']?.stone === undefined &&
normalizedLaunchSupplies['liu-bei']?.wine === 1 &&
normalizedLaunchSupplies['liu-bei']?.['x'.repeat(97)] === undefined &&
normalizedLaunchSupplies['guan-yu']?.wine === 1 &&
normalizedLaunchSupplies['ghost-unit'] === undefined,
`Expected launch sortie supplies to share save normalization rules: ${JSON.stringify(normalizedLaunchSupplies)}`
);
const cappedLaunchSupplies = normalizeCampaignSortieItemAssignments(
Object.fromEntries(Array.from({ length: 120 }, (_, index) => [`unit-${index}`, { bean: 1 }]))
);
assert(
Object.keys(cappedLaunchSupplies).length === 96 &&
cappedLaunchSupplies['unit-95']?.bean === 1 &&
cappedLaunchSupplies['unit-96'] === undefined,
`Expected launch sortie supplies without a roster filter to stay capped: ${JSON.stringify(cappedLaunchSupplies)}`
);
resetCampaignState();
const firstScenario = battleScenarios['first-battle-zhuo-commandery'];
@@ -222,9 +235,10 @@ try {
selectedSortieUnitIds: { corrupted: true },
sortieFormationAssignments: 'front',
sortieItemAssignments: {
'liu-bei': { bean: '5', wine: -1, salve: '1', stone: '9' },
'liu-bei': { ' bean ': '5', wine: -1, salve: '1', stone: '9', ['x'.repeat(97)]: '1' },
'guan-yu': '2',
'zhang-fei': ['bean', '2'],
['x'.repeat(97)]: { bean: 1 },
'': { bean: 4 }
},
battleHistory: []
@@ -260,8 +274,10 @@ try {
malformed.sortieItemAssignments['liu-bei']?.salve === 1 &&
malformed.sortieItemAssignments['liu-bei']?.stone === undefined &&
malformed.sortieItemAssignments['liu-bei']?.wine === undefined &&
malformed.sortieItemAssignments['liu-bei']?.['x'.repeat(97)] === undefined &&
malformed.sortieItemAssignments['guan-yu'] === undefined &&
malformed.sortieItemAssignments['zhang-fei'] === undefined &&
malformed.sortieItemAssignments['x'.repeat(97)] === undefined &&
Object.keys(malformed.sortieItemAssignments).length === 1 &&
Object.keys(malformed.sortieFormationAssignments).length === 0,
`Expected malformed inventory and sortie assignments to normalize: ${JSON.stringify(malformed)}`