Allow deleting malformed sessions

This commit is contained in:
Sirz Benjie 2025-08-12 20:16:58 -05:00
parent 13ffef7015
commit 88c71930ef
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E

View File

@ -113,55 +113,58 @@ export class SaveSlotSelectUiHandler extends MessageUiHandler {
const originalCallback = this.saveSlotSelectCallback; const originalCallback = this.saveSlotSelectCallback;
if (button === Button.ACTION) { if (button === Button.ACTION) {
const cursor = this.cursor + this.scrollCursor; const cursor = this.cursor + this.scrollCursor;
if (this.uiMode === SaveSlotUiMode.LOAD && !this.sessionSlots[cursor].hasData) { const sessionSlot = this.sessionSlots[cursor];
if (this.uiMode === SaveSlotUiMode.LOAD && !sessionSlot.hasData) {
error = true; error = true;
} else { } else {
switch (this.uiMode) { switch (this.uiMode) {
case SaveSlotUiMode.LOAD: case SaveSlotUiMode.LOAD:
manageDataOptions.push({ if (!sessionSlot.malformed) {
label: i18next.t("menu:loadGame"), manageDataOptions.push({
handler: () => { label: i18next.t("menu:loadGame"),
globalScene.ui.revertMode(); handler: () => {
originalCallback?.(cursor); globalScene.ui.revertMode();
return true; originalCallback?.(cursor);
}, return true;
keepOpen: false, },
}); keepOpen: false,
});
manageDataOptions.push({ manageDataOptions.push({
label: i18next.t("saveSlotSelectUiHandler:renameRun"), label: i18next.t("saveSlotSelectUiHandler:renameRun"),
handler: () => { handler: () => {
globalScene.ui.revertMode(); globalScene.ui.revertMode();
ui.setOverlayMode( ui.setOverlayMode(
UiMode.RENAME_RUN, UiMode.RENAME_RUN,
{ {
buttonActions: [ buttonActions: [
(sanitizedName: string) => { (sanitizedName: string) => {
const name = decodeURIComponent(atob(sanitizedName)); const name = decodeURIComponent(atob(sanitizedName));
globalScene.gameData.renameSession(cursor, name).then(response => { globalScene.gameData.renameSession(cursor, name).then(response => {
if (response[0] === false) { if (response[0] === false) {
globalScene.reset(true); globalScene.reset(true);
} else { } else {
this.clearSessionSlots(); this.clearSessionSlots();
this.cursorObj = null; this.cursorObj = null;
this.populateSessionSlots(); this.populateSessionSlots();
this.setScrollCursor(0); this.setScrollCursor(0);
this.setCursor(0); this.setCursor(0);
ui.revertMode(); ui.revertMode();
ui.showText("", 0); ui.showText("", 0);
} }
}); });
}, },
() => { () => {
ui.revertMode(); ui.revertMode();
}, },
], ],
}, },
"", "",
); );
return true; return true;
}, },
}); });
}
this.manageDataConfig = { this.manageDataConfig = {
xOffset: 0, xOffset: 0,
@ -389,7 +392,8 @@ export class SaveSlotSelectUiHandler extends MessageUiHandler {
const cursorPosition = cursor + this.scrollCursor; const cursorPosition = cursor + this.scrollCursor;
const cursorIncrement = cursorPosition * 76; const cursorIncrement = cursorPosition * 76;
if (this.sessionSlots[cursorPosition] && this.cursorObj) { if (this.sessionSlots[cursorPosition] && this.cursorObj) {
const hasData = this.sessionSlots[cursorPosition].hasData; const session = this.sessionSlots[cursorPosition];
const hasData = session.hasData && !session.malformed;
// If the session slot lacks session data, it does not move from its default, central position. // If the session slot lacks session data, it does not move from its default, central position.
// Only session slots with session data will move leftwards and have a visible arrow. // Only session slots with session data will move leftwards and have a visible arrow.
if (!hasData) { if (!hasData) {
@ -478,6 +482,8 @@ export class SaveSlotSelectUiHandler extends MessageUiHandler {
class SessionSlot extends Phaser.GameObjects.Container { class SessionSlot extends Phaser.GameObjects.Container {
public slotId: number; public slotId: number;
public hasData: boolean; public hasData: boolean;
/** Indicates the save slot ran into an error while being loaded */
public malformed: boolean;
private slotWindow: Phaser.GameObjects.NineSlice; private slotWindow: Phaser.GameObjects.NineSlice;
private loadingLabel: Phaser.GameObjects.Text; private loadingLabel: Phaser.GameObjects.Text;
public saveData: SessionSaveData; public saveData: SessionSaveData;
@ -625,22 +631,32 @@ class SessionSlot extends Phaser.GameObjects.Container {
load(): Promise<boolean> { load(): Promise<boolean> {
return new Promise<boolean>(resolve => { return new Promise<boolean>(resolve => {
globalScene.gameData.getSession(this.slotId).then(async sessionData => { globalScene.gameData
// Ignore the results if the view was exited .getSession(this.slotId)
if (!this.active) { .then(async sessionData => {
return; // Ignore the results if the view was exited
} if (!this.active) {
if (!sessionData) { return;
this.hasData = false; }
this.loadingLabel.setText(i18next.t("saveSlotSelectUiHandler:empty")); this.hasData = !!sessionData;
resolve(false); if (!sessionData) {
return; this.loadingLabel.setText(i18next.t("saveSlotSelectUiHandler:empty"));
} resolve(false);
this.hasData = true; return;
this.saveData = sessionData; }
await this.setupWithData(sessionData); this.saveData = sessionData;
resolve(true); resolve(true);
}); })
.catch(e => {
if (!this.active) {
return;
}
console.warn(`Failed to load session slot #${this.slotId}:`, e);
this.loadingLabel.setText(i18next.t("menu:failedToLoadSession"));
this.hasData = true;
this.malformed = true;
resolve(true);
});
}); });
} }
} }