Implement solution to data loss issue
parent
02f86d41b2
commit
09e7fab141
|
@ -73,7 +73,7 @@ export class LoginPhase extends BattlePhase {
|
||||||
this.scene.playSound('menu_open');
|
this.scene.playSound('menu_open');
|
||||||
|
|
||||||
const loadData = () => {
|
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, {
|
this.scene.ui.setMode(Mode.LOGIN_FORM, {
|
||||||
|
@ -98,14 +98,25 @@ export class LoginPhase extends BattlePhase {
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
} else
|
} else {
|
||||||
this.end();
|
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 {
|
end(): void {
|
||||||
this.scene.ui.setMode(Mode.MESSAGE);
|
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());
|
handleTutorial(this.scene, Tutorial.Intro).then(() => super.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -591,8 +591,6 @@ export default class BattleScene extends Phaser.Scene {
|
||||||
this.pushPhase(new LoginPhase(this));
|
this.pushPhase(new LoginPhase(this));
|
||||||
if (!bypassLogin)
|
if (!bypassLogin)
|
||||||
this.pushPhase(new ConsolidateDataPhase(this)); // TODO: Remove
|
this.pushPhase(new ConsolidateDataPhase(this)); // TODO: Remove
|
||||||
if (!this.gameData.gender)
|
|
||||||
this.pushPhase(new SelectGenderPhase(this));
|
|
||||||
this.pushPhase(new CheckLoadPhase(this));
|
this.pushPhase(new CheckLoadPhase(this));
|
||||||
} else
|
} else
|
||||||
this.pushPhase(new EncounterPhase(this));
|
this.pushPhase(new EncounterPhase(this));
|
||||||
|
|
|
@ -189,7 +189,6 @@ export class GameData {
|
||||||
};
|
};
|
||||||
this.eggs = [];
|
this.eggs = [];
|
||||||
this.initDexData();
|
this.initDexData();
|
||||||
this.loadSystem();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveSystem(): Promise<boolean> {
|
public saveSystem(): Promise<boolean> {
|
||||||
|
@ -242,66 +241,71 @@ export class GameData {
|
||||||
public loadSystem(): Promise<boolean> {
|
public loadSystem(): Promise<boolean> {
|
||||||
return new Promise<boolean>(resolve => {
|
return new Promise<boolean>(resolve => {
|
||||||
if (bypassLogin && !localStorage.hasOwnProperty('data'))
|
if (bypassLogin && !localStorage.hasOwnProperty('data'))
|
||||||
return false;
|
return resolve(false);
|
||||||
|
|
||||||
const handleSystemData = (systemDataStr: string) => {
|
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' ];
|
/*const versions = [ this.scene.game.config.gameVersion, data.gameVersion || '0.0.0' ];
|
||||||
|
|
||||||
if (versions[0] !== versions[1]) {
|
if (versions[0] !== versions[1]) {
|
||||||
const [ versionNumbers, oldVersionNumbers ] = versions.map(ver => ver.split('.').map(v => parseInt(v)));
|
const [ versionNumbers, oldVersionNumbers ] = versions.map(ver => ver.split('.').map(v => parseInt(v)));
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
this.trainerId = systemData.trainerId;
|
this.trainerId = systemData.trainerId;
|
||||||
this.secretId = systemData.secretId;
|
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)
|
if (systemData.gameStats)
|
||||||
this.gameStats = systemData.gameStats;
|
this.gameStats = systemData.gameStats;
|
||||||
|
|
||||||
if (systemData.unlocks) {
|
if (systemData.unlocks) {
|
||||||
for (let key of Object.keys(systemData.unlocks)) {
|
for (let key of Object.keys(systemData.unlocks)) {
|
||||||
if (this.unlocks.hasOwnProperty(key))
|
if (this.unlocks.hasOwnProperty(key))
|
||||||
this.unlocks[key] = systemData.unlocks[key];
|
this.unlocks[key] = systemData.unlocks[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (systemData.achvUnlocks) {
|
if (systemData.achvUnlocks) {
|
||||||
for (let a of Object.keys(systemData.achvUnlocks)) {
|
for (let a of Object.keys(systemData.achvUnlocks)) {
|
||||||
if (achvs.hasOwnProperty(a))
|
if (achvs.hasOwnProperty(a))
|
||||||
this.achvUnlocks[a] = systemData.achvUnlocks[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.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) {
|
if (!bypassLogin) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import MessageUiHandler from "./message-ui-handler";
|
||||||
import { GameDataType } from "../system/game-data";
|
import { GameDataType } from "../system/game-data";
|
||||||
import { OptionSelectConfig } from "./abstact-option-select-ui-handler";
|
import { OptionSelectConfig } from "./abstact-option-select-ui-handler";
|
||||||
import { Tutorial, handleTutorial } from "../tutorial";
|
import { Tutorial, handleTutorial } from "../tutorial";
|
||||||
|
import { updateUserInfo } from "../account";
|
||||||
|
|
||||||
export enum MenuOptions {
|
export enum MenuOptions {
|
||||||
GAME_SETTINGS,
|
GAME_SETTINGS,
|
||||||
|
@ -220,7 +221,7 @@ export default class MenuUiHandler extends MessageUiHandler {
|
||||||
if (!res.ok)
|
if (!res.ok)
|
||||||
console.error(`Log out failed (${res.status}: ${res.statusText})`);
|
console.error(`Log out failed (${res.status}: ${res.statusText})`);
|
||||||
Utils.setCookie(Utils.sessionIdKey, '');
|
Utils.setCookie(Utils.sessionIdKey, '');
|
||||||
this.scene.reset(true);
|
updateUserInfo().then(() => this.scene.reset(true));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (this.scene.currentBattle) {
|
if (this.scene.currentBattle) {
|
||||||
|
|
Loading…
Reference in New Issue