Validate battle save campaign step
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { BattleBond, UnitData } from '../data/scenario';
|
||||
import type { CampaignStep } from './campaignState';
|
||||
import { isCampaignStep, type CampaignStep } from './campaignState';
|
||||
import type { UnitDirection } from '../data/unitAssets';
|
||||
import { equipmentExpToNext, equipmentSlots, type EquipmentSlot } from '../data/battleItems';
|
||||
|
||||
@@ -142,6 +142,10 @@ export function isValidBattleSaveState(state: unknown, options: BattleSaveValida
|
||||
return false;
|
||||
}
|
||||
|
||||
if (state.campaignStep !== undefined && !isCampaignStep(state.campaignStep)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const attackIntents = state.attackIntents;
|
||||
const units = state.units;
|
||||
|
||||
|
||||
@@ -1237,8 +1237,12 @@ function normalizeReserveTrainingFocusId(focusId?: string): CampaignReserveTrain
|
||||
: defaultCampaignReserveTrainingFocusId;
|
||||
}
|
||||
|
||||
export function isCampaignStep(value: unknown): value is CampaignStep {
|
||||
return typeof value === 'string' && campaignStepIds.has(value as CampaignStep);
|
||||
}
|
||||
|
||||
function normalizeCampaignStep(step: unknown): CampaignStep {
|
||||
return typeof step === 'string' && campaignStepIds.has(step as CampaignStep) ? step as CampaignStep : 'new';
|
||||
return isCampaignStep(step) ? step : 'new';
|
||||
}
|
||||
|
||||
function normalizeFirstBattleReport(report: unknown): FirstBattleReport | undefined {
|
||||
|
||||
Reference in New Issue
Block a user