Compare commits

...

4 Commits

Author SHA1 Message Date
James Diefenbach
2535f0ab67 more time logs and fix pre-load issues 2024-08-31 13:18:57 +10:00
James Diefenbach
c9d05daad1 skip redundant load 2024-08-31 12:02:01 +10:00
James Diefenbach
aaec973af3 Merge branch 'egg-summary-2' of https://github.com/j-diefenbach/pokerogue_tinylad-fork into egg-summary-2 2024-08-31 11:52:40 +10:00
James Diefenbach
ab5f252f16 time logging and optimisation 2024-08-31 11:51:40 +10:00
5 changed files with 37 additions and 51 deletions

View File

@ -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) {
@ -36,20 +38,17 @@ export class EggLapsePhase extends Phase {
// show prompt for skip
this.scene.ui.showText(i18next.t("battle:eggSkipPrompt"), 0);
this.scene.ui.setModeWithoutClear(Mode.CONFIRM, () => {
console.time("hatch eggs");
for (const egg of eggsToHatch) {
this.hatchEggSilently(egg);
}
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);
@ -62,14 +61,16 @@ export class EggLapsePhase extends Phase {
}
this.end();
}
console.log(this.eggHatchData);
} else {
this.end();
}
}
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
@ -78,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,9 +90,17 @@ export class EggLapsePhase extends Phase {
if (pokemon.fusionSpecies) {
pokemon.clearFusionSpecies();
}
console.log(pokemon);
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);
@ -104,7 +114,6 @@ export class EggLapsePhase extends Phase {
if (pokemon.isShiny()) {
this.scene.validateAchv(achvs.HATCH_SHINY);
}
});
}

View File

@ -21,11 +21,12 @@ export class EggSummaryPhase extends Phase {
start() {
super.start();
console.time("update egg dex");
const updateNextPokemon = (i: integer) => {
console.log(i);
if (i >= this.eggHatchData.length) {
console.log("displayed all pokemon");
console.timeEnd("update egg dex");
this.scene.ui.setModeForceTransition(Mode.EGG_HATCH_SUMMARY, this.eggHatchData).then(() => {
this.scene.fadeOutBgm(undefined, false);
this.eggHatchHandler = this.scene.ui.getHandler() as EggHatchSceneHandler;
@ -35,7 +36,6 @@ export class EggSummaryPhase extends Phase {
} else {
this.eggHatchData[i].setDex();
this.eggHatchData[i].updatePokemon().then(() => {
console.log("updating next pokemon");
if (i < this.eggHatchData.length) {
updateNextPokemon(i + 1);
}

View File

@ -1618,12 +1618,10 @@ export class GameData {
}
const checkPrevolution = () => {
console.log("checking prevolution");
if (hasPrevolution) {
const prevolutionSpecies = pokemonPrevolutions[species.speciesId];
this.setPokemonSpeciesCaught(pokemon, getPokemonSpecies(prevolutionSpecies), incrementCount, fromEgg, showMessage).then(() => resolve());
} else {
console.log("resolving");
resolve();
}
};

View File

@ -156,6 +156,7 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
this.eggHatchBg.setVisible(true);
this.infoContainer.hideDisplayPokemon();
console.time("display icons");
this.eggHatchData.forEach( (value: EggHatchData, i: number) => {
const x = (i % 11) * 18;
@ -229,6 +230,8 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
em.setVisible(value.eggMoveUnlocked);
this.pokemonIconsContainer.add(em);
});
console.timeEnd("display icons");
this.setCursor(0);
// TODO nice animation reveal for all eggs hatching at once
@ -242,7 +245,6 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
let success = false;
const error = false;
console.log("egg handler button " + button);
if (button === Button.CANCEL) {
const phase = this.scene.getCurrentPhase();
if (phase instanceof EggSummaryPhase) {
@ -294,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));

View File

@ -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,42 +116,26 @@ 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);
console.log("displaying pokemon", pokemon.name);
const species = pokemon.species;
const female = pokemon.gender === Gender.FEMALE;
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");
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.pokemonSprite.setVisible(!this.statsMode);
});
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);
}
/**
@ -167,7 +144,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer {
* @param hatchInfo The EggHatchData of the pokemon / new hatch to show
*/
showHatchInfo(hatchInfo: EggHatchData) {
console.log("showing hatch info", hatchInfo.pokemon.name);
console.time("show hatch info" + hatchInfo.pokemon.name);
this.pokemonEggMovesContainer.setVisible(true);
const pokemon = hatchInfo.pokemon;
@ -208,6 +185,7 @@ export default class PokemonHatchInfoContainer extends PokemonInfoContainer {
} else {
this.pokemonHatchedIcon.setFrame(getEggTierForSpecies(species));
}
console.timeEnd("show hatch info" + hatchInfo.pokemon.name);
}