pokerogue/src/phases/egg-summary-phase.ts
Sirz Benjie 344e9463cc
[Bug] Fix memory leak in egg hatch (#6511)
Co-authored-by: MokaStitcher <54149968+MokaStitcher@users.noreply.github.com>
2025-09-07 17:05:25 -05:00

52 lines
1.5 KiB
TypeScript

import { globalScene } from "#app/global-scene";
import { Phase } from "#app/phase";
import type { EggHatchData } from "#data/egg-hatch-data";
import { UiMode } from "#enums/ui-mode";
/**
* 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 {
public readonly phaseName = "EggSummaryPhase";
private eggHatchData: EggHatchData[];
constructor(eggHatchData: EggHatchData[]) {
super();
this.eggHatchData = eggHatchData;
}
start() {
super.start();
// updates next pokemon once the current update has been completed
const updateNextPokemon = (i: number) => {
if (i >= this.eggHatchData.length) {
globalScene.ui.setModeForceTransition(UiMode.EGG_HATCH_SUMMARY, this.eggHatchData).then(() => {
globalScene.fadeOutBgm(undefined, false);
});
} else {
this.eggHatchData[i].setDex();
this.eggHatchData[i].updatePokemon().then(() => {
if (i < this.eggHatchData.length) {
updateNextPokemon(i + 1);
}
});
}
};
updateNextPokemon(0);
}
end() {
this.eggHatchData.forEach(data => {
data.pokemon?.destroy();
});
this.eggHatchData = [];
globalScene.time.delayedCall(250, () => globalScene.setModifiersVisible(true));
globalScene.ui.setModeForceTransition(UiMode.MESSAGE).then(() => {
super.end();
});
}
}