Fix crash on starter screen related to form index out of bounds
This commit is contained in:
parent
b04cdd3f60
commit
48ff8b248b
|
@ -269,6 +269,10 @@ export abstract class PokemonSpeciesForm {
|
||||||
let ret = speciesId.toString();
|
let ret = speciesId.toString();
|
||||||
const forms = getPokemonSpecies(speciesId).forms;
|
const forms = getPokemonSpecies(speciesId).forms;
|
||||||
if (forms.length) {
|
if (forms.length) {
|
||||||
|
if (formIndex >= forms.length) {
|
||||||
|
console.warn(`Attempted accessing form with index ${formIndex} of species ${getPokemonSpecies(speciesId).getName()} with only ${forms.length || 0} forms`);
|
||||||
|
formIndex = Math.min(formIndex, forms.length - 1);
|
||||||
|
}
|
||||||
const formKey = forms[formIndex || 0].formKey;
|
const formKey = forms[formIndex || 0].formKey;
|
||||||
switch (formKey) {
|
switch (formKey) {
|
||||||
case SpeciesFormKey.MEGA:
|
case SpeciesFormKey.MEGA:
|
||||||
|
@ -618,6 +622,10 @@ export default class PokemonSpecies extends PokemonSpeciesForm {
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormSpriteKey(formIndex?: integer) {
|
getFormSpriteKey(formIndex?: integer) {
|
||||||
|
if (this.forms.length && formIndex >= this.forms.length) {
|
||||||
|
console.warn(`Attempted accessing form with index ${formIndex} of species ${this.getName()} with only ${this.forms?.length || 0} forms`);
|
||||||
|
formIndex = Math.min(formIndex, this.forms.length - 1);
|
||||||
|
}
|
||||||
return this.forms?.length
|
return this.forms?.length
|
||||||
? this.forms[formIndex || 0].getFormSpriteKey()
|
? this.forms[formIndex || 0].getFormSpriteKey()
|
||||||
: '';
|
: '';
|
||||||
|
|
Loading…
Reference in New Issue