From 1de58d9890b64ec7a3f98585b20b6e7bbf7c922d Mon Sep 17 00:00:00 2001 From: James Diefenbach Date: Fri, 30 Aug 2024 18:59:12 +1000 Subject: [PATCH] code cleanup, documentation and slight refactor --- src/data/egg-hatch-data.ts | 89 ++++++++++++++++ src/overrides.ts | 1 - src/phases/egg-hatch-phase.ts | 111 +------------------ src/phases/egg-lapse-phase.ts | 19 +++- src/phases/egg-summary-phase.ts | 10 +- src/ui/egg-summary-ui-handler.ts | 142 ++----------------------- src/ui/pokemon-hatch-info-container.ts | 24 +++-- 7 files changed, 140 insertions(+), 256 deletions(-) create mode 100644 src/data/egg-hatch-data.ts diff --git a/src/data/egg-hatch-data.ts b/src/data/egg-hatch-data.ts new file mode 100644 index 00000000000..f14aaccb217 --- /dev/null +++ b/src/data/egg-hatch-data.ts @@ -0,0 +1,89 @@ +import BattleScene from "#app/battle-scene.js"; +import { PlayerPokemon } from "#app/field/pokemon.js"; +import { DexEntry, StarterDataEntry } from "#app/system/game-data.js"; + +export class EggHatchData { + public pokemon: PlayerPokemon; + public eggMoveIndex: number; + public eggMoveUnlocked: boolean; + public dexEntryBeforeUpdate: DexEntry; + public starterDataEntryBeforeUpdate: StarterDataEntry; + private scene: BattleScene; + + constructor(scene: BattleScene, pokemon: PlayerPokemon, eggMoveIndex: number) { + this.scene = scene; + this.pokemon = pokemon; + this.eggMoveIndex = eggMoveIndex; + } + + /** + * Sets the boolean for if the egg move for the hatch is a new unlock + * @param unlocked True if the EM is new + */ + setEggMoveUnlocked(unlocked: boolean) { + this.eggMoveUnlocked = unlocked; + } + + /** + * Stores a copy of the current DexEntry of the pokemon and StarterDataEntry of its starter + * Used before updating the dex, so comparing the pokemon to these entries will show the new attributes + */ + setDex() { + const currDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId]; + const currStarterDataEntry = this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId()]; + // this.prevDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId]; + this.dexEntryBeforeUpdate = { + seenAttr: currDexEntry.seenAttr, + caughtAttr: currDexEntry.caughtAttr, + natureAttr: currDexEntry.natureAttr, + seenCount: currDexEntry.seenCount, + caughtCount: currDexEntry.caughtCount, + hatchedCount: currDexEntry.hatchedCount, + ivs: [...currDexEntry.ivs] + }; + this.starterDataEntryBeforeUpdate = { + moveset: currStarterDataEntry.moveset, + eggMoves: currStarterDataEntry.eggMoves, + candyCount: currStarterDataEntry.candyCount, + friendship: currStarterDataEntry.friendship, + abilityAttr: currStarterDataEntry.abilityAttr, + passiveAttr: currStarterDataEntry.passiveAttr, + valueReduction: currStarterDataEntry.valueReduction, + classicWinCount: currStarterDataEntry.classicWinCount + }; + } + + /** + * Gets the dex entry before update + * @returns Dex Entry corresponding to this pokemon before the pokemon was added / updated to dex + */ + getDex(): DexEntry { + return this.dexEntryBeforeUpdate; + } + + /** + * Gets the starter dex entry before update + * @returns Starter Dex Entry corresponding to this pokemon before the pokemon was added / updated to dex + */ + getStarterEntry(): StarterDataEntry { + return this.starterDataEntryBeforeUpdate; + } + + /** + * Update the pokedex data corresponding with the new hatch's pokemon data + * Also sets whether the egg move is a new unlock or not + * @param showMessage boolean to show messages for the new catches and egg moves (false by default) + * @returns + */ + updatePokemon(showMessage : boolean = false) { + return new Promise(resolve => { + this.scene.gameData.setPokemonCaught(this.pokemon, true, true, showMessage).then(() => { + this.scene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs); + this.scene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex, showMessage).then((value) => { + this.setEggMoveUnlocked(value); + resolve(); + }); + }); + }); + } +} diff --git a/src/overrides.ts b/src/overrides.ts index 193fe7ceb25..32ff116f41d 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -29,7 +29,6 @@ import { type ModifierOverride } from "./modifier/modifier-type"; * } * ``` */ - const overrides = {} satisfies Partial>; /** diff --git a/src/phases/egg-hatch-phase.ts b/src/phases/egg-hatch-phase.ts index 65b9a9ebeb4..18abe67da7c 100644 --- a/src/phases/egg-hatch-phase.ts +++ b/src/phases/egg-hatch-phase.ts @@ -12,8 +12,8 @@ import { Mode } from "#app/ui/ui.js"; import i18next from "i18next"; import SoundFade from "phaser3-rex-plugins/plugins/soundfade"; import * as Utils from "#app/utils.js"; -import { DexEntry, StarterDataEntry } from "#app/system/game-data.js"; import { EggLapsePhase } from "./egg-lapse-phase"; +import { EggHatchData } from "#app/data/egg-hatch-data.js"; /** @@ -444,119 +444,12 @@ export class EggHatchPhase extends Phase { /** * Generates a Pokemon to be hatched by the egg + * Also stores the generated pokemon in this.eggHatchData * @returns the hatched PlayerPokemon */ generatePokemon(): PlayerPokemon { - // let ret: PlayerPokemon; - - // this.scene.executeWithSeedOffset(() => { - // ret = this.egg.generatePlayerPokemon(this.scene); - // }, this.egg.id, EGG_SEED.toString()); - // this.eggHatchContainer.add(new EggHatchData(this.scene, )) - - // return ret; this.eggHatchData = this.hatchScene.generatePokemon(this.egg); this.eggHatchData.setDex(); return this.eggHatchData.pokemon; } - - // getNewProperties(pokemon: PlayerPokemon) { - // const speciesId = pokemon.species.speciesId; - // let newProperties = {newEggMove: false, newStarter: false}; - - // if (!this.starterData[speciesId].eggMoves) { - // this.starterData[speciesId].eggMoves = 0; - // } - - // const value = Math.pow(2, eggMoveIndex); - -// if (this.starterData[speciesId].eggMoves & value) { -// resolve(false); -// return; -// } -// } -} - -export class EggHatchData { - public pokemon: PlayerPokemon; - public eggMoveIndex: integer; - public eggMoveUnlocked: boolean; - public prevDexEntry: DexEntry; - public prevStarterEntry: StarterDataEntry; - private scene: BattleScene; - - constructor(scene: BattleScene, pokemon: PlayerPokemon, eggMoveIndex: integer) { - this.scene = scene; - this.pokemon = pokemon; - this.eggMoveIndex = eggMoveIndex; - } - - setEggMoveUnlocked(unlocked: boolean) { - this.eggMoveUnlocked = unlocked; - } - - setDex() { - const currDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId]; - const starterDataEntry = this.scene.gameData.starterData[this.pokemon.species.getRootSpeciesId()]; - // this.prevDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId]; - this.prevDexEntry = { - seenAttr: currDexEntry.seenAttr, - caughtAttr: currDexEntry.caughtAttr, - natureAttr: currDexEntry.natureAttr, - seenCount: currDexEntry.seenCount, - caughtCount: currDexEntry.caughtCount, - hatchedCount: currDexEntry.hatchedCount, - ivs: [...currDexEntry.ivs] - }; - this.prevStarterEntry = { - moveset: starterDataEntry.moveset, - eggMoves: starterDataEntry.eggMoves, - candyCount: starterDataEntry.candyCount, - friendship: starterDataEntry.friendship, - abilityAttr: starterDataEntry.abilityAttr, - passiveAttr: starterDataEntry.passiveAttr, - valueReduction: starterDataEntry.valueReduction, - classicWinCount: starterDataEntry.classicWinCount - }; - console.log("setting dex:"); - console.log(this.prevDexEntry); - // export interface DexEntry { - - // } - } - - getDex(): DexEntry { - console.log("getting dex:"); - console.log(this.prevDexEntry); - return this.prevDexEntry; - } - - // function that can be called when doing egg summary to set dex one at a time - updatePokemon(showMessage : boolean = false) { - // console.log("setting dex (actual, local):"); - // const currDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId]; - // console.log(currDexEntry); - // console.log(this.prevDexEntry); - // this.setDex(); - // TODO seperate dex updates for skip or serial hatch - // this.setDex(); - return new Promise(resolve => { - this.scene.gameData.setPokemonCaught(this.pokemon, true, true, showMessage).then(() => { - this.scene.gameData.updateSpeciesDexIvs(this.pokemon.species.speciesId, this.pokemon.ivs); - this.scene.gameData.setEggMoveUnlocked(this.pokemon.species, this.eggMoveIndex, showMessage).then((value) => { - this.eggMoveUnlocked = value; - console.log("updates complete, logging actual dex and local dexEntry"); - const currDexEntry = this.scene.gameData.dexData[this.pokemon.species.speciesId]; - console.log(currDexEntry); - console.log(this.prevDexEntry); - - resolve(); - }); - }); - }); - } - - getEggMove() { - // TODO easy function to get egg move for display (or no egg move) - } } diff --git a/src/phases/egg-lapse-phase.ts b/src/phases/egg-lapse-phase.ts index c5ca5bb6f2b..568b6225278 100644 --- a/src/phases/egg-lapse-phase.ts +++ b/src/phases/egg-lapse-phase.ts @@ -3,11 +3,12 @@ import { Egg, EGG_SEED } from "#app/data/egg.js"; import { Phase } from "#app/phase.js"; import i18next from "i18next"; import Overrides from "#app/overrides"; -import { EggHatchData, EggHatchPhase } from "./egg-hatch-phase"; +import { EggHatchPhase } from "./egg-hatch-phase"; import { Mode } from "#app/ui/ui.js"; import { achvs } from "#app/system/achv.js"; import { PlayerPokemon } from "#app/field/pokemon.js"; import { EggSummaryPhase } from "./egg-summary-phase"; +import { EggHatchData } from "#app/data/egg-hatch-data.js"; export class EggLapsePhase extends Phase { @@ -23,11 +24,14 @@ export class EggLapsePhase extends Phase { return Overrides.EGG_IMMEDIATE_HATCH_OVERRIDE ? true : --egg.hatchWaves < 1; }); - let eggsToHatchCount: integer = eggsToHatch.length; + let eggsToHatchCount: number = eggsToHatch.length; this.eggHatchData= []; + + const minEggsToPromptSkip = 5; + if (eggsToHatchCount > 0) { - if (eggsToHatchCount >= 5) { + if (eggsToHatchCount >= minEggsToPromptSkip) { this.scene.ui.showText(i18next.t("battle:eggHatching"), 0, () => { // show prompt for skip this.scene.ui.showText(i18next.t("battle:eggSkipPrompt"), 0); @@ -67,6 +71,12 @@ export class EggLapsePhase extends Phase { } } + /** + * Hatches an egg and stores it in the local EggHatchData array without animations + * Also validates the achievements for the hatched pokemon and removes the egg + * @param egg egg to hatch + * @returns + */ hatchEggSilently(egg: Egg) { const eggIndex = this.scene.gameData.eggs.findIndex(e => e.id === egg.id); if (eggIndex === -1) { @@ -100,9 +110,8 @@ export class EggLapsePhase extends Phase { } - // TODO fix duplicated code neatly /** - * Generates a Pokemon and hatch data to be hatched by the egg + * Generates a Pokemon and creates a new EggHatchData instance for the given egg * @returns the hatched PlayerPokemon */ generatePokemon(egg: Egg): EggHatchData { diff --git a/src/phases/egg-summary-phase.ts b/src/phases/egg-summary-phase.ts index 421d7066fd2..aed91014cf2 100644 --- a/src/phases/egg-summary-phase.ts +++ b/src/phases/egg-summary-phase.ts @@ -1,14 +1,18 @@ import BattleScene from "#app/battle-scene.js"; import { Phase } from "#app/phase.js"; -import { EggHatchData } from "./egg-hatch-phase"; import { Mode } from "#app/ui/ui.js"; import EggHatchSceneHandler from "#app/ui/egg-hatch-scene-handler.js"; +import { EggHatchData } from "#app/data/egg-hatch-data.js"; +/** + * Class that represents the egg summary phase + * It does some of the function for updating egg data + * Phase is handled mostly by the egg-hatch-scene-handler UI + */ export class EggSummaryPhase extends Phase { private eggHatchData: EggHatchData[]; private eggHatchHandler: EggHatchSceneHandler; - private eggHatchOverlay: Phaser.GameObjects.Rectangle; constructor(scene: BattleScene, eggHatchData: EggHatchData[]) { super(scene); @@ -46,6 +50,8 @@ export class EggSummaryPhase extends Phase { console.log("ended egg hatch summary phase"); this.eggHatchHandler.clear(); // this.scene.time.delayedCall(250, () => this.scene.setModifiersVisible(true)); + this.scene.ui.setModeForceTransition(Mode.MESSAGE).then(() => { + }); super.end(); } } diff --git a/src/ui/egg-summary-ui-handler.ts b/src/ui/egg-summary-ui-handler.ts index 6ff3cfb644a..45c25085c8e 100644 --- a/src/ui/egg-summary-ui-handler.ts +++ b/src/ui/egg-summary-ui-handler.ts @@ -8,10 +8,15 @@ import { Gender } from "#app/data/gender.js"; import { getVariantTint } from "#app/data/variant.js"; import { EggTier } from "#app/enums/egg-type.js"; import PokemonHatchInfoContainer from "./pokemon-hatch-info-container"; -import { EggHatchData } from "#app/phases/egg-hatch-phase.js"; import { EggSummaryPhase } from "#app/phases/egg-summary-phase.js"; import { DexAttr } from "#app/system/game-data.js"; +import { EggHatchData } from "#app/data/egg-hatch-data.js"; +/** + * UI Handler for the egg summary. + * Handles navigation and display of each pokemon as a list + * Also handles display of the pokemon-hatch-info-container + */ export default class EggSummaryUiHandler extends MessageUiHandler { private pokemonListContainer: Phaser.GameObjects.Container; private pokemonIconSpritesContainer: Phaser.GameObjects.Container; @@ -53,18 +58,12 @@ export default class EggSummaryUiHandler extends MessageUiHandler { this.eggHatchContainer.setVisible(false); ui.add(this.eggHatchContainer); - // this.scene.fieldUI.add(this.eggHatchContainer); - - // const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860); - // bgColor.setOrigin(0, 0); - // this.eggListContainer.add(bgColor); this.iconAnimHandler = new PokemonIconAnimHandler(); this.iconAnimHandler.setup(this.scene); this.eggHatchBg = this.scene.add.image(0, 0, "egg_summary_bg"); this.eggHatchBg.setOrigin(0, 0); this.eggHatchContainer.add(this.eggHatchBg); - // this.eggHatchContainer.add(addWindow(this.scene, 107, 1, 212, 178)); this.pokemonIconsContainer = this.scene.add.container(115, 9); @@ -76,16 +75,6 @@ export default class EggSummaryUiHandler extends MessageUiHandler { this.cursorObj.setOrigin(0, 0); this.pokemonListContainer.add(this.cursorObj); - // this.eggSprite = this.scene.add.sprite(54, 37, "egg"); - // this.eggListContainer.add(this.eggSprite); - - - // TODO remove? - this.eggListMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6); - this.eggListMessageBoxContainer.setVisible(false); - this.pokemonListContainer.add(this.eggListMessageBoxContainer); - - // TODO clean up info container showing this.infoContainer = new PokemonHatchInfoContainer(this.scene, this.pokemonListContainer); this.infoContainer.setup(); this.infoContainer.changeToEggSummaryLayout(); @@ -105,6 +94,8 @@ export default class EggSummaryUiHandler extends MessageUiHandler { // this.currentPokemonSprite.setVisible(false); // this.pokemonEggMovesContainer.setVisible(false); this.getUi().hideTooltip(); + // TODO clear EggHatchData + // TODO back sprites and extra sprites etc. console.log("Egg Summary Handler cleared"); } @@ -201,7 +192,7 @@ export default class EggSummaryUiHandler extends MessageUiHandler { pb.setScale(0.5); // add animation for new unlocks (new catch or new shiny or new form) - const dexEntry = value.prevDexEntry; + const dexEntry = value.dexEntryBeforeUpdate; const caughtAttr = dexEntry.caughtAttr; const newShiny = BigInt(1 << (displayPokemon.shiny ? 1 : 0)); const newVariant = BigInt(1 << (displayPokemon.variant + 4)); @@ -220,126 +211,12 @@ export default class EggSummaryUiHandler extends MessageUiHandler { em.setVisible(value.eggMoveUnlocked); this.pokemonIconsContainer.add(em); }); - // console.log("generating icons..."); - // this.shinyIcons = new Array(this.eggHatchData.length).fill(null).map((_, i) => { - // const x = (i % 11) * 18; - // const y = Math.floor(i / 11) * 18; - // const ret = this.scene.add.image(x + 12, y + 2, "shiny_star_small"); - // ret.setOrigin(0, 0); - // ret.setScale(0.5); - // ret.setVisible(false); - // this.pokemonIconsContainer.add(ret); - // return ret; - // }); - - // this.hiddenAbilityIcons = new Array(this.eggHatchData.length).fill(null).map((_, i) => { - // const x = (i % 11) * 18; - // const y = Math.floor(i / 11) * 18; - // const ret = this.scene.add.image(x + 12, y + 7, "ha_capsule"); - // ret.setOrigin(0, 0); - // ret.setScale(0.5); - // ret.setVisible(false); - // this.pokemonIconsContainer.add(ret); - // return ret; - // }); - - // this.pokeballIcons = new Array(this.eggHatchData.length).fill(null).map((_, i) => { - // const x = (i % 11) * 18; - // const y = Math.floor(i / 11) * 18; - // const ret = this.scene.add.image(x + 12, y + 14, "icon_owned"); - // ret.setOrigin(0, 0); - // ret.setScale(0.5); - // ret.setVisible(false); - // this.pokemonIconsContainer.add(ret); - // return ret; - // }); - - // this.eggMoveIcons = new Array(this.eggHatchData.length).fill(null).map((_, i) => { - // const x = (i % 11) * 18; - // const y = Math.floor(i / 11) * 18; - // const ret = this.scene.add.image(x, y + 2, "icon_egg_move"); - // ret.setOrigin(0, 0); - // ret.setScale(0.5); - // ret.setVisible(false); - // this.pokemonIconsContainer.add(ret); - // return ret; - // }); - // console.log("icons done"); - - // console.log("generating info containers..."); - - // // setup single info container - - // // this.infoContainers = new Array(this.pokemonHatched.length).fill(null).map((_, i) => { - // // const ret = new PokemonInfoContainer(this.scene, 45, 100); - // // ret.setup(); - // // ret.show(this.pokemonHatched[i]); - // // ret.setVisible(false); - // // ret.setScale(0.8); - // // this.eggListPokemonContainer.add(ret); - // // return ret; - // // }); - - - - // // TODO sort by number / egg type - // // TODO add egg hatch count in bottom right - // let i = 0; - // for (const hatchData of this.eggHatchData) { - // console.log(hatchData); - // const displayPokemon = hatchData.pokemon; - - // // const x = (index % 9) * 18; - // // const y = Math.floor(index / 9) * 18; - // const x = (i % 11) * 18; - // const y = Math.floor(i / 11) * 18; - // const icon = this.scene.add.sprite(x-2, y+2, displayPokemon.species.getIconAtlasKey(displayPokemon.formIndex, displayPokemon.shiny, displayPokemon.variant)); - // // const icon = this.scene.add.sprite(x - 2, y + 2, "egg_icons"); - // icon.setScale(0.5); - // icon.setOrigin(0, 0); - // icon.setOrigin(0, 0); - // icon.setFrame(displayPokemon.species.getIconId(displayPokemon.gender === Gender.FEMALE, displayPokemon.formIndex, displayPokemon.shiny, displayPokemon.variant)); - // // icon.setFrame(egg.getKey()); - // this.pokemonIconSpritesContainer.add(icon); - // this.iconAnimHandler.addOrUpdate(icon, PokemonIconAnimMode.NONE); - - // // this.checkIconId(icon, displayPokemon.species, displayPokemon.female, displayPokemon.formIndex, displayPokemon.shiny, displayPokemon.variant); - - // // DONE shiny icon funcitonality for variants - // // TODO test shiny icons - // this.shinyIcons[i].setVisible(displayPokemon.shiny); - // this.shinyIcons[i].setTint(getVariantTint(displayPokemon.variant)); - // // this.shinyIcons[i].setTint(getVariantTint(speciesVariants[v] === DexAttr.DEFAULT_VARIANT ? 0 : speciesVariants[v] === DexAttr.VARIANT_2 ? 1 : 2)); - // // DONE new pokemon / catch icon functionality - // // TODO test for new pokemon - // const dexEntry = hatchData.prevDexEntry; - // const caughtAttr = dexEntry.caughtAttr; - // this.pokeballIcons[i].setVisible(!caughtAttr); - // // this.pokeballIcons[i].setVisible(this.scene.gameData.dexData[displayPokemon.species.speciesId].caughtAttr) - - - // this.hiddenAbilityIcons[i].setVisible((displayPokemon.hasAbility(displayPokemon.species.abilityHidden))); - - // this.eggMoveIcons[i].setVisible(hatchData.eggMoveUnlocked); - - // console.log(displayPokemon); - // console.log(displayPokemon.shiny); - // console.log(caughtAttr); - // console.log(hatchData.eggMoveUnlocked); - // // this.pokeballIcons[i].setVisible(true); - // // this.shinyIcons[i].setVisible(true); - // // this.hiddenAbilityIcons[i].setVisible(true); - - // i++; - // } this.setCursor(0); return true; } - - processInput(button: Button): boolean { const ui = this.getUi(); @@ -391,6 +268,7 @@ export default class EggSummaryUiHandler extends MessageUiHandler { } setCursor(cursor: integer): boolean { + console.log("set cursor", cursor); let changed = false; const lastCursor = this.cursor; diff --git a/src/ui/pokemon-hatch-info-container.ts b/src/ui/pokemon-hatch-info-container.ts index e3b0dff5f3a..0fed7255041 100644 --- a/src/ui/pokemon-hatch-info-container.ts +++ b/src/ui/pokemon-hatch-info-container.ts @@ -10,10 +10,14 @@ import { speciesEggMoves } from "#app/data/egg-moves.js"; import { allMoves } from "#app/data/move.js"; import { Species } from "#app/enums/species.js"; import { getEggTierForSpecies } from "#app/data/egg.js"; -import { EggHatchData } from "#app/phases/egg-hatch-phase.js"; import { starterColors } from "../battle-scene"; import { argbFromRgba } from "@material/material-color-utilities"; +import { EggHatchData } from "#app/data/egg-hatch-data.js"; +/** + * Class for the hatch info summary of each pokemon + * Holds an info container aswell as an additional egg sprite, name, egg moves and main sprite + */ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { private currentPokemonSprite: Phaser.GameObjects.Sprite; private pokemonNumberText: Phaser.GameObjects.Text; @@ -42,6 +46,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.currentPokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); this.pokemonListContainer.add(this.currentPokemonSprite); + // setup name and number this.pokemonNumberText = addTextObject(this.scene, 80, 107.5, "0000", TextStyle.SUMMARY, {fontSize: 74}); this.pokemonNumberText.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonNumberText); @@ -50,6 +55,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.pokemonNameText.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonNameText); + // setup egg icon and candy count this.pokemonHatchedIcon = this.scene.add.sprite(-5, 90, "egg_icons"); this.pokemonHatchedIcon.setOrigin(0, 0.2); this.pokemonHatchedIcon.setScale(0.8); @@ -69,6 +75,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.pokemonCandyCountText.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonCandyCountText); + // setup egg moves this.pokemonEggMoveContainers = []; this.pokemonEggMoveBgs = []; this.pokemonEggMoveLabels = []; @@ -106,7 +113,13 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { } + /** + * Updates the info container with the appropriate dex data and starter entry from the hatchInfo + * Also updates the displayed name, number, egg moves and main animated sprite for the pokemon + * @param hatchInfo The EggHatchData of the pokemon / new hatch to show + */ showHatchInfo(hatchInfo: EggHatchData) { + console.log("showing hatch info", hatchInfo.pokemon.name); this.pokemonEggMovesContainer.setVisible(true); const displayPokemon = hatchInfo.pokemon; @@ -115,7 +128,8 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { const formIndex = displayPokemon.formIndex; const shiny = displayPokemon.shiny; const variant = displayPokemon.variant; - super.show(displayPokemon, false, 1, hatchInfo.getDex(), hatchInfo.prevStarterEntry, true); + + super.show(displayPokemon, false, 1, hatchInfo.getDex(), hatchInfo.getStarterEntry(), true); const colorScheme = starterColors[species.speciesId]; this.pokemonCandyIcon.setTint(argbFromRgba(Utils.rgbHexToRgba(colorScheme[0]))); @@ -138,7 +152,6 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.currentPokemonSprite.setPipelineData("spriteKey", species.getSpriteKey(female, formIndex, shiny, variant)); // this.pokemonSprite.setVisible(!this.statsMode); }); - // TODO pokemon name and number this.pokemonNumberText.setText(Utils.padInt(species.speciesId, 4)); this.pokemonNameText.setText(species.name); @@ -146,13 +159,12 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { const hasEggMoves = species && speciesEggMoves.hasOwnProperty(species.speciesId); for (let em = 0; em < 4; em++) { - // TODO add some new egg move indicator const eggMove = hasEggMoves ? allMoves[speciesEggMoves[species.speciesId][em]] : null; const eggMoveUnlocked = eggMove && this.scene.gameData.starterData[species.speciesId].eggMoves & Math.pow(2, em); this.pokemonEggMoveBgs[em].setFrame(Type[eggMove ? eggMove.type : Type.UNKNOWN].toString().toLowerCase()); this.pokemonEggMoveLabels[em].setText(eggMove && eggMoveUnlocked ? eggMove.name : "???"); - if (!(eggMove && hatchInfo.prevStarterEntry.eggMoves & Math.pow(2, em)) && eggMoveUnlocked) { + if (!(eggMove && hatchInfo.starterDataEntryBeforeUpdate.eggMoves & Math.pow(2, em)) && eggMoveUnlocked) { this.pokemonEggMoveLabels[em].setText("(+) " + eggMove.name); } } @@ -160,7 +172,6 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { // will always have at least one egg move this.pokemonEggMovesContainer.setVisible(true); - // TODO show egg tier / icon if (species.speciesId === Species.MANAPHY || species.speciesId === Species.PHIONE) { this.pokemonHatchedIcon.setFrame("manaphy"); } else { @@ -169,5 +180,4 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { } - }