mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-21 07:42:25 +02:00
PokedexMonContainer now has a method to change species.
This commit is contained in:
parent
5b1950a1ae
commit
0d72857d4e
@ -36,26 +36,7 @@ export class PokedexMonContainer extends Phaser.GameObjects.Container {
|
|||||||
constructor(species: PokemonSpecies, options: SpeciesDetails = {}) {
|
constructor(species: PokemonSpecies, options: SpeciesDetails = {}) {
|
||||||
super(globalScene, 0, 0);
|
super(globalScene, 0, 0);
|
||||||
|
|
||||||
this.species = species;
|
this.setSpecies(species, options);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// starter passive bg
|
// starter passive bg
|
||||||
const starterPassiveBg = globalScene.add.image(2, 5, "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.add(starterPassiveBg);
|
||||||
this.starterPassiveBgs = 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
|
// shiny icons
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
const shinyIcon = globalScene.add.image(i * -3 + 12, 2, "shiny_star_small");
|
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;
|
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) {
|
checkIconId(female, formIndex, shiny, variant) {
|
||||||
if (this.icon.frame.name !== this.species.getIconId(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.`);
|
console.log(`${this.species.name}'s variant icon does not exist. Replacing with default.`);
|
||||||
|
Loading…
Reference in New Issue
Block a user