From 5fa7921e411246262230377b3cd2e032c379e59b Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 7 Nov 2023 21:05:27 -0500 Subject: [PATCH] Fix additional cases of missing form data causing crash --- src/system/game-data.ts | 15 ++++++++++----- src/ui/battle-info.ts | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 181c0a65cfa..626710831f3 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -397,11 +397,18 @@ export class GameData { const genderIndex = !female ? 0 : 1; const data = this.dexData[species.speciesId]; if (species.forms?.length) { - try { + const getEntry = () => { if (species.malePercent !== null) return data[shinyIndex][formIndex][genderIndex][abilityIndex]; return data[shinyIndex][formIndex][abilityIndex]; - } catch (err) { + }; + let entry: DexEntry; + try { + entry = getEntry(); + } catch (err) { } + if (entry) + return entry; + else { console.warn(`Form data not found for dex entry for ${species.name}: Restructuring dex entry`); for (let s = 0; s < 2; s++) { const oldData = Object.assign({}, data[s]); @@ -411,9 +418,7 @@ export class GameData { } this.saveSystem(); } - if (species.malePercent !== null) - return data[shinyIndex][formIndex][genderIndex][abilityIndex]; - return data[shinyIndex][formIndex][abilityIndex]; + return getEntry(); } else if (species.malePercent !== null) return data[shinyIndex][genderIndex][abilityIndex]; return data[shinyIndex][abilityIndex] as DexEntry; diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index ce52dde501c..5a32b570827 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -131,7 +131,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { if (!this.player) { const speciesOwned = !!pokemon.scene.gameData.getDefaultDexEntry(pokemon.species)?.entry?.caught; this.ownedIcon.setVisible(speciesOwned); - if (!pokemon.scene.gameData.getPokemonDexEntry(pokemon).caught) + if (!pokemon.scene.gameData.getPokemonDexEntry(pokemon)?.caught) this.ownedIcon.setTint(0x808080); }