Implement solution to data loss issue
parent
02f86d41b2
commit
09e7fab141
|
@ -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
|
||||
this.end();
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -189,7 +189,6 @@ export class GameData {
|
|||
};
|
||||
this.eggs = [];
|
||||
this.initDexData();
|
||||
this.loadSystem();
|
||||
}
|
||||
|
||||
public saveSystem(): Promise<boolean> {
|
||||
|
@ -242,66 +241,71 @@ 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) => {
|
||||
const systemData = this.parseSystemData(systemDataStr);
|
||||
try {
|
||||
const systemData = this.parseSystemData(systemDataStr);
|
||||
|
||||
console.debug(systemData);
|
||||
console.debug(systemData);
|
||||
|
||||
/*const versions = [ this.scene.game.config.gameVersion, data.gameVersion || '0.0.0' ];
|
||||
|
||||
if (versions[0] !== versions[1]) {
|
||||
const [ versionNumbers, oldVersionNumbers ] = versions.map(ver => ver.split('.').map(v => parseInt(v)));
|
||||
}*/
|
||||
/*const versions = [ this.scene.game.config.gameVersion, data.gameVersion || '0.0.0' ];
|
||||
|
||||
if (versions[0] !== versions[1]) {
|
||||
const [ versionNumbers, oldVersionNumbers ] = versions.map(ver => ver.split('.').map(v => parseInt(v)));
|
||||
}*/
|
||||
|
||||
this.trainerId = systemData.trainerId;
|
||||
this.secretId = systemData.secretId;
|
||||
this.trainerId = systemData.trainerId;
|
||||
this.secretId = systemData.secretId;
|
||||
|
||||
this.gender = systemData.gender;
|
||||
this.gender = systemData.gender;
|
||||
|
||||
this.saveSetting(Setting.Player_Gender, systemData.gender === PlayerGender.FEMALE ? 1 : 0);
|
||||
this.saveSetting(Setting.Player_Gender, systemData.gender === PlayerGender.FEMALE ? 1 : 0);
|
||||
|
||||
if (systemData.gameStats)
|
||||
this.gameStats = systemData.gameStats;
|
||||
if (systemData.gameStats)
|
||||
this.gameStats = systemData.gameStats;
|
||||
|
||||
if (systemData.unlocks) {
|
||||
for (let key of Object.keys(systemData.unlocks)) {
|
||||
if (this.unlocks.hasOwnProperty(key))
|
||||
this.unlocks[key] = systemData.unlocks[key];
|
||||
if (systemData.unlocks) {
|
||||
for (let key of Object.keys(systemData.unlocks)) {
|
||||
if (this.unlocks.hasOwnProperty(key))
|
||||
this.unlocks[key] = systemData.unlocks[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (systemData.achvUnlocks) {
|
||||
for (let a of Object.keys(systemData.achvUnlocks)) {
|
||||
if (achvs.hasOwnProperty(a))
|
||||
this.achvUnlocks[a] = systemData.achvUnlocks[a];
|
||||
}
|
||||
}
|
||||
|
||||
if (systemData.voucherUnlocks) {
|
||||
for (let v of Object.keys(systemData.voucherUnlocks)) {
|
||||
if (vouchers.hasOwnProperty(v))
|
||||
this.voucherUnlocks[v] = systemData.voucherUnlocks[v];
|
||||
if (systemData.achvUnlocks) {
|
||||
for (let a of Object.keys(systemData.achvUnlocks)) {
|
||||
if (achvs.hasOwnProperty(a))
|
||||
this.achvUnlocks[a] = systemData.achvUnlocks[a];
|
||||
}
|
||||
}
|
||||
|
||||
if (systemData.voucherUnlocks) {
|
||||
for (let v of Object.keys(systemData.voucherUnlocks)) {
|
||||
if (vouchers.hasOwnProperty(v))
|
||||
this.voucherUnlocks[v] = systemData.voucherUnlocks[v];
|
||||
}
|
||||
}
|
||||
|
||||
if (systemData.voucherCounts) {
|
||||
Utils.getEnumKeys(VoucherType).forEach(key => {
|
||||
const index = VoucherType[key];
|
||||
this.voucherCounts[index] = systemData.voucherCounts[index] || 0;
|
||||
});
|
||||
}
|
||||
|
||||
this.eggs = systemData.eggs
|
||||
? systemData.eggs.map(e => e.toEgg())
|
||||
: [];
|
||||
|
||||
this.dexData = Object.assign(this.dexData, systemData.dexData);
|
||||
this.consolidateDexData(this.dexData);
|
||||
this.defaultDexData = null;
|
||||
|
||||
resolve(true);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
resolve(false);
|
||||
}
|
||||
|
||||
if (systemData.voucherCounts) {
|
||||
Utils.getEnumKeys(VoucherType).forEach(key => {
|
||||
const index = VoucherType[key];
|
||||
this.voucherCounts[index] = systemData.voucherCounts[index] || 0;
|
||||
});
|
||||
}
|
||||
|
||||
this.eggs = systemData.eggs
|
||||
? systemData.eggs.map(e => e.toEgg())
|
||||
: [];
|
||||
|
||||
this.dexData = Object.assign(this.dexData, systemData.dexData);
|
||||
this.consolidateDexData(this.dexData);
|
||||
this.defaultDexData = null;
|
||||
|
||||
resolve(true);
|
||||
}
|
||||
|
||||
if (!bypassLogin) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue