Fix additional cases of missing form data causing crash

pull/2/head
Flashfyre 2023-11-07 21:05:27 -05:00
parent 39a458cb3a
commit 5fa7921e41
2 changed files with 11 additions and 6 deletions

View File

@ -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;

View File

@ -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);
}