Skip to content

Commit 43f8b78

Browse files
authored
[Bug] Fix sessions clearing the wrong slot on save (#6509)
* Store session id in session data to prevent somehow deleting wrong slot * Only log session / system if beta or local; fix promise * Fix serialization/deserialization when logging session/system data * Force loadSaveSlot to set the logged in user's last session * No longer add slotId to session data
1 parent 8fdd504 commit 43f8b78

File tree

5 files changed

+206
-182
lines changed

5 files changed

+206
-182
lines changed

src/phases/game-over-phase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export class GameOverPhase extends BattlePhase {
204204
}
205205
this.getRunHistoryEntry().then(runHistoryEntry => {
206206
globalScene.gameData.saveRunHistory(runHistoryEntry, this.isVictory);
207-
globalScene.phaseManager.pushNew("PostGameOverPhase", endCardPhase);
207+
globalScene.phaseManager.pushNew("PostGameOverPhase", globalScene.sessionSlotId, endCardPhase);
208208
this.end();
209209
});
210210
};

src/phases/post-game-over-phase.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import type { EndCardPhase } from "#phases/end-card-phase";
55
export class PostGameOverPhase extends Phase {
66
public readonly phaseName = "PostGameOverPhase";
77
private endCardPhase?: EndCardPhase;
8+
private slotId: number;
89

9-
constructor(endCardPhase?: EndCardPhase) {
10+
constructor(slotId: number, endCardPhase?: EndCardPhase) {
1011
super();
11-
12+
this.slotId = slotId;
1213
this.endCardPhase = endCardPhase;
1314
}
1415

@@ -20,16 +21,14 @@ export class PostGameOverPhase extends Phase {
2021
if (!success) {
2122
return globalScene.reset(true);
2223
}
23-
globalScene.gameData
24-
.tryClearSession(globalScene.sessionSlotId)
25-
.then((success: boolean | [boolean, boolean]) => {
26-
if (!success[0]) {
27-
return globalScene.reset(true);
28-
}
29-
globalScene.reset();
30-
globalScene.phaseManager.unshiftNew("TitlePhase");
31-
this.end();
32-
});
24+
globalScene.gameData.tryClearSession(this.slotId).then((success: boolean | [boolean, boolean]) => {
25+
if (!success[0]) {
26+
return globalScene.reset(true);
27+
}
28+
globalScene.reset();
29+
globalScene.phaseManager.unshiftNew("TitlePhase");
30+
this.end();
31+
});
3332
});
3433
};
3534

src/phases/title-phase.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ export class TitlePhase extends Phase {
177177
.then((success: boolean) => {
178178
if (success) {
179179
this.loaded = true;
180+
if (loggedInUser) {
181+
loggedInUser.lastSessionSlot = slotId;
182+
}
180183
globalScene.ui.showText(i18next.t("menu:sessionSuccess"), null, () => this.end());
181184
} else {
182185
this.end();

src/plugins/api/pokerogue-session-savedata-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class PokerogueSessionSavedataApi extends ApiBase {
8282
try {
8383
const urlSearchParams = this.toUrlSearchParams(params);
8484
const response = await this.doGet(`/savedata/session/delete?${urlSearchParams}`);
85+
console.debug("%cSending a request to delete session in slot %d", "color: blue", params.slot);
8586

8687
if (response.ok) {
8788
return null;

0 commit comments

Comments
 (0)