diff --git a/src/battle-phases.ts b/src/battle-phases.ts index dd391c11788..da09732e2db 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -85,6 +85,12 @@ export class LoginPhase extends BattlePhase { this.end(); }); } + + end(): void { + this.scene.ui.setMode(Mode.MESSAGE); + + super.end(); + } } // TODO: Remove @@ -2592,20 +2598,20 @@ export class GameOverPhase extends BattlePhase { start() { super.start(); - this.scene.gameData.clearSession(); - - this.scene.time.delayedCall(1000, () => { - if (this.victory) - this.scene.validateAchv(achvs.CLASSIC_VICTORY); - const fadeDuration = this.victory ? 10000 : 5000; - this.scene.fadeOutBgm(fadeDuration, true); - this.scene.ui.fadeOut(fadeDuration).then(() => { - this.scene.clearPhaseQueue(); - this.scene.ui.clearText(); - this.handleUnlocks(this.scene.getParty()); - this.scene.reset(); - this.scene.unshiftPhase(new CheckLoadPhase(this.scene)); - this.end(); + this.scene.gameData.clearSession().then(() => { + this.scene.time.delayedCall(1000, () => { + if (this.victory) + this.scene.validateAchv(achvs.CLASSIC_VICTORY); + const fadeDuration = this.victory ? 10000 : 5000; + this.scene.fadeOutBgm(fadeDuration, true); + this.scene.ui.fadeOut(fadeDuration).then(() => { + this.scene.clearPhaseQueue(); + this.scene.ui.clearText(); + this.handleUnlocks(this.scene.getParty()); + this.scene.reset(); + this.scene.unshiftPhase(new CheckLoadPhase(this.scene)); + this.end(); + }); }); }); } diff --git a/src/system/game-data.ts b/src/system/game-data.ts index a773c8ab1f4..ca9b8d456d3 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -19,7 +19,7 @@ import { Egg } from "../data/egg"; import { VoucherType, vouchers } from "./voucher"; import { AES, enc } from "crypto-js"; import { Mode } from "../ui/ui"; -import { updateUserInfo } from "../account"; +import { loggedInUser, updateUserInfo } from "../account"; const saveKey = 'x0i2O7WRiANTqPmZ'; // Temporary; secure encryption is not yet necessary @@ -357,8 +357,6 @@ export class GameData { timestamp: new Date().getTime() } as SessionSaveData; - console.log(JSON.stringify(sessionData)); - if (!bypassLogin) { Utils.apiPost(`savedata/update?datatype=${GameDataType.SESSION}`, JSON.stringify(sessionData)) .then(response => response.text()) @@ -465,8 +463,6 @@ export class GameData { return resolve(false); } - console.log(JSON.parse(response)); - await handleSessionData(response); }); } else @@ -474,8 +470,25 @@ export class GameData { }); } - clearSession(): void { - localStorage.removeItem('sessionData'); + clearSession(): Promise { + return new Promise(resolve => { + if (bypassLogin) { + localStorage.removeItem('sessionData'); + return resolve(true); + } + + updateUserInfo().then(success => { + if (success !== null && !success) + return resolve(false); + Utils.apiFetch(`savedata/delete?datatype=${GameDataType.SESSION}`).then(response => { + if (response.ok) { + loggedInUser.hasGameSession = false; + return resolve(true); + } + resolve(false); + }); + }); + }); } parseSessionData(dataStr: string): SessionSaveData {