pull/381/merge
MonsieurDMA 2024-05-07 09:22:00 +02:00 committed by GitHub
commit fd3393f033
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 9 deletions

View File

@ -278,18 +278,23 @@ export class GameData {
Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}`, systemData, undefined, true) Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}`, systemData, undefined, true)
.then(response => response.text()) .then(response => response.text())
.then(error => { .then(error => {
this.scene.ui.savingIcon.hide();
if (error) { if (error) {
console.error(error);
if (error.startsWith('client version out of date')) { if (error.startsWith('client version out of date')) {
this.scene.ui.savingIcon.hide();
this.scene.clearPhaseQueue(); this.scene.clearPhaseQueue();
this.scene.unshiftPhase(new OutdatedPhase(this.scene)); this.scene.unshiftPhase(new OutdatedPhase(this.scene));
return resolve(false);
} else if (error.startsWith('session out of date')) { } else if (error.startsWith('session out of date')) {
this.scene.ui.savingIcon.hide();
this.scene.clearPhaseQueue(); this.scene.clearPhaseQueue();
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene)); this.scene.unshiftPhase(new ReloadSessionPhase(this.scene));
}
console.error(error);
return resolve(false); return resolve(false);
} }
console.log(`Retrying...`);
this.scene.ui.savingIcon.retry();
return this.saveSystem().then(resolve);
}
resolve(true); resolve(true);
}); });
} else { } else {
@ -564,13 +569,15 @@ export class GameData {
.then(response => response.text()) .then(response => response.text())
.then(error => { .then(error => {
if (error) { if (error) {
console.error(error);
if (error.startsWith('session out of date')) { if (error.startsWith('session out of date')) {
this.scene.clearPhaseQueue(); this.scene.clearPhaseQueue();
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene)); this.scene.unshiftPhase(new ReloadSessionPhase(this.scene));
}
console.error(error);
return resolve(false); return resolve(false);
} }
console.log(`Retrying...`);
return this.saveSession(this.scene, skipVerification).then(resolve);
}
console.debug('Session data saved'); console.debug('Session data saved');
resolve(true); resolve(true);
}); });

View File

@ -13,7 +13,7 @@ export default class SavingIconHandler extends Phaser.GameObjects.Container {
setup(): void { setup(): void {
this.icon = this.scene.add.sprite(0, 0, 'saving_icon'); this.icon = this.scene.add.sprite(0, 0, 'saving_icon');
this.icon.setOrigin(1, 1); this.icon.setOrigin(0.5, 0.5);
this.add(this.icon); this.add(this.icon);
@ -50,6 +50,24 @@ export default class SavingIconHandler extends Phaser.GameObjects.Container {
this.shown = true; this.shown = true;
} }
retry(): void {
this.setAlpha(1);
this.setVisible(true);
this.shown = true;
this.animActive = true;
this.scene.tweens.add({
targets: this,
rotation: 360,
repeat: Infinity,
duration: Utils.fixedInt(60000),
ease: 'Linear'
});
this.setVisible(true);
}
hide(): void { hide(): void {
this.shown = false; this.shown = false;

View File

@ -268,9 +268,24 @@ export function apiPost(path: string, data?: any, contentType: string = 'applica
if (sId) if (sId)
headers['Authorization'] = sId; headers['Authorization'] = sId;
} }
fetch(`${apiUrl}/${path}`, { method: 'POST', headers: headers, body: data })
.then(response => resolve(response)) const controller = new AbortController();
.catch(err => reject(err)); const signal = controller.signal;
const timeoutId = setTimeout(() => {
controller.abort();
reject(new Error('Request timed out'));
}, 8000);
fetch(`${apiUrl}/${path}`, { method: 'POST', headers: headers, body: data, signal })
.then(response => {
clearTimeout(timeoutId);
resolve(response);
})
.catch(err => {
clearTimeout(timeoutId);
reject(err);
});
}); });
} }