Add local data clears where applicable

This commit is contained in:
Flashfyre 2024-05-15 00:11:41 -04:00
parent 9a965055b1
commit 7c45da4a01
2 changed files with 11 additions and 8 deletions

View File

@ -414,6 +414,8 @@ export class ReloadSessionPhase extends Phase {
delayElapsed = true; delayElapsed = true;
}); });
this.scene.gameData.clearLocalData();
(this.systemDataStr ? this.scene.gameData.initSystem(this.systemDataStr) : this.scene.gameData.loadSystem()).then(() => { (this.systemDataStr ? this.scene.gameData.initSystem(this.systemDataStr) : this.scene.gameData.loadSystem()).then(() => {
if (delayElapsed) if (delayElapsed)
this.end(); this.end();

View File

@ -359,11 +359,8 @@ export class GameData {
if (cachedSystemData.timestamp > systemData.timestamp) { if (cachedSystemData.timestamp > systemData.timestamp) {
console.debug('Use cached system'); console.debug('Use cached system');
systemData = cachedSystemData; systemData = cachedSystemData;
} else { } else
localStorage.removeItem(`data_${loggedInUser.username}`); this.clearLocalData();
for (let s = 0; s < 5; s++)
localStorage.removeItem(`sessionData${s ? s : ''}_${loggedInUser.username}`);
}
} }
console.debug(systemData); console.debug(systemData);
@ -512,15 +509,19 @@ export class GameData {
if (!response.valid) { if (!response.valid) {
this.scene.clearPhaseQueue(); this.scene.clearPhaseQueue();
this.scene.unshiftPhase(new ReloadSessionPhase(this.scene, JSON.stringify(response.systemData))); this.scene.unshiftPhase(new ReloadSessionPhase(this.scene, JSON.stringify(response.systemData)));
localStorage.removeItem(`data_${loggedInUser.username}`); this.clearLocalData();
for (let s = 0; s < 5; s++)
localStorage.removeItem(`sessionData${s ? s : ''}_${loggedInUser.username}`);
return false; return false;
} }
return true; return true;
} }
public clearLocalData(): void {
localStorage.removeItem(`data_${loggedInUser.username}`);
for (let s = 0; s < 5; s++)
localStorage.removeItem(`sessionData${s ? s : ''}_${loggedInUser.username}`);
}
public saveSetting(setting: Setting, valueIndex: integer): boolean { public saveSetting(setting: Setting, valueIndex: integer): boolean {
let settings: object = {}; let settings: object = {};
if (localStorage.hasOwnProperty('settings')) if (localStorage.hasOwnProperty('settings'))