Implement solution to data loss issue

pull/16/head
Flashfyre 2024-02-19 20:36:10 -05:00
parent 02f86d41b2
commit 09e7fab141
4 changed files with 68 additions and 54 deletions

View File

@ -73,7 +73,7 @@ export class LoginPhase extends BattlePhase {
this.scene.playSound('menu_open');
const loadData = () => {
this.scene.gameData.loadSystem().then(() => this.end());
updateUserInfo().then(() => this.scene.gameData.loadSystem().then(() => this.end()));
};
this.scene.ui.setMode(Mode.LOGIN_FORM, {
@ -98,14 +98,25 @@ export class LoginPhase extends BattlePhase {
]
});
return null;
} else
} else {
this.scene.gameData.loadSystem().then(success => {
if (success)
this.end();
else {
this.scene.ui.setMode(Mode.MESSAGE);
this.scene.ui.showText('Failed to load save data. Please reload the page.\nIf this continues, please contact the administrator.');
}
});
}
});
}
end(): void {
this.scene.ui.setMode(Mode.MESSAGE);
if (!this.scene.gameData.gender)
this.scene.unshiftPhase(new SelectGenderPhase(this.scene));
handleTutorial(this.scene, Tutorial.Intro).then(() => super.end());
}
}

View File

@ -591,8 +591,6 @@ export default class BattleScene extends Phaser.Scene {
this.pushPhase(new LoginPhase(this));
if (!bypassLogin)
this.pushPhase(new ConsolidateDataPhase(this)); // TODO: Remove
if (!this.gameData.gender)
this.pushPhase(new SelectGenderPhase(this));
this.pushPhase(new CheckLoadPhase(this));
} else
this.pushPhase(new EncounterPhase(this));

View File

@ -189,7 +189,6 @@ export class GameData {
};
this.eggs = [];
this.initDexData();
this.loadSystem();
}
public saveSystem(): Promise<boolean> {
@ -242,9 +241,10 @@ export class GameData {
public loadSystem(): Promise<boolean> {
return new Promise<boolean>(resolve => {
if (bypassLogin && !localStorage.hasOwnProperty('data'))
return false;
return resolve(false);
const handleSystemData = (systemDataStr: string) => {
try {
const systemData = this.parseSystemData(systemDataStr);
console.debug(systemData);
@ -302,6 +302,10 @@ export class GameData {
this.defaultDexData = null;
resolve(true);
} catch (err) {
console.error(err);
resolve(false);
}
}
if (!bypassLogin) {

View File

@ -7,6 +7,7 @@ import MessageUiHandler from "./message-ui-handler";
import { GameDataType } from "../system/game-data";
import { OptionSelectConfig } from "./abstact-option-select-ui-handler";
import { Tutorial, handleTutorial } from "../tutorial";
import { updateUserInfo } from "../account";
export enum MenuOptions {
GAME_SETTINGS,
@ -220,7 +221,7 @@ export default class MenuUiHandler extends MessageUiHandler {
if (!res.ok)
console.error(`Log out failed (${res.status}: ${res.statusText})`);
Utils.setCookie(Utils.sessionIdKey, '');
this.scene.reset(true);
updateUserInfo().then(() => this.scene.reset(true));
});
};
if (this.scene.currentBattle) {