Fix game not loading if save data is not found

This commit is contained in:
Flashfyre 2024-04-01 15:18:15 -04:00
parent e6c7f5dc77
commit a3e09ee5cc
3 changed files with 5 additions and 50 deletions

View File

@ -685,8 +685,6 @@ export default class BattleScene extends Phaser.Scene {
initMoveAnim(Moves.STRUGGLE).then(() => loadMoveAnimAssets(this, [ Moves.STRUGGLE ], true)) initMoveAnim(Moves.STRUGGLE).then(() => loadMoveAnimAssets(this, [ Moves.STRUGGLE ], true))
]).then(() => { ]).then(() => {
this.pushPhase(new LoginPhase(this)); this.pushPhase(new LoginPhase(this));
if (!bypassLogin)
this.pushPhase(new ConsolidateDataPhase(this)); // TODO: Remove
this.pushPhase(new TitlePhase(this)); this.pushPhase(new TitlePhase(this));
this.shiftPhase(); this.shiftPhase();

View File

@ -92,7 +92,7 @@ export class LoginPhase extends Phase {
buttonActions: [ buttonActions: [
() => { () => {
this.scene.ui.playSelect(); this.scene.ui.playSelect();
loadData(); updateUserInfo().then(() => this.end());
}, () => { }, () => {
this.scene.unshiftPhase(new LoginPhase(this.scene, false)); this.scene.unshiftPhase(new LoginPhase(this.scene, false));
this.end(); this.end();
@ -300,53 +300,6 @@ export class TitlePhase extends Phase {
} }
} }
// TODO: Remove
export class ConsolidateDataPhase extends Phase {
start(): void {
super.start();
Utils.apiFetch(`savedata/get?datatype=${GameDataType.SYSTEM}`)
.then(response => response.text())
.then(response => {
if (!response.length || response[0] !== '{') {
console.log('System data not found: Loading legacy local system data');
const systemDataStr = atob(localStorage.getItem('data'));
Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}`, systemDataStr)
.then(response => response.text())
.then(error => {
if (error) {
console.error(error);
return this.end();
}
Utils.apiFetch(`savedata/get?datatype=${GameDataType.SESSION}`)
.then(response => response.text())
.then(response => {
if (!response.length || response[0] !== '{') {
console.log('Session data not found: Loading legacy local session data');
const sessionDataStr = atob(localStorage.getItem('sessionData'));
Utils.apiPost(`savedata/update?datatype=${GameDataType.SESSION}`, sessionDataStr)
.then(response => response.text())
.then(error => {
if (error)
console.error(error);
window.location = window.location;
});
} else
window.location = window.location;
});
});
} else
this.end();
});
}
}
export class SelectGenderPhase extends Phase { export class SelectGenderPhase extends Phase {
constructor(scene: BattleScene) { constructor(scene: BattleScene) {
super(scene); super(scene);

View File

@ -354,6 +354,10 @@ export class GameData {
.then(response => response.text()) .then(response => response.text())
.then(response => { .then(response => {
if (!response.length || response[0] !== '{') { if (!response.length || response[0] !== '{') {
if (response.startsWith('failed to read save file')) {
this.scene.queueMessage('Save data could not be found. If this is a new account, you can safely ignore this message.', null, true);
return resolve(true);
}
console.error(response); console.error(response);
return resolve(false); return resolve(false);
} }