2024-09-07 21:37:37 -07:00
|
|
|
import BattleScene from "#app/battle-scene";
|
|
|
|
import { Phase } from "#app/phase";
|
2024-08-19 03:23:52 +01:00
|
|
|
import { EndCardPhase } from "./end-card-phase";
|
|
|
|
import { TitlePhase } from "./title-phase";
|
|
|
|
|
|
|
|
export class PostGameOverPhase extends Phase {
|
|
|
|
private endCardPhase: EndCardPhase | null;
|
|
|
|
|
|
|
|
constructor(scene: BattleScene, endCardPhase?: EndCardPhase) {
|
|
|
|
super(scene);
|
|
|
|
|
|
|
|
this.endCardPhase = endCardPhase!; // TODO: is this bang correct?
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
super.start();
|
|
|
|
|
|
|
|
const saveAndReset = () => {
|
|
|
|
this.scene.gameData.saveAll(this.scene, true, true, true).then(success => {
|
|
|
|
if (!success) {
|
|
|
|
return this.scene.reset(true);
|
|
|
|
}
|
|
|
|
this.scene.gameData.tryClearSession(this.scene, this.scene.sessionSlotId).then((success: boolean | [boolean, boolean]) => {
|
|
|
|
if (!success[0]) {
|
|
|
|
return this.scene.reset(true);
|
|
|
|
}
|
|
|
|
this.scene.reset();
|
|
|
|
this.scene.unshiftPhase(new TitlePhase(this.scene));
|
|
|
|
this.end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.endCardPhase) {
|
|
|
|
this.scene.ui.fadeOut(500).then(() => {
|
|
|
|
this.scene.ui.getMessageHandler().bg.setVisible(true);
|
|
|
|
|
|
|
|
this.endCardPhase?.endCard.destroy();
|
|
|
|
this.endCardPhase?.text.destroy();
|
|
|
|
saveAndReset();
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
saveAndReset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|