From 0d72857d4e19075ccfa656a7d28e623db8cef736 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Sat, 22 Feb 2025 22:51:34 +0100 Subject: [PATCH] PokedexMonContainer now has a method to change species. --- src/ui/pokedex-mon-container.ts | 67 +++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/src/ui/pokedex-mon-container.ts b/src/ui/pokedex-mon-container.ts index 31a98c30d1c..83c85bdd116 100644 --- a/src/ui/pokedex-mon-container.ts +++ b/src/ui/pokedex-mon-container.ts @@ -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"); @@ -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"); @@ -196,6 +168,43 @@ 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.icon.setTint(0); + 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.`);