From 2535f0ab677e3b61cef9443349e8b9a3f62a23fd Mon Sep 17 00:00:00 2001 From: James Diefenbach Date: Sat, 31 Aug 2024 13:18:57 +1000 Subject: [PATCH] more time logs and fix pre-load issues --- src/phases/egg-lapse-phase.ts | 25 ++++++++++++++------ src/ui/egg-summary-ui-handler.ts | 1 - src/ui/pokemon-hatch-info-container.ts | 32 +++----------------------- 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/phases/egg-lapse-phase.ts b/src/phases/egg-lapse-phase.ts index d94ecf64996..1f7ef83478b 100644 --- a/src/phases/egg-lapse-phase.ts +++ b/src/phases/egg-lapse-phase.ts @@ -13,6 +13,7 @@ import { EggHatchData } from "#app/data/egg-hatch-data.js"; export class EggLapsePhase extends Phase { private eggHatchData: EggHatchData[] = []; + private loadsWaiting: number; constructor(scene: BattleScene) { super(scene); } @@ -28,6 +29,7 @@ export class EggLapsePhase extends Phase { this.eggHatchData= []; const minEggsToPromptSkip = 5; + this.loadsWaiting = eggsToHatch.length; if (eggsToHatchCount > 0) { @@ -40,18 +42,13 @@ export class EggLapsePhase extends Phase { for (const egg of eggsToHatch) { this.hatchEggSilently(egg); } - console.timeEnd("hatch eggs"); - - this.scene.unshiftPhase(new EggSummaryPhase(this.scene, this.eggHatchData)); - this.end(); }, () => { for (const egg of eggsToHatch) { this.scene.unshiftPhase(new EggHatchPhase(this.scene, this, egg, eggsToHatchCount)); eggsToHatchCount--; } + this.showSummary(); - this.scene.unshiftPhase(new EggSummaryPhase(this.scene, this.eggHatchData)); - this.end(); } ); }, 100, true); @@ -69,6 +66,11 @@ export class EggLapsePhase extends Phase { } } + showSummary() { + this.scene.unshiftPhase(new EggSummaryPhase(this.scene, this.eggHatchData)); + this.end(); + } + /** * 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 @@ -77,6 +79,7 @@ export class EggLapsePhase extends Phase { */ hatchEggSilently(egg: Egg) { const eggIndex = this.scene.gameData.eggs.findIndex(e => e.id === egg.id); + const eggsRemaining = this.scene.gameData.eggs.length; if (eggIndex === -1) { return this.end(); } @@ -88,7 +91,16 @@ export class EggLapsePhase extends Phase { pokemon.clearFusionSpecies(); } + console.time("loading assets " + pokemon.name + " " + eggsRemaining); pokemon.loadAssets().then(() => { + this.loadsWaiting--; + console.log(this.loadsWaiting); + console.timeEnd("loading assets " + pokemon.name + " " + eggsRemaining); + + if (this.loadsWaiting === 0) { + console.timeEnd("hatch eggs"); + this.showSummary(); + } if (pokemon.species.subLegendary) { this.scene.validateAchv(achvs.HATCH_SUB_LEGENDARY); @@ -102,7 +114,6 @@ export class EggLapsePhase extends Phase { if (pokemon.isShiny()) { this.scene.validateAchv(achvs.HATCH_SHINY); } - }); } diff --git a/src/ui/egg-summary-ui-handler.ts b/src/ui/egg-summary-ui-handler.ts index 4350a47523c..f5b032e0d1d 100644 --- a/src/ui/egg-summary-ui-handler.ts +++ b/src/ui/egg-summary-ui-handler.ts @@ -296,7 +296,6 @@ export default class EggSummaryUiHandler extends MessageUiHandler { const lastCursor = this.cursor; changed = super.setCursor(cursor); - this.infoContainer.interruptDisplay(); if (changed) { this.cursorObj.setPosition(114 + 18 * (cursor % 11), 10 + 18 * Math.floor(cursor / 11)); diff --git a/src/ui/pokemon-hatch-info-container.ts b/src/ui/pokemon-hatch-info-container.ts index 68714d0d854..0984bdf9dcb 100644 --- a/src/ui/pokemon-hatch-info-container.ts +++ b/src/ui/pokemon-hatch-info-container.ts @@ -3,7 +3,6 @@ import PokemonInfoContainer from "./pokemon-info-container"; import BattleScene from "../battle-scene"; import { Gender } from "../data/gender"; import { Type } from "../data/type"; -import i18next from "i18next"; import * as Utils from "../utils"; import { TextStyle, addTextObject } from "./text"; import { speciesEggMoves } from "#app/data/egg-moves.js"; @@ -33,7 +32,6 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { private pokemonCandyIcon: Phaser.GameObjects.Sprite; private pokemonCandyOverlayIcon: Phaser.GameObjects.Sprite; private pokemonCandyCountText: Phaser.GameObjects.Text; - private assetLoadCancelled: Utils.BooleanHolder | null; constructor(scene: BattleScene, listContainer : Phaser.GameObjects.Container, x: number = 115, y: number = 9,) { super(scene, x, y); @@ -74,7 +72,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.pokemonCandyOverlayIcon.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonCandyOverlayIcon); - this.pokemonCandyCountText = addTextObject(this.scene, 14, 40, "x0", TextStyle.WINDOW_ALT, { fontSize: "56px" }); + this.pokemonCandyCountText = addTextObject(this.scene, 14, 40, "x0", TextStyle.SUMMARY, { fontSize: "56px" }); this.pokemonCandyCountText.setOrigin(0, 0); this.pokemonListContainer.add(this.pokemonCandyCountText); @@ -86,11 +84,6 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.pokemonEggMovesContainer.setVisible(false); this.pokemonEggMovesContainer.setScale(0.5); - const eggMovesLabel = addTextObject(this.scene, 70, 0, i18next.t("starterSelectUiHandler:eggMoves"), TextStyle.WINDOW_ALT); - eggMovesLabel.setOrigin(0.5, 0); - - this.pokemonEggMovesContainer.add(eggMovesLabel); - for (let m = 0; m < 4; m++) { const eggMoveContainer = this.scene.add.container(0, 0 + 6 * m); @@ -123,15 +116,9 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { this.currentPokemonSprite.setVisible(false); } - interruptDisplay() { - if (this.assetLoadCancelled) { - this.assetLoadCancelled.value = true; - this.assetLoadCancelled = null; - } - } - /** * Display a given pokemon sprite with animations + * @precondition the specific pokemon sprite has already been loaded */ displayPokemon(pokemon: PlayerPokemon) { console.time("display pokemon" + pokemon.name); @@ -141,27 +128,14 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer { const formIndex = pokemon.formIndex; const shiny = pokemon.shiny; const variant = pokemon.variant; - const assetLoadCancelled = new Utils.BooleanHolder(false); - this.assetLoadCancelled = assetLoadCancelled; - // species.loadAssets(this.scene, female, formIndex, shiny, variant, true).then(() => { - if (assetLoadCancelled.value) { - console.log("interrupted"); - console.timeEnd("display pokemon" + pokemon.name); - return; - } - this.assetLoadCancelled = null; - // this.speciesLoaded.set(species.speciesId, true); - // redundant setVisible(true) but makes sure sprite is only visible after being rendered (no substitute visible) - this.currentPokemonSprite.setVisible(true); getPokemonSpeciesForm(species.speciesId, pokemon.formIndex).cry(this.scene); this.currentPokemonSprite.play(species.getSpriteKey(female, formIndex, shiny, variant)); this.currentPokemonSprite.setPipelineData("shiny", shiny); this.currentPokemonSprite.setPipelineData("variant", variant); this.currentPokemonSprite.setPipelineData("spriteKey", species.getSpriteKey(female, formIndex, shiny, variant)); + this.currentPokemonSprite.setVisible(true); console.timeEnd("display pokemon" + pokemon.name); - // this.pokemonSprite.setVisible(!this.statsMode); - // }); } /**