Normalize malformed campaign bonds

This commit is contained in:
2026-07-05 09:26:40 +09:00
parent dac0411ad1
commit d45d240875
2 changed files with 47 additions and 5 deletions

View File

@@ -802,8 +802,12 @@ function normalizeCampaignState(state: Partial<CampaignState>): CampaignState {
normalized.step = normalizeCampaignStep(normalized.step);
normalized.activeSaveSlot = normalizeSlot(normalized.activeSaveSlot);
normalized.gold = normalizeNonNegativeInteger(normalized.gold);
normalized.roster = arrayOrEmpty<UnitData>(normalized.roster).map(cloneUnit);
normalized.bonds = arrayOrEmpty<CampBondSnapshot>(normalized.bonds).map(cloneBondSnapshot);
normalized.roster = arrayOrEmpty<unknown>(normalized.roster)
.filter(isPlainObject)
.map((unit) => cloneUnit(unit as UnitData));
normalized.bonds = arrayOrEmpty<unknown>(normalized.bonds)
.map(normalizeCampBondSnapshot)
.filter((bond): bond is CampBondSnapshot => Boolean(bond));
normalized.completedCampDialogues = uniqueStrings(normalized.completedCampDialogues);
normalized.completedCampVisits = uniqueStrings(normalized.completedCampVisits);
normalized.inventory = normalizeInventory(normalized.inventory);
@@ -933,6 +937,33 @@ function normalizeFirstBattleReport(report: unknown): FirstBattleReport | undefi
}
}
function normalizeCampBondSnapshot(value: unknown): CampBondSnapshot | undefined {
if (!isPlainObject(value)) {
return undefined;
}
const unitIds = arrayOrEmpty<unknown>(value.unitIds).filter((unitId): unitId is string => typeof unitId === 'string' && unitId.length > 0);
if (
typeof value.id !== 'string' ||
value.id.length === 0 ||
typeof value.title !== 'string' ||
value.title.length === 0 ||
unitIds.length < 2
) {
return undefined;
}
return {
...(value as CampBondSnapshot),
id: value.id,
title: value.title,
unitIds: [unitIds[0], unitIds[1]] as [string, string],
level: normalizeNonNegativeInteger(value.level),
exp: normalizeNonNegativeInteger(value.exp),
battleExp: normalizeNonNegativeInteger(value.battleExp)
};
}
function reserveTrainingFocusDefinition(focusId?: string) {
const normalizedId = normalizeReserveTrainingFocusId(focusId);
return campaignReserveTrainingFocusDefinitions.find((focus) => focus.id === normalizedId) ?? campaignReserveTrainingFocusDefinitions[0];