Skip to content

Commit

Permalink
[UI/UX] Reducing number of containers in the Pokédex (pagefaultgames#…
Browse files Browse the repository at this point in the history
…5400)

* PokedexMonContainer now has a method to change species.

* Not setting tint to 0 in the container

* Using only 81 containers in Pokédex

* Apply suggestions from code review

Co-authored-by: NightKev <[email protected]>

---------

Co-authored-by: NightKev <[email protected]>
  • Loading branch information
2 people authored and IBBCalc committed Feb 27, 2025
1 parent 13ba6bb commit 6cae8b2
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 174 deletions.
66 changes: 37 additions & 29 deletions src/ui/pokedex-mon-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,7 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
constructor(species: PokemonSpecies, options: SpeciesDetails = {}) {
super(globalScene, 0, 0);

this.species = species;

const { shiny, formIndex, female, variant } = options;

const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, false, true);
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);

if (!isNullOrUndefined(formIndex)) {
defaultProps.formIndex = formIndex;
}
if (!isNullOrUndefined(shiny)) {
defaultProps.shiny = shiny;
}
if (!isNullOrUndefined(variant)) {
defaultProps.variant = variant;
}
if (!isNullOrUndefined(female)) {
defaultProps.female = female;
}

this.setSpecies(species, options);

// starter passive bg
const starterPassiveBg = globalScene.add.image(2, 5, "passive_bg");
Expand All @@ -65,15 +46,6 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
this.add(starterPassiveBg);
this.starterPassiveBgs = starterPassiveBg;

// icon
this.icon = globalScene.add.sprite(-2, 2, species.getIconAtlasKey(defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.icon.setScale(0.5);
this.icon.setOrigin(0, 0);
this.icon.setFrame(species.getIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.checkIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant);
this.icon.setTint(0);
this.add(this.icon);

// shiny icons
for (let i = 0; i < 3; i++) {
const shinyIcon = globalScene.add.image(i * -3 + 12, 2, "shiny_star_small");
Expand Down Expand Up @@ -196,6 +168,42 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
this.passive2OverlayIcon = passive2OverlayIcon;
}

setSpecies(species: PokemonSpecies, options: SpeciesDetails = {}) {

this.species = species;

const { shiny, formIndex, female, variant } = options;

const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, false, true);
const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr);

if (!isNullOrUndefined(formIndex)) {
defaultProps.formIndex = formIndex;
}
if (!isNullOrUndefined(shiny)) {
defaultProps.shiny = shiny;
}
if (!isNullOrUndefined(variant)) {
defaultProps.variant = variant;
}
if (!isNullOrUndefined(female)) {
defaultProps.female = female;
}

if (this.icon) {
this.remove(this.icon);
this.icon.destroy(); // Properly removes the sprite from memory
}

// icon
this.icon = globalScene.add.sprite(-2, 2, species.getIconAtlasKey(defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.icon.setScale(0.5);
this.icon.setOrigin(0, 0);
this.icon.setFrame(species.getIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant));
this.checkIconId(defaultProps.female, defaultProps.formIndex, defaultProps.shiny, defaultProps.variant);
this.add(this.icon);
}

checkIconId(female, formIndex, shiny, variant) {
if (this.icon.frame.name !== this.species.getIconId(female, formIndex, shiny, variant)) {
console.log(`${this.species.name}'s variant icon does not exist. Replacing with default.`);
Expand Down
Loading

0 comments on commit 6cae8b2

Please sign in to comment.