Validate battle save item stock ids
This commit is contained in:
@@ -11350,7 +11350,12 @@ export class BattleScene extends Phaser.Scene {
|
||||
mapWidth: battleMap.width,
|
||||
mapHeight: battleMap.height,
|
||||
validUnitIds: new Set(battleUnits.map((unit) => unit.id)),
|
||||
validUsableIds: new Set(Object.keys(usableCatalog))
|
||||
validUsableIds: new Set(Object.keys(usableCatalog)),
|
||||
validItemIds: new Set(
|
||||
Object.values(usableCatalog)
|
||||
.filter((usable) => usable.command === 'item')
|
||||
.map((usable) => usable.id)
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ type BattleSaveValidationOptions = {
|
||||
mapHeight?: number;
|
||||
validUnitIds?: ReadonlySet<string>;
|
||||
validUsableIds?: ReadonlySet<string>;
|
||||
validItemIds?: ReadonlySet<string>;
|
||||
};
|
||||
|
||||
const unitDirections = new Set<UnitDirection>(['south', 'east', 'north', 'west']);
|
||||
@@ -127,7 +128,7 @@ export function isValidBattleSaveState(state: unknown, options: BattleSaveValida
|
||||
}
|
||||
|
||||
if (
|
||||
!isOptionalNestedCountRecord(state.itemStocks, options) ||
|
||||
!isOptionalItemStockRecord(state.itemStocks, options) ||
|
||||
!isOptionalBuffArray(state.battleBuffs, options) ||
|
||||
!isOptionalStatusArray(state.battleStatuses, options) ||
|
||||
!isOptionalStatsRecord(state.battleStats, options) ||
|
||||
@@ -267,7 +268,7 @@ function isBondArray(value: unknown, options: BattleSaveValidationOptions) {
|
||||
);
|
||||
}
|
||||
|
||||
function isOptionalNestedCountRecord(value: unknown, options: BattleSaveValidationOptions) {
|
||||
function isOptionalItemStockRecord(value: unknown, options: BattleSaveValidationOptions) {
|
||||
if (value === undefined) {
|
||||
return true;
|
||||
}
|
||||
@@ -280,7 +281,10 @@ function isOptionalNestedCountRecord(value: unknown, options: BattleSaveValidati
|
||||
([unitId, stocks]) =>
|
||||
isKnownUnitId(unitId, options) &&
|
||||
isRecord(stocks) &&
|
||||
Object.values(stocks).every((count) => Number.isInteger(count) && Number(count) >= 0)
|
||||
Object.entries(stocks).every(
|
||||
([itemId, count]) =>
|
||||
(!options.validItemIds || options.validItemIds.has(itemId)) && Number.isInteger(count) && Number(count) >= 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user