Validate battle save unit references
This commit is contained in:
@@ -15,9 +15,10 @@ try {
|
||||
expectedBattleId: 'first-battle-zhuo-commandery',
|
||||
mapWidth: 12,
|
||||
mapHeight: 8,
|
||||
validUnitIds: new Set(['liu-bei'])
|
||||
validUnitIds: new Set(['liu-bei', 'guan-yu', 'rebel-1'])
|
||||
};
|
||||
const validState = createValidBattleSaveState();
|
||||
const patchUnit = (index, patch) => validState.units.map((unit, unitIndex) => (unitIndex === index ? { ...unit, ...patch } : unit));
|
||||
|
||||
assert(normalizeBattleSaveSlot(0, 3) === 1, 'Expected slot 0 to normalize to slot 1.');
|
||||
assert(normalizeBattleSaveSlot(Number.NaN, 3) === 1, 'Expected NaN slot to normalize to slot 1.');
|
||||
@@ -35,19 +36,26 @@ try {
|
||||
['invalid activeFaction', { activeFaction: 'neutral' }],
|
||||
['invalid rosterTab', { rosterTab: 'neutral' }],
|
||||
['invalid actedUnitIds', { actedUnitIds: 'liu-bei' }],
|
||||
['unknown acted unit id', { actedUnitIds: ['ghost-unit'] }],
|
||||
['invalid battleLog', { battleLog: 'hit' }],
|
||||
['invalid attackIntents', { attackIntents: [{ attackerId: 'liu-bei' }] }],
|
||||
['unknown attack intent unit id', { attackIntents: [{ attackerId: 'liu-bei', targetId: 'ghost-unit' }] }],
|
||||
['invalid units array', { units: {} }],
|
||||
['invalid unit hp', { units: [{ ...validState.units[0], hp: 99, maxHp: 30 }] }],
|
||||
['invalid unit x', { units: [{ ...validState.units[0], x: 12 }] }],
|
||||
['invalid unit direction', { units: [{ ...validState.units[0], direction: 'down' }] }],
|
||||
['unknown unit id', { units: [{ ...validState.units[0], id: 'ghost-unit' }] }],
|
||||
['duplicate unit id', { units: [{ ...validState.units[0] }, { ...validState.units[0], x: 2 }] }],
|
||||
['invalid unit hp', { units: patchUnit(0, { hp: 99, maxHp: 30 }) }],
|
||||
['invalid unit x', { units: patchUnit(0, { x: 12 }) }],
|
||||
['invalid unit direction', { units: patchUnit(0, { direction: 'down' }) }],
|
||||
['unknown unit id', { units: patchUnit(0, { id: 'ghost-unit' }) }],
|
||||
['duplicate unit id', { units: [validState.units[0], { ...validState.units[0], x: 2 }, validState.units[2]] }],
|
||||
['invalid bonds', { bonds: [{ ...validState.bonds[0], unitIds: ['liu-bei'] }] }],
|
||||
['unknown bond unit id', { bonds: [{ ...validState.bonds[0], unitIds: ['liu-bei', 'ghost-unit'] }] }],
|
||||
['invalid item stock count', { itemStocks: { 'liu-bei': { bean: -1 } } }],
|
||||
['unknown item stock unit id', { itemStocks: { 'ghost-unit': { bean: 1 } } }],
|
||||
['invalid buff turns', { battleBuffs: [{ ...validState.battleBuffs[0], turns: 0 }] }],
|
||||
['unknown buff unit id', { battleBuffs: [{ ...validState.battleBuffs[0], unitId: 'ghost-unit' }] }],
|
||||
['invalid status kind', { battleStatuses: [{ ...validState.battleStatuses[0], kind: 'poison' }] }],
|
||||
['unknown status unit id', { battleStatuses: [{ ...validState.battleStatuses[0], unitId: 'ghost-unit' }] }],
|
||||
['invalid stats shape', { battleStats: { 'liu-bei': { damageDealt: 10 } } }],
|
||||
['unknown stats unit id', { battleStats: { 'ghost-unit': validState.battleStats['liu-bei'] } }],
|
||||
['invalid enemy usable keys', { enemyUsableUseKeys: [1] }],
|
||||
['invalid triggered events', { triggeredBattleEvents: [1] }]
|
||||
];
|
||||
@@ -58,7 +66,7 @@ try {
|
||||
});
|
||||
|
||||
assert(
|
||||
!isValidBattleSaveState(validState, { ...options, validUnitIds: new Set(['liu-bei', 'guan-yu']) }),
|
||||
!isValidBattleSaveState(validState, { ...options, validUnitIds: new Set(['liu-bei', 'guan-yu', 'rebel-1', 'zhang-fei']) }),
|
||||
'Expected save missing a current battle unit to be rejected.'
|
||||
);
|
||||
|
||||
@@ -92,6 +100,32 @@ function createValidBattleSaveState() {
|
||||
y: 2,
|
||||
direction: 'south',
|
||||
equipment: {}
|
||||
},
|
||||
{
|
||||
id: 'guan-yu',
|
||||
level: 2,
|
||||
exp: 5,
|
||||
hp: 32,
|
||||
maxHp: 34,
|
||||
attack: 14,
|
||||
move: 4,
|
||||
x: 2,
|
||||
y: 2,
|
||||
direction: 'south',
|
||||
equipment: {}
|
||||
},
|
||||
{
|
||||
id: 'rebel-1',
|
||||
level: 1,
|
||||
exp: 0,
|
||||
hp: 20,
|
||||
maxHp: 20,
|
||||
attack: 8,
|
||||
move: 3,
|
||||
x: 8,
|
||||
y: 4,
|
||||
direction: 'west',
|
||||
equipment: {}
|
||||
}
|
||||
],
|
||||
bonds: [
|
||||
|
||||
Reference in New Issue
Block a user