Filter stale battle report references
This commit is contained in:
@@ -837,6 +837,9 @@ function normalizeCampaignState(state: Partial<CampaignState>): CampaignState {
|
||||
normalized.battleHistory = normalizeBattleHistory(normalized.battleHistory);
|
||||
normalized.latestBattleId = normalizeLatestBattleId(normalized.latestBattleId, normalized.battleHistory);
|
||||
normalized.firstBattleReport = normalizeFirstBattleReport(normalized.firstBattleReport);
|
||||
if (normalized.firstBattleReport && sortieUnitFilter) {
|
||||
normalized.firstBattleReport = filterFirstBattleReportRosterReferences(normalized.firstBattleReport, sortieUnitFilter);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
@@ -900,6 +903,17 @@ function normalizeLatestBattleId(value: unknown, battleHistory: Record<string, C
|
||||
.sort((a, b) => String(b.completedAt).localeCompare(String(a.completedAt)))[0]?.battleId;
|
||||
}
|
||||
|
||||
function filterFirstBattleReportRosterReferences(report: FirstBattleReport, rosterUnitIds: Set<string>): FirstBattleReport {
|
||||
const filtered = {
|
||||
...report,
|
||||
bonds: report.bonds.filter((bond) => bond.unitIds.every((unitId) => rosterUnitIds.has(unitId)))
|
||||
};
|
||||
if (filtered.mvp && !rosterUnitIds.has(filtered.mvp.unitId)) {
|
||||
delete filtered.mvp;
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
function normalizeCampaignBattleSettlement(value: unknown): CampaignBattleSettlement | undefined {
|
||||
if (!isPlainObject(value)) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user