This commit is contained in:
Wlowscha 2025-04-09 10:48:49 -05:00 committed by GitHub
commit c182559093
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 272 additions and 430 deletions

View File

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

View File

@ -257,6 +257,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
private menuDescriptions: string[];
private isFormGender: boolean;
private filteredIndices: Species[] | null = null;
private filteredFormIndices: (number | null)[] | null = null;
private filteredIndex: number;
private availableVariants: number;
private unlockedVariants: boolean[];
@ -679,8 +681,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
form: 0,
};
this.formIndex = this.savedStarterAttributes.form ?? 0;
this.filteredIndices = args[2] ?? 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];
@ -696,6 +698,21 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
this.starterAttributes = this.initStarterPrefs();
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.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);
@ -1145,13 +1162,19 @@ 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;
} else {
ui.revertMode().then(() => {
console.log("exitCallback", this.exitCallback);
if (this.exitCallback instanceof Function) {
const exitCallback = this.exitCallback;
this.exitCallback = null;
@ -1589,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),
@ -1631,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),
@ -1675,11 +1710,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;
},
@ -2061,6 +2100,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
newSpecies,
this.savedStarterAttributes,
this.filteredIndices,
this.filteredFormIndices,
);
});
this.blockInput = false;
@ -2100,6 +2140,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler {
newSpecies,
this.savedStarterAttributes,
this.filteredIndices,
this.filteredFormIndices,
);
});
break;

View File

@ -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;
@ -229,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);
@ -631,8 +623,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 +640,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
*/
@ -781,7 +676,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;
}
@ -1133,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;
@ -1182,7 +1085,14 @@ 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,
{ form: formIndex },
this.filteredIndices,
this.filteredFormIndices,
);
success = true;
} else {
switch (button) {
@ -1309,28 +1219,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;
}
// 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 = [];
@ -1345,143 +1233,18 @@ 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 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[species.speciesId]?.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);
@ -1638,24 +1401,156 @@ 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);
const formsData: ContainerData[] = [];
allForms.forEach((form, formIndex) => {
const data: ContainerData = {
species: species,
cost: globalScene.gameData.getSpeciesStarterValue(starterId),
formIndex: formIndex,
};
// 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
) {
formsData.push(data);
}
});
if (formsData.length === allForms.length) {
this.filteredPokemonData.push(formsData[0]);
} else {
this.filteredPokemonData.push(...formsData);
}
});
@ -1707,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();
};
@ -1729,7 +1625,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);
@ -1749,7 +1645,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);
@ -1802,31 +1698,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);
@ -1868,9 +1758,10 @@ export default class PokedexUiHandler extends MessageUiHandler {
this.cursorObj.setPosition(pos.x - 1, pos.y + 1);
const species = this.pokemonContainers[cursor]?.species;
const formIndex = this.pokemonContainers[cursor]?.formIndex;
if (species) {
this.setSpecies(species);
this.setSpecies(species, formIndex);
return true;
}
}
@ -1936,12 +1827,11 @@ 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 = [];
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
? (dexEntry.caughtAttr & species.getFullUnlocksData() & globalScene.gameData.getFormAttr(f.formIndex ?? 0)) > 0n
: false;
@ -1986,7 +1876,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;
}
@ -2006,7 +1896,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;
}
@ -2039,8 +1929,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
@ -2048,7 +1939,7 @@ export default class PokedexUiHandler extends MessageUiHandler {
}
}
setSpecies(species: PokemonSpecies | null) {
setSpecies(species: PokemonSpecies | null, formIndex = 0) {
this.speciesStarterDexEntry = species ? globalScene.gameData.dexData[species.speciesId] : null;
if (!species && globalScene.ui.getTooltip().visible) {
@ -2061,65 +1952,24 @@ 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, {});
this.pokemonSprite.clearTint();
this.type1Icon.clearTint();
this.type2Icon.clearTint();
} else {
this.type1Icon.setVisible(true);
this.type2Icon.setVisible(true);
this.setSpeciesDetails(species);
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, {});
}
this.setTypeIcons(null, null);
}
}
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) {
@ -2134,27 +1984,13 @@ 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 = this.isSeen(species, dexEntry);
const isFormSeen = this.isSeen(species);
const assetLoadCancelled = new BooleanHolder(false);
this.assetLoadCancelled = assetLoadCancelled;
@ -2185,14 +2021,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("");
}
@ -2298,58 +2138,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;