diff --git a/athena/generator/MapGenerator.tsx b/athena/generator/MapGenerator.tsx index e6b4218a..749a7c11 100644 --- a/athena/generator/MapGenerator.tsx +++ b/athena/generator/MapGenerator.tsx @@ -443,7 +443,7 @@ export function generateRandomMap( ]; const length = size.width * size.height; for (let i = 0; i < length; i++) { - map.push(randomEntry(tiles).id); + map.push((randomEntry(tiles) || tiles[0]).id); } return MapData.createMap({ diff --git a/dionysus/DionysusAlpha.tsx b/dionysus/DionysusAlpha.tsx index 7f6ca30b..4adebbab 100644 --- a/dionysus/DionysusAlpha.tsx +++ b/dionysus/DionysusAlpha.tsx @@ -135,7 +135,7 @@ export default class DionysusAlpha extends BaseAI { } if (potentialSkills.length) { - const [skill] = randomEntry(potentialSkills); + const [skill] = randomEntry(potentialSkills) || potentialSkills[0]; const currentMap = this.execute(map, ActivatePowerAction(skill)); if (currentMap) { this.tryAttacking(); @@ -718,8 +718,10 @@ export default class DionysusAlpha extends BaseAI { }); if (buyableSkills.length) { - const skill = randomEntry(buyableSkills); - return this.execute(map, BuySkillAction(from, skill)); + return this.execute( + map, + BuySkillAction(from, randomEntry(buyableSkills) || buyableSkills[0]), + ); } return null; diff --git a/docs/content/playground/PlaygroundDemoGame.tsx b/docs/content/playground/PlaygroundDemoGame.tsx index 86b09c24..a5773315 100644 --- a/docs/content/playground/PlaygroundDemoGame.tsx +++ b/docs/content/playground/PlaygroundDemoGame.tsx @@ -9,24 +9,25 @@ import demo2, { } from '@deities/hermes/map-fixtures/demo-2.tsx'; import PlaygroundGame from './PlaygroundGame.tsx'; -const biome = randomEntry([ - Biome.Grassland, - Biome.Desert, - Biome.Snow, - Biome.Swamp, - Biome.Volcano, -]); +const biome = + randomEntry([ + Biome.Grassland, + Biome.Desert, + Biome.Snow, + Biome.Swamp, + Biome.Volcano, + ]) || Biome.Grassland; const [map, metadata] = randomEntry([ [demo1, metadata1], [demo1, metadata1], [demo1, metadata1], [demo2, metadata2], -]); +]) || [demo1, metadata1]; const currentDemoMap = convertBiome( map.copy({ config: map.config.copy({ - fog: randomEntry([true, false, false, false, false]), + fog: randomEntry([true, false, false, false, false]) || false, }), }), biome, diff --git a/hephaestus/randomEntry.tsx b/hephaestus/randomEntry.tsx index e512d6d2..cbdf979e 100644 --- a/hephaestus/randomEntry.tsx +++ b/hephaestus/randomEntry.tsx @@ -1,5 +1,5 @@ import random from './random.tsx'; -export default function randomEntry(array: ReadonlyArray): T { - return array.at(random(0, array.length - 1))!; +export default function randomEntry(array: ReadonlyArray): T | null { + return array.at(random(0, array.length - 1)) || null; } diff --git a/hera/hooks/useUnitState.tsx b/hera/hooks/useUnitState.tsx index 3bdc5b99..2e74e49b 100644 --- a/hera/hooks/useUnitState.tsx +++ b/hera/hooks/useUnitState.tsx @@ -93,7 +93,7 @@ const getNextUnitState = (unitState: UnitState, unit: Unit): UnitState => { switch (stateType) { case 'idle': return { - direction: randomEntry(directions), + direction: randomEntry(directions) || directions[0], highlightStyle: 'move-null', type: 'move', }; diff --git a/hera/ui/demo/UnitPreviews.tsx b/hera/ui/demo/UnitPreviews.tsx index ffb600e0..0070ce21 100644 --- a/hera/ui/demo/UnitPreviews.tsx +++ b/hera/ui/demo/UnitPreviews.tsx @@ -48,10 +48,12 @@ const UnitPreview = ({ ); +const playerIDs = PlayerIDs.slice(1); + const map = MapData.createMap({ map: [1], modifiers: [0], - teams: PlayerIDs.slice(1).map((id) => ({ + teams: playerIDs.map((id) => ({ id, name: '', players: [{ funds: 0, id, name: `User-${id}`, teamId: id }], @@ -84,7 +86,7 @@ export default function UnitPreviews() { unit.characterDescription !== 'Unknown', ) .map((unit) => { - const player = randomEntry(PlayerIDs.slice(1)); + const player = randomEntry(playerIDs) || playerIDs[0]; return (