[Bug] fix starter select crash when a variant preference is incorrect (#4209)

This commit is contained in:
MokaStitcher 2024-09-13 15:29:35 +02:00 committed by GitHub
parent 8409f39b8d
commit 48c2bdf1d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 4 deletions

View File

@ -995,15 +995,14 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
delete starterAttributes.shiny;
}
if (starterAttributes.variant !== undefined && !isNaN(starterAttributes.variant)) {
if (starterAttributes.variant !== undefined) {
const unlockedVariants = [
hasNonShiny,
hasShiny && caughtAttr & DexAttr.DEFAULT_VARIANT,
hasShiny && caughtAttr & DexAttr.VARIANT_2,
hasShiny && caughtAttr & DexAttr.VARIANT_3
];
if (!unlockedVariants[starterAttributes.variant + 1]) { // add 1 as -1 = non-shiny
// requested variant wasn't unlocked, purging setting
if (isNaN(starterAttributes.variant) || starterAttributes.variant < 0 || !unlockedVariants[starterAttributes.variant]) {
// variant value is invalid or requested variant wasn't unlocked, purging setting
delete starterAttributes.variant;
}
}