Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[P1] Fix wrong local save being deleted when creating a new run #4598

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/system/game-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,10 +1125,16 @@ export class GameData {
});
}

/**
* Delete the session data at the given slot when overwriting a save file
* For deleting the session of a finished run, use {@linkcode tryClearSession}
* @param slotId the slot to clear
* @returns Promise with result `true` if the session was deleted successfully, `false` otherwise
*/
deleteSession(slotId: integer): Promise<boolean> {
return new Promise<boolean>(resolve => {
if (bypassLogin) {
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser?.username}`);
localStorage.removeItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`);
return resolve(true);
}

Expand All @@ -1139,7 +1145,7 @@ export class GameData {
Utils.apiFetch(`savedata/session/delete?slot=${slotId}&clientSessionId=${clientSessionId}`, true).then(response => {
if (response.ok) {
loggedInUser!.lastSessionSlot = -1; // TODO: is the bang correct?
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser?.username}`);
localStorage.removeItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`);
resolve(true);
}
return response.text();
Expand Down Expand Up @@ -1190,7 +1196,9 @@ export class GameData {


/**
* Attempt to clear session data. After session data is removed, attempt to update user info so the menu updates
* Attempt to clear session data after the end of a run
* After session data is removed, attempt to update user info so the menu updates
* To delete an unfinished run instead, use {@linkcode deleteSession}
*/
async tryClearSession(scene: BattleScene, slotId: integer): Promise<[success: boolean, newClear: boolean]> {
let result: [boolean, boolean] = [ false, false ];
Expand All @@ -1204,7 +1212,7 @@ export class GameData {

if (response.ok) {
loggedInUser!.lastSessionSlot = -1; // TODO: is the bang correct?
localStorage.removeItem(`sessionData${this.scene.sessionSlotId ? this.scene.sessionSlotId : ""}_${loggedInUser?.username}`);
localStorage.removeItem(`sessionData${slotId ? slotId : ""}_${loggedInUser?.username}`);
}

const jsonResponse: PokerogueApiClearSessionData = await response.json();
Expand Down
Loading