From f6a8d7b04fb2fc7d757ef58f71753cb4965af5d6 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:02:10 +0100 Subject: [PATCH 1/7] =?UTF-8?q?Show=20all=20forms=20in=20Pok=C3=A9dex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/pokedex-mon-container.ts | 2 + src/ui/pokedex-ui-handler.ts | 321 ++++++++++++++++---------------- 2 files changed, 160 insertions(+), 163 deletions(-) diff --git a/src/ui/pokedex-mon-container.ts b/src/ui/pokedex-mon-container.ts index e61da86e95e..c3684b82e3f 100644 --- a/src/ui/pokedex-mon-container.ts +++ b/src/ui/pokedex-mon-container.ts @@ -13,6 +13,7 @@ interface SpeciesDetails { export class PokedexMonContainer extends Phaser.GameObjects.Container { public species: PokemonSpecies; + public formIndex: number; public icon: Phaser.GameObjects.Sprite; public shinyIcons: Phaser.GameObjects.Image[] = []; public label: Phaser.GameObjects.Text; @@ -178,6 +179,7 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container { if (!isNullOrUndefined(formIndex)) { defaultProps.formIndex = formIndex; + this.formIndex = formIndex; } if (!isNullOrUndefined(shiny)) { defaultProps.shiny = shiny; diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index d55b278a148..697be34019c 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -1173,7 +1173,8 @@ export default class PokedexUiHandler extends MessageUiHandler { } } else { if (button === Button.ACTION) { - ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, null, this.filteredIndices); + const formIndex = this.pokemonContainers[this.cursor]?.formIndex; + ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, formIndex, this.filteredIndices); success = true; } else { switch (button) { @@ -1310,18 +1311,6 @@ export default class PokedexUiHandler extends MessageUiHandler { return sanitizedProps; } - // Returns true if one of the forms has the requested move - hasFormLevelMove(form: PokemonForm, selectedMove: string): boolean { - if ( - !pokemonFormLevelMoves.hasOwnProperty(form.speciesId) || - !pokemonFormLevelMoves[form.speciesId].hasOwnProperty(form.formIndex) - ) { - return false; - } - const levelMoves = pokemonFormLevelMoves[form.speciesId][form.formIndex].map(m => allMoves[m[1]].name); - return levelMoves.includes(selectedMove); - } - updateStarters = () => { this.scrollCursor = 0; this.filteredPokemonData = []; @@ -1339,140 +1328,18 @@ export default class PokedexUiHandler extends MessageUiHandler { const currentDexAttr = this.getCurrentDexProps(species.speciesId); const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(species, currentDexAttr)); - const data: ContainerData = { - species: species, - cost: globalScene.gameData.getSpeciesStarterValue(starterId), - props: props, - }; - - // First, ensure you have the caught attributes for the species else default to bigint 0 - // TODO: This might be removed depending on how accessible we want the pokedex function to be - const caughtAttr = - (globalScene.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0)) & - (globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)]?.caughtAttr || BigInt(0)) & - species.getFullUnlocksData(); const starterData = globalScene.gameData.starterData[starterId]; const isStarterProgressable = speciesEggMoves.hasOwnProperty(starterId); - // Name filter - const selectedName = this.filterText.getValue(FilterTextRow.NAME); - const fitsName = species.name === selectedName || selectedName === this.filterText.defaultText; - - // Move filter - // TODO: There can be fringe cases where the two moves belong to mutually exclusive forms, these must be handled separately (Pikachu); - // On the other hand, in some cases it is possible to switch between different forms and combine (Deoxys) - const levelMoves = pokemonSpeciesLevelMoves[species.speciesId].map(m => allMoves[m[1]].name); - // This always gets egg moves from the starter - const eggMoves = speciesEggMoves[starterId]?.map(m => allMoves[m].name) ?? []; - const tmMoves = speciesTmMoves[starterId]?.map(m => allMoves[Array.isArray(m) ? m[1] : m].name) ?? []; - const selectedMove1 = this.filterText.getValue(FilterTextRow.MOVE_1); - const selectedMove2 = this.filterText.getValue(FilterTextRow.MOVE_2); - - const fitsFormMove1 = species.forms.some(form => this.hasFormLevelMove(form, selectedMove1)); - const fitsFormMove2 = species.forms.some(form => this.hasFormLevelMove(form, selectedMove2)); - const fitsLevelMove1 = levelMoves.includes(selectedMove1) || fitsFormMove1; - const fitsEggMove1 = eggMoves.includes(selectedMove1); - const fitsTmMove1 = tmMoves.includes(selectedMove1); - const fitsLevelMove2 = levelMoves.includes(selectedMove2) || fitsFormMove2; - const fitsEggMove2 = eggMoves.includes(selectedMove2); - const fitsTmMove2 = tmMoves.includes(selectedMove2); - const fitsMove1 = fitsLevelMove1 || fitsEggMove1 || fitsTmMove1 || selectedMove1 === this.filterText.defaultText; - const fitsMove2 = fitsLevelMove2 || fitsEggMove2 || fitsTmMove2 || selectedMove2 === this.filterText.defaultText; - const fitsMoves = fitsMove1 && fitsMove2; - - if (fitsEggMove1 && !fitsLevelMove1) { - const em1 = eggMoves.findIndex(name => name === selectedMove1); - if ((starterData.eggMoves & (1 << em1)) === 0) { - data.eggMove1 = false; - } else { - data.eggMove1 = true; - } - } else if (fitsTmMove1 && !fitsLevelMove1) { - data.tmMove1 = true; - } - if (fitsEggMove2 && !fitsLevelMove2) { - const em2 = eggMoves.findIndex(name => name === selectedMove2); - if ((starterData.eggMoves & (1 << em2)) === 0) { - data.eggMove2 = false; - } else { - data.eggMove2 = true; - } - } else if (fitsTmMove2 && !fitsLevelMove2) { - data.tmMove2 = true; - } - - // Ability filter - const abilities = [species.ability1, species.ability2, species.abilityHidden].map(a => allAbilities[a].name); - const passiveId = starterPassiveAbilities.hasOwnProperty(species.speciesId) - ? species.speciesId - : starterPassiveAbilities.hasOwnProperty(starterId) - ? starterId - : pokemonPrevolutions[starterId]; - const passives = starterPassiveAbilities[passiveId]; - - const selectedAbility1 = this.filterText.getValue(FilterTextRow.ABILITY_1); - const fitsFormAbility1 = species.forms.some(form => - [form.ability1, form.ability2, form.abilityHidden].map(a => allAbilities[a].name).includes(selectedAbility1), - ); - const fitsAbility1 = - abilities.includes(selectedAbility1) || fitsFormAbility1 || selectedAbility1 === this.filterText.defaultText; - const fitsPassive1 = Object.values(passives).some(p => allAbilities[p].name === selectedAbility1); - - const selectedAbility2 = this.filterText.getValue(FilterTextRow.ABILITY_2); - const fitsFormAbility2 = species.forms.some(form => - [form.ability1, form.ability2, form.abilityHidden].map(a => allAbilities[a].name).includes(selectedAbility2), - ); - const fitsAbility2 = - abilities.includes(selectedAbility2) || fitsFormAbility2 || selectedAbility2 === this.filterText.defaultText; - const fitsPassive2 = Object.values(passives).some(p => allAbilities[p].name === selectedAbility2); - - // If both fields have been set to the same ability, show both ability and passive - const fitsAbilities = - (fitsAbility1 && (fitsPassive2 || selectedAbility2 === this.filterText.defaultText)) || - (fitsAbility2 && (fitsPassive1 || selectedAbility1 === this.filterText.defaultText)); - - if (fitsPassive1 || fitsPassive2) { - if (fitsPassive1) { - if (starterData.passiveAttr > 0) { - data.passive1 = true; - } else { - data.passive1 = false; - } - } else { - if (starterData.passiveAttr > 0) { - data.passive2 = true; - } else { - data.passive2 = false; - } - } - } - // Gen filter const fitsGen = this.filterBar.getVals(DropDownColumn.GEN).includes(species.generation); - // Type filter - const fitsType = this.filterBar - .getVals(DropDownColumn.TYPES) - .some(type => species.isOfType((type as number) - 1)); - - // Biome filter - const indexToBiome = new Map( - Object.values(Biome) - .map((value, index) => (typeof value === "string" ? [index, value] : undefined)) - .filter((entry): entry is [number, string] => entry !== undefined), - ); - indexToBiome.set(35, "Uncatchable"); - - // We get biomes for both the mon and its starters to ensure that evolutions get the correct filters. - // TODO: We might also need to do it the other way around. - const biomes = catchableSpecies[species.speciesId].concat(catchableSpecies[starterId]).map(b => Biome[b.biome]); - if (biomes.length === 0) { - biomes.push("Uncatchable"); - } - const showNoBiome = !!(biomes.length === 0 && this.filterBar.getVals(DropDownColumn.BIOME).length === 36); - const fitsBiome = - this.filterBar.getVals(DropDownColumn.BIOME).some(item => biomes.includes(indexToBiome.get(item) ?? "")) || - showNoBiome; + // First, ensure you have the caught attributes for the species else default to bigint 0 + // TODO: This might be removed depending on how accessible we want the pokedex function to be + const caughtAttr = + (globalScene.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0)) & // Change this + (globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)]?.caughtAttr || BigInt(0)) & + species.getFullUnlocksData(); // Caught / Shiny filter const isNonShinyCaught = !!(caughtAttr & DexAttr.NON_SHINY); @@ -1629,25 +1496,152 @@ export default class PokedexUiHandler extends MessageUiHandler { } }); - if ( - fitsName && - fitsAbilities && - fitsMoves && - fitsGen && - fitsBiome && - fitsType && - fitsCaught && - fitsPassive && - fitsCostReduction && - fitsStarter && - fitsFavorite && - fitsWin && - fitsHA && - fitsEgg && - fitsPokerus - ) { - this.filteredPokemonData.push(data); - } + const allForms: (PokemonForm | PokemonSpecies)[] = species?.forms?.length > 0 ? species.forms : [species]; + + // Name filter + const selectedName = this.filterText.getValue(FilterTextRow.NAME); + const fitsName = species.name === selectedName || selectedName === this.filterText.defaultText; + + const selectedMove1 = this.filterText.getValue(FilterTextRow.MOVE_1); + const selectedMove2 = this.filterText.getValue(FilterTextRow.MOVE_2); + + // This always gets egg moves from the starter + const eggMoves = speciesEggMoves[starterId]?.map(m => allMoves[m].name) ?? []; + const fitsEggMove1 = eggMoves.includes(selectedMove1); + const fitsEggMove2 = eggMoves.includes(selectedMove2); + + allForms.forEach((form, formIndex) => { + const formProps = { ...props }; + formProps.formIndex = formIndex; + + const data: ContainerData = { + species: species, + cost: globalScene.gameData.getSpeciesStarterValue(starterId), + props: formProps, + }; + + // Move filter + const levelMoves = + pokemonFormLevelMoves.hasOwnProperty(species.speciesId) && + pokemonFormLevelMoves[species.speciesId].hasOwnProperty(form.formIndex) + ? pokemonFormLevelMoves[species.speciesId][form.formIndex].map(m => allMoves[m[1]].name) + : pokemonSpeciesLevelMoves[species.speciesId].map(m => allMoves[m[1]].name); + + const fitsLevelMove1 = levelMoves.includes(selectedMove1); + const fitsLevelMove2 = levelMoves.includes(selectedMove2); + + // TODO: Also needs to be changed obviously + const tmMoves = speciesTmMoves[species.speciesId]?.map(m => allMoves[Array.isArray(m) ? m[1] : m].name) ?? []; + + const fitsTmMove1 = tmMoves.includes(selectedMove1); + const fitsTmMove2 = tmMoves.includes(selectedMove2); + const fitsMove1 = + fitsLevelMove1 || fitsEggMove1 || fitsTmMove1 || selectedMove1 === this.filterText.defaultText; + const fitsMove2 = + fitsLevelMove2 || fitsEggMove2 || fitsTmMove2 || selectedMove2 === this.filterText.defaultText; + const fitsMoves = fitsMove1 && fitsMove2; + + if (fitsEggMove1 && !fitsLevelMove1) { + const em1 = eggMoves.findIndex(name => name === selectedMove1); + if ((starterData.eggMoves & (1 << em1)) === 0) { + data.eggMove1 = false; + } else { + data.eggMove1 = true; + } + } else if (fitsTmMove1 && !fitsLevelMove1) { + data.tmMove1 = true; + } + if (fitsEggMove2 && !fitsLevelMove2) { + const em2 = eggMoves.findIndex(name => name === selectedMove2); + if ((starterData.eggMoves & (1 << em2)) === 0) { + data.eggMove2 = false; + } else { + data.eggMove2 = true; + } + } else if (fitsTmMove2 && !fitsLevelMove2) { + data.tmMove2 = true; + } + + // Rework to look at forms separately + const abilities = [form.ability1, form.ability2, form.abilityHidden].map(a => allAbilities[a].name); + + const selectedAbility1 = this.filterText.getValue(FilterTextRow.ABILITY_1); + const fitsAbility1 = abilities.includes(selectedAbility1) || selectedAbility1 === this.filterText.defaultText; + + const selectedAbility2 = this.filterText.getValue(FilterTextRow.ABILITY_2); + const fitsAbility2 = abilities.includes(selectedAbility2) || selectedAbility2 === this.filterText.defaultText; + + const passive = starterPassiveAbilities.hasOwnProperty(species.speciesId) + ? starterPassiveAbilities[species.speciesId].hasOwnProperty(formIndex) + ? starterPassiveAbilities[species.speciesId][formIndex] + : starterPassiveAbilities[species.speciesId][0] + : starterPassiveAbilities[starterId][0]; + const fitsPassive1 = allAbilities[passive].name === selectedAbility1; + const fitsPassive2 = allAbilities[passive].name === selectedAbility2; + + // If both fields have been set to the same ability, show both ability and passive + const fitsAbilities = + (fitsAbility1 && (fitsPassive2 || selectedAbility2 === this.filterText.defaultText)) || + (fitsAbility2 && (fitsPassive1 || selectedAbility1 === this.filterText.defaultText)); + + if (fitsPassive1 || fitsPassive2) { + if (fitsPassive1) { + if (starterData.passiveAttr > 0) { + data.passive1 = true; + } else { + data.passive1 = false; + } + } else { + if (starterData.passiveAttr > 0) { + data.passive2 = true; + } else { + data.passive2 = false; + } + } + } + + // Type filter + const fitsType = this.filterBar.getVals(DropDownColumn.TYPES).some(type => form.isOfType((type as number) - 1)); + + // Biome filter + const indexToBiome = new Map( + Object.values(Biome) + .map((value, index) => (typeof value === "string" ? [index, value] : undefined)) + .filter((entry): entry is [number, string] => entry !== undefined), + ); + indexToBiome.set(35, "Uncatchable"); + + // We get biomes for both the mon and its starters to ensure that evolutions get the correct filters. + // TODO: We might also need to do it the other way around. + const biomes = catchableSpecies[species.speciesId].concat(catchableSpecies[starterId]).map(b => Biome[b.biome]); + if (biomes.length === 0) { + biomes.push("Uncatchable"); + } + const showNoBiome = !!(biomes.length === 0 && this.filterBar.getVals(DropDownColumn.BIOME).length === 36); + const fitsBiome = + this.filterBar.getVals(DropDownColumn.BIOME).some(item => biomes.includes(indexToBiome.get(item) ?? "")) || + showNoBiome; + + if ( + fitsName && + fitsAbilities && + fitsMoves && + fitsGen && + fitsBiome && + fitsType && + fitsCaught && + fitsPassive && + fitsCostReduction && + fitsStarter && + fitsFavorite && + fitsWin && + fitsHA && + fitsEgg && + fitsPokerus + ) { + this.filteredPokemonData.push(data); + } + }); }); this.starterSelectScrollBar.setTotalRows(Math.max(Math.ceil(this.filteredPokemonData.length / 9), 1)); @@ -1859,9 +1853,10 @@ export default class PokedexUiHandler extends MessageUiHandler { this.cursorObj.setPosition(pos.x - 1, pos.y + 1); const species = this.pokemonContainers[cursor]?.species; + const props = this.filteredPokemonData[cursor].props; if (species) { - this.setSpecies(species); + this.setSpecies(species, props); return true; } } @@ -2041,7 +2036,7 @@ export default class PokedexUiHandler extends MessageUiHandler { } } - setSpecies(species: PokemonSpecies | null) { + setSpecies(species: PokemonSpecies | null, props: DexAttrProps | null = null) { this.speciesStarterDexEntry = species ? globalScene.gameData.dexData[species.speciesId] : null; if (!species && globalScene.ui.getTooltip().visible) { @@ -2080,7 +2075,7 @@ export default class PokedexUiHandler extends MessageUiHandler { this.type1Icon.setVisible(true); this.type2Icon.setVisible(true); - this.setSpeciesDetails(species); + this.setSpeciesDetails(species, props ?? {}); this.pokemonSprite.setTint(0x808080); } } else { From b490b8357b066ab0a42ffe76cc925f6d3cd7e2ed Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Fri, 28 Mar 2025 20:11:14 +0100 Subject: [PATCH 2/7] Refactor to minimize number of props that are passed around for no reason; filtering exclusive forms --- src/ui/pokedex-ui-handler.ts | 285 ++++++----------------------------- 1 file changed, 50 insertions(+), 235 deletions(-) diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index 697be34019c..d475729d6ed 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -12,7 +12,7 @@ import { getStarterValueFriendshipCap, speciesStarterCosts, POKERUS_STARTER_COUN import { catchableSpecies } from "#app/data/balance/biomes"; import { PokemonType } from "#enums/pokemon-type"; import type { DexAttrProps, DexEntry, StarterAttributes, StarterPreferences } from "#app/system/game-data"; -import { AbilityAttr, DexAttr, loadStarterPreferences, saveStarterPreferences } from "#app/system/game-data"; +import { AbilityAttr, DexAttr, loadStarterPreferences } from "#app/system/game-data"; import MessageUiHandler from "#app/ui/message-ui-handler"; import PokemonIconAnimHandler, { PokemonIconAnimMode } from "#app/ui/pokemon-icon-anim-handler"; import { TextStyle, addTextObject } from "#app/ui/text"; @@ -114,7 +114,7 @@ enum FilterTextOptions { interface ContainerData { species: PokemonSpecies; cost: number; - props: DexAttrProps; + formIndex: number; eggMove1?: boolean; eggMove2?: boolean; tmMove1?: boolean; @@ -143,15 +143,6 @@ function calcStarterPosition(index: number): { x: number; y: number } { return { x: x, y: y }; } -interface SpeciesDetails { - shiny?: boolean; - formIndex?: number; - female?: boolean; - variant?: Variant; - abilityIndex?: number; - natureIndex?: number; -} - export default class PokedexUiHandler extends MessageUiHandler { private starterSelectContainer: Phaser.GameObjects.Container; private starterSelectScrollBar: ScrollBar; @@ -631,8 +622,6 @@ export default class PokedexUiHandler extends MessageUiHandler { const icon = container.icon; const species = container.species; - this.starterPreferences[species.speciesId] = this.initStarterPrefs(species); - this.setUpgradeAnimation(icon, species); }); @@ -650,101 +639,6 @@ export default class PokedexUiHandler extends MessageUiHandler { return true; } - /** - * Get the starter attributes for the given PokemonSpecies, after sanitizing them. - * If somehow a preference is set for a form, variant, gender, ability or nature - * that wasn't actually unlocked or is invalid it will be cleared here - * - * @param species The species to get Starter Preferences for - * @returns StarterAttributes for the species - */ - initStarterPrefs(species: PokemonSpecies): StarterAttributes { - const starterAttributes = this.starterPreferences[species.speciesId]; - const dexEntry = globalScene.gameData.dexData[species.speciesId]; - const starterData = globalScene.gameData.starterData[species.speciesId]; - - // no preferences or Pokemon wasn't caught, return empty attribute - if (!starterAttributes || !dexEntry.caughtAttr) { - return {}; - } - - const caughtAttr = dexEntry.caughtAttr & species.getFullUnlocksData(); - - const hasShiny = caughtAttr & DexAttr.SHINY; - const hasNonShiny = caughtAttr & DexAttr.NON_SHINY; - if (starterAttributes.shiny && !hasShiny) { - // shiny form wasn't unlocked, purging shiny and variant setting - - starterAttributes.shiny = undefined; - starterAttributes.variant = undefined; - } else if (starterAttributes.shiny === false && !hasNonShiny) { - // non shiny form wasn't unlocked, purging shiny setting - starterAttributes.shiny = undefined; - } - - if (starterAttributes.variant !== undefined) { - const unlockedVariants = [ - hasShiny && caughtAttr & DexAttr.DEFAULT_VARIANT, - hasShiny && caughtAttr & DexAttr.VARIANT_2, - hasShiny && caughtAttr & DexAttr.VARIANT_3, - ]; - if ( - Number.isNaN(starterAttributes.variant) || - starterAttributes.variant < 0 || - !unlockedVariants[starterAttributes.variant] - ) { - // variant value is invalid or requested variant wasn't unlocked, purging setting - starterAttributes.variant = undefined; - } - } - - if (starterAttributes.female !== undefined) { - if (!(starterAttributes.female ? caughtAttr & DexAttr.FEMALE : caughtAttr & DexAttr.MALE)) { - // requested gender wasn't unlocked, purging setting - starterAttributes.female = undefined; - } - } - - if (starterAttributes.ability !== undefined) { - const speciesHasSingleAbility = species.ability2 === species.ability1; - const abilityAttr = starterData.abilityAttr; - const hasAbility1 = abilityAttr & AbilityAttr.ABILITY_1; - const hasAbility2 = abilityAttr & AbilityAttr.ABILITY_2; - const hasHiddenAbility = abilityAttr & AbilityAttr.ABILITY_HIDDEN; - // Due to a past bug it is possible that some Pokemon with a single ability have the ability2 flag - // In this case, we only count ability2 as valid if ability1 was not unlocked, otherwise we ignore it - const unlockedAbilities = [ - hasAbility1, - speciesHasSingleAbility ? hasAbility2 && !hasAbility1 : hasAbility2, - hasHiddenAbility, - ]; - if (!unlockedAbilities[starterAttributes.ability]) { - // requested ability wasn't unlocked, purging setting - starterAttributes.ability = undefined; - } - } - - const selectedForm = starterAttributes.form; - if ( - selectedForm !== undefined && - (!species.forms[selectedForm]?.isStarterSelectable || - !(caughtAttr & globalScene.gameData.getFormAttr(selectedForm))) - ) { - // requested form wasn't unlocked/isn't a starter form, purging setting - starterAttributes.form = undefined; - } - - if (starterAttributes.nature !== undefined) { - const unlockedNatures = globalScene.gameData.getNaturesForAttr(dexEntry.natureAttr); - if (unlockedNatures.indexOf(starterAttributes.nature as unknown as Nature) < 0) { - // requested nature wasn't unlocked, purging setting - starterAttributes.nature = undefined; - } - } - - return starterAttributes; - } - /** * Set the selections for all filters to their default starting value */ @@ -1174,7 +1068,7 @@ export default class PokedexUiHandler extends MessageUiHandler { } else { if (button === Button.ACTION) { const formIndex = this.pokemonContainers[this.cursor]?.formIndex; - ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, formIndex, this.filteredIndices); + ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, { form: formIndex }, this.filteredIndices); success = true; } else { switch (button) { @@ -1301,16 +1195,6 @@ export default class PokedexUiHandler extends MessageUiHandler { controlLabel.setVisible(true); } - getSanitizedProps(props: DexAttrProps): DexAttrProps { - const sanitizedProps: DexAttrProps = { - shiny: false, - female: props.female, - variant: 0, - formIndex: props.formIndex, - }; - return sanitizedProps; - } - updateStarters = () => { this.scrollCursor = 0; this.filteredPokemonData = []; @@ -1325,9 +1209,6 @@ export default class PokedexUiHandler extends MessageUiHandler { this.allSpecies.forEach(species => { const starterId = this.getStarterSpeciesId(species.speciesId); - const currentDexAttr = this.getCurrentDexProps(species.speciesId); - const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(species, currentDexAttr)); - const starterData = globalScene.gameData.starterData[starterId]; const isStarterProgressable = speciesEggMoves.hasOwnProperty(starterId); @@ -1510,14 +1391,13 @@ export default class PokedexUiHandler extends MessageUiHandler { const fitsEggMove1 = eggMoves.includes(selectedMove1); const fitsEggMove2 = eggMoves.includes(selectedMove2); - allForms.forEach((form, formIndex) => { - const formProps = { ...props }; - formProps.formIndex = formIndex; + const formsData: ContainerData[] = []; + allForms.forEach((form, formIndex) => { const data: ContainerData = { species: species, cost: globalScene.gameData.getSpeciesStarterValue(starterId), - props: formProps, + formIndex: formIndex, }; // Move filter @@ -1639,9 +1519,15 @@ export default class PokedexUiHandler extends MessageUiHandler { fitsEgg && fitsPokerus ) { - this.filteredPokemonData.push(data); + formsData.push(data); } }); + + if (formsData.length === allForms.length) { + this.filteredPokemonData.push(formsData[0]); + } else { + this.filteredPokemonData.push(...formsData); + } }); this.starterSelectScrollBar.setTotalRows(Math.max(Math.ceil(this.filteredPokemonData.length / 9), 1)); @@ -1714,7 +1600,7 @@ export default class PokedexUiHandler extends MessageUiHandler { container.setVisible(true); const data = this.filteredPokemonData[i_data]; - const props = data.props; + const props = this.getDefaultProps(data.species, data.formIndex); container.setSpecies(data.species, props); @@ -1787,31 +1673,25 @@ export default class PokedexUiHandler extends MessageUiHandler { } } - container.starterPassiveBgs.setVisible( - !!globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].passiveAttr, - ); + const starterId = this.getStarterSpeciesId(speciesId); + + container.starterPassiveBgs.setVisible(!!globalScene.gameData.starterData[starterId].passiveAttr); container.hiddenAbilityIcon.setVisible( - !!caughtAttr && !!(globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].abilityAttr & 4), - ); - container.classicWinIcon.setVisible( - globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].classicWinCount > 0, + !!caughtAttr && !!(globalScene.gameData.starterData[starterId].abilityAttr & 4), ); + container.classicWinIcon.setVisible(globalScene.gameData.starterData[starterId].classicWinCount > 0); container.favoriteIcon.setVisible(this.starterPreferences[speciesId]?.favorite ?? false); // 'Candy Icon' mode if (globalScene.candyUpgradeDisplay === 0) { - if (!starterColors[this.getStarterSpeciesId(speciesId)]) { + if (!starterColors[starterId]) { // Default to white if no colors are found - starterColors[this.getStarterSpeciesId(speciesId)] = ["ffffff", "ffffff"]; + starterColors[starterId] = ["ffffff", "ffffff"]; } // Set the candy colors - container.candyUpgradeIcon.setTint( - argbFromRgba(rgbHexToRgba(starterColors[this.getStarterSpeciesId(speciesId)][0])), - ); - container.candyUpgradeOverlayIcon.setTint( - argbFromRgba(rgbHexToRgba(starterColors[this.getStarterSpeciesId(speciesId)][1])), - ); + container.candyUpgradeIcon.setTint(argbFromRgba(rgbHexToRgba(starterColors[starterId][0]))); + container.candyUpgradeOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(starterColors[starterId][1]))); } else if (globalScene.candyUpgradeDisplay === 1) { container.candyUpgradeIcon.setVisible(false); container.candyUpgradeOverlayIcon.setVisible(false); @@ -1853,10 +1733,10 @@ export default class PokedexUiHandler extends MessageUiHandler { this.cursorObj.setPosition(pos.x - 1, pos.y + 1); const species = this.pokemonContainers[cursor]?.species; - const props = this.filteredPokemonData[cursor].props; + const formIndex = this.pokemonContainers[cursor]?.formIndex; if (species) { - this.setSpecies(species, props); + this.setSpecies(species, formIndex); return true; } } @@ -1922,11 +1802,10 @@ export default class PokedexUiHandler extends MessageUiHandler { this.formTrayContainer.setY(goUp ? boxPos.y - this.trayBg.height : boxPos.y + 17); const dexEntry = globalScene.gameData.dexData[species.speciesId]; - const dexAttr = this.getCurrentDexProps(species.speciesId); - const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr)); this.trayContainers = []; this.trayForms.map((f, index) => { + const props = this.getDefaultProps(species, f.formIndex); const isFormCaught = dexEntry ? (dexEntry.caughtAttr & species.getFullUnlocksData() & globalScene.gameData.getFormAttr(f.formIndex ?? 0)) > 0n : false; @@ -1974,7 +1853,7 @@ export default class PokedexUiHandler extends MessageUiHandler { this.formTrayContainer.setVisible(false); this.showingTray = false; - this.setSpeciesDetails(this.lastSpecies); + this.setSpeciesDetails(this.lastSpecies, this.pokemonContainers[this.cursor].formIndex); return true; } @@ -1994,7 +1873,7 @@ export default class PokedexUiHandler extends MessageUiHandler { const species = this.lastSpecies; const formIndex = this.trayForms[cursor].formIndex; - this.setSpeciesDetails(species, { formIndex: formIndex }); + this.setSpeciesDetails(species, formIndex); return changed; } @@ -2027,8 +1906,9 @@ export default class PokedexUiHandler extends MessageUiHandler { const container = this.pokemonContainers[cursor]; if (container) { const lastSpeciesIcon = container.icon; - const dexAttr = this.getCurrentDexProps(container.species.speciesId); - const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(container.species, dexAttr)); + + const props = this.getDefaultProps(container.species, container.formIndex); + this.checkIconId(lastSpeciesIcon, container.species, props.female, props.formIndex, props.shiny, props.variant); this.iconAnimHandler.addOrUpdate(lastSpeciesIcon, PokemonIconAnimMode.NONE); // Resume the animation for the previously selected species @@ -2036,7 +1916,7 @@ export default class PokedexUiHandler extends MessageUiHandler { } } - setSpecies(species: PokemonSpecies | null, props: DexAttrProps | null = null) { + setSpecies(species: PokemonSpecies | null, formIndex = 0) { this.speciesStarterDexEntry = species ? globalScene.gameData.dexData[species.speciesId] : null; if (!species && globalScene.ui.getTooltip().visible) { @@ -2065,7 +1945,7 @@ export default class PokedexUiHandler extends MessageUiHandler { const speciesForm = getPokemonSpeciesForm(species.speciesId, 0); this.setTypeIcons(speciesForm.type1, speciesForm.type2); - this.setSpeciesDetails(species, {}); + this.setSpeciesDetails(species, formIndex); this.pokemonSprite.clearTint(); @@ -2075,7 +1955,7 @@ export default class PokedexUiHandler extends MessageUiHandler { this.type1Icon.setVisible(true); this.type2Icon.setVisible(true); - this.setSpeciesDetails(species, props ?? {}); + this.setSpeciesDetails(species, formIndex); this.pokemonSprite.setTint(0x808080); } } else { @@ -2088,26 +1968,16 @@ export default class PokedexUiHandler extends MessageUiHandler { this.type2Icon.setVisible(false); if (species) { this.pokemonSprite.setTint(0x000000); - this.setSpeciesDetails(species, {}); + this.setSpeciesDetails(species, formIndex); } } } - setSpeciesDetails(species: PokemonSpecies, options: SpeciesDetails = {}): void { - let { shiny, formIndex, female, variant } = options; - + setSpeciesDetails(species: PokemonSpecies, formIndex = 0): void { // We will only update the sprite if there is a change to form, shiny/variant // or gender for species with gender sprite differences const shouldUpdateSprite = true; - if (species?.forms?.find(f => f.formKey === "female")) { - if (female !== undefined) { - formIndex = female ? 1 : 0; - } else if (formIndex !== undefined) { - female = formIndex === 1; - } - } - this.pokemonSprite.setVisible(false); if (this.assetLoadCancelled) { @@ -2122,24 +1992,10 @@ export default class PokedexUiHandler extends MessageUiHandler { globalScene.gameData.dexData[this.getStarterSpeciesId(species.speciesId)].caughtAttr & species.getFullUnlocksData(); - if (caughtAttr) { - const props = this.getSanitizedProps( - globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId)), - ); - - if (shiny === undefined) { - shiny = props.shiny; - } - if (formIndex === undefined) { - formIndex = props.formIndex; - } - if (female === undefined) { - female = props.female; - } - if (variant === undefined) { - variant = props.variant; - } - } + const props = this.getDefaultProps(species, formIndex); + const shiny = props.shiny; + const female = props.female; + const variant = props.variant; const isFormCaught = dexEntry ? (caughtAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n : false; const isFormSeen = dexEntry ? (dexEntry.seenAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n : false; @@ -2286,58 +2142,17 @@ export default class PokedexUiHandler extends MessageUiHandler { * @param speciesId the id of the species to get props for * @returns the dex props */ - getCurrentDexProps(speciesId: number): bigint { - let props = 0n; - const species = allSpecies.find(sp => sp.speciesId === speciesId); - const caughtAttr = - globalScene.gameData.dexData[speciesId].caughtAttr & - globalScene.gameData.dexData[this.getStarterSpeciesId(speciesId)].caughtAttr & - (species?.getFullUnlocksData() ?? 0n); + getDefaultProps(species: PokemonSpecies, formIndex = 0): DexAttrProps { + const props: DexAttrProps = { + shiny: false, + variant: 0, + formIndex: formIndex, + female: false, + }; + const fullUnlocks = species.getFullUnlocksData(); - /* this checks the gender of the pokemon; this works by checking a) that the starter preferences for the species exist, and if so, is it female. If so, it'll add DexAttr.FEMALE to our temp props - * It then checks b) if the caughtAttr for the pokemon is female and NOT male - this means that the ONLY gender we've gotten is female, and we need to add DexAttr.FEMALE to our temp props - * If neither of these pass, we add DexAttr.MALE to our temp props - */ - if ( - this.starterPreferences[speciesId]?.female || - ((caughtAttr & DexAttr.FEMALE) > 0n && (caughtAttr & DexAttr.MALE) === 0n) - ) { - props += DexAttr.FEMALE; - } else { - props += DexAttr.MALE; - } - /* This part is very similar to above, but instead of for gender, it checks for shiny within starter preferences. - * If they're not there, it enables shiny state by default if any shiny was caught - */ - if ( - this.starterPreferences[speciesId]?.shiny || - ((caughtAttr & DexAttr.SHINY) > 0n && this.starterPreferences[speciesId]?.shiny !== false) - ) { - props += DexAttr.SHINY; - if (this.starterPreferences[speciesId]?.variant !== undefined) { - props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.variant)) * DexAttr.DEFAULT_VARIANT; - } else { - /* This calculates the correct variant if there's no starter preferences for it. - * This gets the highest tier variant that you've caught and adds it to the temp props - */ - if ((caughtAttr & DexAttr.VARIANT_3) > 0) { - props += DexAttr.VARIANT_3; - } else if ((caughtAttr & DexAttr.VARIANT_2) > 0) { - props += DexAttr.VARIANT_2; - } else { - props += DexAttr.DEFAULT_VARIANT; - } - } - } else { - props += DexAttr.NON_SHINY; - props += DexAttr.DEFAULT_VARIANT; // we add the default variant here because non shiny versions are listed as default variant - } - if (this.starterPreferences[speciesId]?.form) { - // this checks for the form of the pokemon - props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.form)) * DexAttr.DEFAULT_FORM; - } else { - // Get the first unlocked form - props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr)); + if (fullUnlocks & DexAttr.FEMALE) { + props.female = true; } return props; From c3b97b244d14fbc8544f3f89414918fcc90cd4e4 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Fri, 28 Mar 2025 20:56:21 +0100 Subject: [PATCH 3/7] Refactoring setSpecies and setSpeciesDetails --- src/ui/pokedex-ui-handler.ts | 55 ++++++++++-------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index 4350581f53b..8f2e6ec4545 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -675,7 +675,9 @@ export default class PokedexUiHandler extends MessageUiHandler { this.starterSelectMessageBoxContainer.setVisible(!!text?.length); } - isSeen(species: PokemonSpecies, dexEntry: DexEntry): boolean { + isSeen(species: PokemonSpecies): boolean { + const dexEntry = globalScene.gameData.dexData[species.speciesId]; + if (dexEntry?.seenAttr) { return true; } @@ -1629,7 +1631,7 @@ export default class PokedexUiHandler extends MessageUiHandler { if (caughtAttr & data.species.getFullUnlocksData() || globalScene.dexForDevs) { container.icon.clearTint(); - } else if (this.isSeen(data.species, dexEntry)) { + } else if (this.isSeen(data.species)) { container.icon.setTint(0x808080); } else { container.icon.setTint(0); @@ -1813,7 +1815,7 @@ export default class PokedexUiHandler extends MessageUiHandler { const dexEntry = globalScene.gameData.dexData[species.speciesId]; this.trayContainers = []; - const isFormSeen = this.isSeen(species, dexEntry); + const isFormSeen = this.isSeen(species); this.trayForms.map((f, index) => { const props = this.getDefaultProps(species, f.formIndex); const isFormCaught = dexEntry @@ -1936,47 +1938,16 @@ export default class PokedexUiHandler extends MessageUiHandler { if (species) { this.lastSpecies = species; - } - - if ( - species && - (this.speciesStarterDexEntry?.seenAttr || this.speciesStarterDexEntry?.caughtAttr || globalScene.dexForDevs) - ) { - this.pokemonNumberText.setText(i18next.t("pokedexUiHandler:pokemonNumber") + padInt(species.speciesId, 4)); - - this.pokemonNameText.setText(species.name); - if (this.speciesStarterDexEntry?.caughtAttr || globalScene.dexForDevs) { this.startIconAnimation(this.cursor); - - const speciesForm = getPokemonSpeciesForm(species.speciesId, 0); - this.setTypeIcons(speciesForm.type1, speciesForm.type2); - - this.setSpeciesDetails(species, formIndex); - - this.pokemonSprite.clearTint(); - - this.type1Icon.clearTint(); - this.type2Icon.clearTint(); - } else { - this.type1Icon.setVisible(true); - this.type2Icon.setVisible(true); - - this.setSpeciesDetails(species, formIndex); - this.pokemonSprite.setTint(0x808080); } + // This now handles caught/seen/uncaught + this.setSpeciesDetails(species, formIndex); } else { - this.pokemonNumberText.setText( - species ? i18next.t("pokedexUiHandler:pokemonNumber") + padInt(species.speciesId, 4) : "", - ); - this.pokemonNameText.setText(species ? "???" : ""); + this.pokemonNumberText.setText(""); + this.pokemonNameText.setText(""); this.pokemonFormText.setText(""); - this.type1Icon.setVisible(false); - this.type2Icon.setVisible(false); - if (species) { - this.pokemonSprite.setTint(0x000000); - this.setSpeciesDetails(species, formIndex); - } + this.setTypeIcons(null, null); } } @@ -2005,7 +1976,7 @@ export default class PokedexUiHandler extends MessageUiHandler { const variant = props.variant; const isFormCaught = dexEntry ? (caughtAttr & globalScene.gameData.getFormAttr(formIndex ?? 0)) > 0n : false; - const isFormSeen = this.isSeen(species, dexEntry); + const isFormSeen = this.isSeen(species); const assetLoadCancelled = new BooleanHolder(false); this.assetLoadCancelled = assetLoadCancelled; @@ -2036,14 +2007,18 @@ export default class PokedexUiHandler extends MessageUiHandler { this.pokemonSprite.setTint(0); } + this.pokemonNumberText.setText(i18next.t("pokedexUiHandler:pokemonNumber") + padInt(species.speciesId, 4)); + if (isFormCaught || isFormSeen || globalScene.dexForDevs) { // TODO: change this once forms are refactored + this.pokemonNameText.setText(species.name); if (normalForm.includes(species.speciesId) && !formIndex) { this.pokemonFormText.setText(""); } else { this.pokemonFormText.setText(species.getFormNameToDisplay(formIndex, false)); } } else { + this.pokemonNameText.setText("???"); this.pokemonFormText.setText(""); } From 2e2f61ff5d51039ff3f05cff9a02728b69b4a6ae Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Sat, 29 Mar 2025 00:03:59 +0100 Subject: [PATCH 4/7] Fixed isSeen in page handler --- src/ui/pokedex-page-ui-handler.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index b359c188e0c..ee4e8b62ffc 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -257,6 +257,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { private menuDescriptions: string[]; private isFormGender: boolean; private filteredIndices: Species[] | null = null; + private filteredFormIndices: number[] | null = null; private availableVariants: number; private unlockedVariants: boolean[]; @@ -680,6 +681,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { }; this.formIndex = this.savedStarterAttributes.form ?? 0; this.filteredIndices = args[2] ?? null; + this.filteredFormIndices = args[3] ?? null; this.starterSetup(); if (args[4] instanceof Function) { @@ -696,6 +698,10 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.starterAttributes = this.initStarterPrefs(); + console.log(this.filteredIndices); + console.log(this.savedStarterAttributes); + console.log(this.starterAttributes); + this.menuOptions = Utils.getEnumKeys(MenuOptions).map(m => Number.parseInt(MenuOptions[m]) as MenuOptions); this.menuContainer.setVisible(true); @@ -1150,15 +1156,14 @@ export default class PokedexPageUiHandler extends MessageUiHandler { }); this.blockInput = false; } else { - ui.revertMode() - .then(() => { - console.log("exitCallback", this.exitCallback); - if (this.exitCallback instanceof Function) { - const exitCallback = this.exitCallback; - this.exitCallback = null; - exitCallback(); - } - }); + ui.revertMode().then(() => { + console.log("exitCallback", this.exitCallback); + if (this.exitCallback instanceof Function) { + const exitCallback = this.exitCallback; + this.exitCallback = null; + exitCallback(); + } + }); success = true; } } else { @@ -2222,8 +2227,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler { const ui = this.getUi(); const isFormCaught = this.isFormCaught(); + const isSeen = this.isSeen(); - if ((this.isCaught() && isFormCaught) || (this.speciesStarterDexEntry?.seenAttr && cursor === 5)) { + if ((this.isCaught() && isFormCaught) || isSeen) { ui.showText(this.menuDescriptions[cursor]); } else { ui.showText(""); @@ -2302,7 +2308,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } } - if (species && (this.speciesStarterDexEntry?.seenAttr || this.isCaught())) { + if (species && (this.isSeen() || this.isCaught())) { this.pokemonNumberText.setText(padInt(species.speciesId, 4)); if (this.isCaught()) { From a2c4f7eaf4bf0ba1ca0a0115235e423900a90136 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Sat, 29 Mar 2025 01:44:49 +0100 Subject: [PATCH 5/7] Setting up filteredFormIndices --- src/ui/pokedex-page-ui-handler.ts | 23 +++++++++++++++++++++-- src/ui/pokedex-ui-handler.ts | 18 ++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index ee4e8b62ffc..e26403b2ad1 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -257,7 +257,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { private menuDescriptions: string[]; private isFormGender: boolean; private filteredIndices: Species[] | null = null; - private filteredFormIndices: number[] | null = null; + private filteredFormIndices: (number | null)[] | null = null; + private filteredIndex: number; private availableVariants: number; private unlockedVariants: boolean[]; @@ -699,9 +700,21 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.starterAttributes = this.initStarterPrefs(); console.log(this.filteredIndices); + console.log(this.filteredFormIndices); console.log(this.savedStarterAttributes); console.log(this.starterAttributes); + if (this.filteredIndices) { + this.filteredIndex = this.filteredIndices.findIndex(id => id === this.species.speciesId); + } + + if (this.filteredFormIndices) { + const newForm = this.filteredFormIndices[this.filteredIndex]; + if (!isNullOrUndefined(newForm)) { + this.starterAttributes.form = newForm; + } + } + this.menuOptions = Utils.getEnumKeys(MenuOptions).map(m => Number.parseInt(MenuOptions[m]) as MenuOptions); this.menuContainer.setVisible(true); @@ -984,7 +997,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { const caughtAttr = this.isCaught(); // no preferences or Pokemon wasn't caught, return empty attribute - if (!starterAttributes || !caughtAttr) { + if (!starterAttributes || !this.isSeen()) { return {}; } @@ -1681,11 +1694,15 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.savedStarterAttributes.form = newFormIndex; this.moveInfoOverlay.clear(); this.clearText(); + if (this.filteredFormIndices) { + this.filteredFormIndices[this.filteredIndex] = null; + } ui.setMode( Mode.POKEDEX_PAGE, newSpecies, this.savedStarterAttributes, this.filteredIndices, + this.filteredFormIndices, ); return true; }, @@ -2062,6 +2079,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { newSpecies, this.savedStarterAttributes, this.filteredIndices, + this.filteredFormIndices, ); }); this.blockInput = false; @@ -2096,6 +2114,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { newSpecies, this.savedStarterAttributes, this.filteredIndices, + this.filteredFormIndices, ); }); break; diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index 8f2e6ec4545..f91967a1bb0 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -220,6 +220,7 @@ export default class PokedexUiHandler extends MessageUiHandler { private showFormTrayLabel: Phaser.GameObjects.Text; private canShowFormTray: boolean; private filteredIndices: Species[]; + private filteredFormIndices: Species[]; constructor() { super(Mode.POKEDEX); @@ -1029,7 +1030,13 @@ export default class PokedexUiHandler extends MessageUiHandler { } else if (this.showingTray) { if (button === Button.ACTION) { const formIndex = this.trayForms[this.trayCursor].formIndex; - ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, { form: formIndex }, this.filteredIndices); + ui.setOverlayMode( + Mode.POKEDEX_PAGE, + this.lastSpecies, + { form: formIndex }, + this.filteredIndices, + this.filteredFormIndices, + ); success = true; } else { const numberOfForms = this.trayContainers.length; @@ -1079,7 +1086,13 @@ export default class PokedexUiHandler extends MessageUiHandler { } else { if (button === Button.ACTION) { const formIndex = this.pokemonContainers[this.cursor]?.formIndex; - ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, { form: formIndex }, this.filteredIndices); + ui.setOverlayMode( + Mode.POKEDEX_PAGE, + this.lastSpecies, + { form: formIndex }, + this.filteredIndices, + this.filteredFormIndices, + ); success = true; } else { switch (button) { @@ -1589,6 +1602,7 @@ export default class PokedexUiHandler extends MessageUiHandler { }); this.filteredIndices = this.filteredPokemonData.map(c => c.species.speciesId); + this.filteredFormIndices = this.filteredPokemonData.map(c => c.formIndex); this.updateScroll(); }; From 711306041fd85762fb743ceaf812f2c030f8b368 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Sat, 29 Mar 2025 02:42:57 +0100 Subject: [PATCH 6/7] Proper navigation when filtering with forms --- src/ui/pokedex-page-ui-handler.ts | 38 ++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index e26403b2ad1..e40cd513910 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -681,9 +681,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { form: 0, }; this.formIndex = this.savedStarterAttributes.form ?? 0; - this.filteredIndices = args[2] ?? null; - this.filteredFormIndices = args[3] ?? null; - this.starterSetup(); + this.filteredIndices = args[2] ? [...args[2]] : null; + this.filteredFormIndices = args[3] ? [...args[3]] : null; if (args[4] instanceof Function) { this.exitCallback = args[4]; @@ -699,11 +698,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.starterAttributes = this.initStarterPrefs(); - console.log(this.filteredIndices); - console.log(this.filteredFormIndices); - console.log(this.savedStarterAttributes); - console.log(this.starterAttributes); - if (this.filteredIndices) { this.filteredIndex = this.filteredIndices.findIndex(id => id === this.species.speciesId); } @@ -711,10 +705,14 @@ export default class PokedexPageUiHandler extends MessageUiHandler { if (this.filteredFormIndices) { const newForm = this.filteredFormIndices[this.filteredIndex]; if (!isNullOrUndefined(newForm)) { + this.savedStarterAttributes.form = newForm; this.starterAttributes.form = newForm; + this.formIndex = newForm; } } + this.starterSetup(); + this.menuOptions = Utils.getEnumKeys(MenuOptions).map(m => Number.parseInt(MenuOptions[m]) as MenuOptions); this.menuContainer.setVisible(true); @@ -1164,7 +1162,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { const starterAttributes = this.previousStarterAttributes.pop(); this.moveInfoOverlay.clear(); this.clearText(); - ui.setModeForceTransition(Mode.POKEDEX_PAGE, species, starterAttributes); + ui.setModeForceTransition( + Mode.POKEDEX_PAGE, + species, + starterAttributes, + this.filteredIndices, + this.filteredFormIndices, + ); success = true; }); this.blockInput = false; @@ -1608,7 +1612,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.savedStarterAttributes.form = newFormIndex; this.moveInfoOverlay.clear(); this.clearText(); - ui.setMode(Mode.POKEDEX_PAGE, newSpecies, this.savedStarterAttributes); + ui.setMode( + Mode.POKEDEX_PAGE, + newSpecies, + this.savedStarterAttributes, + this.filteredIndices, + this.filteredFormIndices, + ); return true; }, onHover: () => this.showText(conditionText), @@ -1650,7 +1660,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.savedStarterAttributes.form = newFormIndex; this.moveInfoOverlay.clear(); this.clearText(); - ui.setMode(Mode.POKEDEX_PAGE, evoSpecies, this.savedStarterAttributes); + ui.setMode( + Mode.POKEDEX_PAGE, + evoSpecies, + this.savedStarterAttributes, + this.filteredIndices, + this.filteredFormIndices, + ); return true; }, onHover: () => this.showText(conditionText), From 7cea1fa6a177bf2e6b3f4138588cd9e93e449d73 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Sat, 29 Mar 2025 02:52:08 +0100 Subject: [PATCH 7/7] Removed leftover console log message --- src/ui/pokedex-page-ui-handler.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index e40cd513910..c480097263b 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -1174,7 +1174,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.blockInput = false; } else { ui.revertMode().then(() => { - console.log("exitCallback", this.exitCallback); if (this.exitCallback instanceof Function) { const exitCallback = this.exitCallback; this.exitCallback = null;