Add combined save between waves (#777)
parent
9a09d790f0
commit
2b9b63e3f3
|
@ -775,11 +775,11 @@ export class EncounterPhase extends BattlePhase {
|
|||
|
||||
this.scene.ui.setMode(Mode.MESSAGE).then(() => {
|
||||
if (!this.loaded) {
|
||||
this.scene.gameData.saveSystem().then(success => {
|
||||
this.scene.gameData.saveAll(this.scene, true).then(success => {
|
||||
this.scene.disableMenu = false;
|
||||
if (!success)
|
||||
return this.scene.reset(true);
|
||||
this.scene.gameData.saveSession(this.scene, true).then(() => this.doEncounter());
|
||||
this.doEncounter();
|
||||
});
|
||||
} else
|
||||
this.doEncounter();
|
||||
|
|
|
@ -250,10 +250,8 @@ export class GameData {
|
|||
this.initStarterData();
|
||||
}
|
||||
|
||||
public saveSystem(): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
this.scene.ui.savingIcon.show();
|
||||
const data: SystemSaveData = {
|
||||
public getSystemSaveData(): SystemSaveData {
|
||||
return {
|
||||
trainerId: this.trainerId,
|
||||
secretId: this.secretId,
|
||||
gender: this.gender,
|
||||
|
@ -268,6 +266,12 @@ export class GameData {
|
|||
gameVersion: this.scene.game.config.gameVersion,
|
||||
timestamp: new Date().getTime()
|
||||
};
|
||||
}
|
||||
|
||||
public saveSystem(): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
this.scene.ui.savingIcon.show();
|
||||
const data = this.getSystemSaveData();
|
||||
|
||||
const maxIntAttrValue = Math.pow(2, 31);
|
||||
const systemData = JSON.stringify(data, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v);
|
||||
|
@ -817,6 +821,59 @@ export class GameData {
|
|||
}) as SessionSaveData;
|
||||
}
|
||||
|
||||
saveAll(scene: BattleScene, skipVerification?: boolean): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
Utils.executeIf(!skipVerification, updateUserInfo).then(success => {
|
||||
if (success !== null && !success)
|
||||
return resolve(false);
|
||||
this.scene.ui.savingIcon.show();
|
||||
const data = this.getSystemSaveData();
|
||||
const sessionData = this.getSessionSaveData(scene);
|
||||
|
||||
const maxIntAttrValue = Math.pow(2, 31);
|
||||
const systemData = this.getSystemSaveData();
|
||||
|
||||
const request = {
|
||||
system: systemData,
|
||||
session: sessionData,
|
||||
sessionSlotId: scene.sessionSlotId
|
||||
};
|
||||
|
||||
if (!bypassLogin) {
|
||||
Utils.apiPost('savedata/updateall', JSON.stringify(request, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v), undefined, true)
|
||||
.then(response => response.text())
|
||||
.then(error => {
|
||||
this.scene.ui.savingIcon.hide();
|
||||
if (error) {
|
||||
if (error.startsWith('client version out of date')) {
|
||||
this.scene.clearPhaseQueue();
|
||||
this.scene.unshiftPhase(new OutdatedPhase(this.scene));
|
||||
} else if (error.startsWith('session out of date')) {
|
||||
this.scene.clearPhaseQueue();
|
||||
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene));
|
||||
}
|
||||
console.error(error);
|
||||
return resolve(false);
|
||||
}
|
||||
resolve(true);
|
||||
});
|
||||
} else {
|
||||
localStorage.setItem('data_bak', localStorage.getItem('data'));
|
||||
|
||||
localStorage.setItem('data', btoa(JSON.stringify(systemData, (k: any, v: any) => typeof v === 'bigint' ? v <= maxIntAttrValue ? Number(v) : v.toString() : v)));
|
||||
|
||||
localStorage.setItem(`sessionData${scene.sessionSlotId ? scene.sessionSlotId : ''}`, btoa(JSON.stringify(sessionData)));
|
||||
|
||||
console.debug('Session data saved');
|
||||
|
||||
this.scene.ui.savingIcon.hide();
|
||||
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public tryExportData(dataType: GameDataType, slotId: integer = 0): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
const dataKey: string = getDataTypeKey(dataType, slotId);
|
||||
|
|
Loading…
Reference in New Issue