From 702aa00a2d85e91ce54504af4f7016c2aad9332d Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Thu, 30 Jul 2026 21:43:51 -0400 Subject: [PATCH] fix(player): drop the resumeFrom prop and let the state win Keep the save prop as the write-back target for "Save & Quit" without adding a second prop to say which asset boots: when both a save and a state are selected, the session resumes from the state. The save is no longer loaded right before a state overwrites it, so the outcome is the same but without the discarded SRAM injection. Co-Authored-By: Claude Opus 5 (1M context) --- frontend/src/v2/views/Player/EmulatorJS.vue | 8 --- .../src/views/Player/EmulatorJS/Player.vue | 19 ++----- .../src/views/Player/EmulatorJS/utils.test.ts | 51 +------------------ frontend/src/views/Player/EmulatorJS/utils.ts | 23 --------- 4 files changed, 6 insertions(+), 95 deletions(-) diff --git a/frontend/src/v2/views/Player/EmulatorJS.vue b/frontend/src/v2/views/Player/EmulatorJS.vue index 86dac08d5..2b0d37ba6 100644 --- a/frontend/src/v2/views/Player/EmulatorJS.vue +++ b/frontend/src/v2/views/Player/EmulatorJS.vue @@ -403,10 +403,6 @@ onMounted(async () => { // there are multiple saves, since loading the state injects a different // SRAM timeline that would overwrite an arbitrary save the user never // picked. In that case the user must select the save slot explicitly. - // - // Binding a save is not the same as resuming from it. The visible tab - // decides that (see `activeAssetTab`), so opening on States never means - // the bound save is the one that boots. const initiallyCompatibleStates = rom.value.user_states.filter( (s) => !s.emulator || s.emulator === supportedCores.value[0], ); @@ -543,9 +539,6 @@ const platformLabel = computed( ); type AssetTab = "save" | "state"; -// Doubles as the resume source handed to . The tab owns both the -// ("Resume from save/state") and what actually boots, so the -// preview can never promise a save while an armed state loads over it (#4010). const activeAssetTab = computed(() => isSavesTabSelected.value ? "save" : "state", ); @@ -793,7 +786,6 @@ const selectedAsset = computed(() => :rom="rom" :state="selectedState" :save="selectedSave" - :resume-from="activeAssetTab" :bios="selectedFirmware" :core="selectedCore" :disc="selectedDisc" diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index d41caf1d6..ac6bd2feb 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -34,8 +34,6 @@ import { createQuickLoadButton, createSaveQuitButton, createExitEmulationButton, - resolveResumeSource, - type ResumeSource, } from "./utils"; const INVALID_CHARS_REGEX = /[#<$+%>!`&*'|{}/\\?"=@:^\r\n]/gi; @@ -49,15 +47,11 @@ const router = useRouter(); const props = defineProps<{ rom: DetailedRom; - // The bound save slot: the write-back target "Save & Quit" PUTs into. It is - // only applied at boot when `resumeFrom` says so, so a save can stay bound - // while the session resumes from a state. save: SaveSchema | null; state: StateSchema | null; bios: FirmwareSchema | null; core: string | null; disc: number | null; - resumeFrom?: ResumeSource | null; }>(); const romRef = ref(props.rom); const saveRef = ref(props.save); @@ -438,18 +432,15 @@ window.EJS_onGameStart = async () => { if (!ready) { console.warn("Game manager not ready for save/state injection"); } else { - const resumeSource = resolveResumeSource({ - resumeFrom: props.resumeFrom, - hasSave: !!props.save, - hasState: !!props.state, - }); - if (resumeSource === "save" && props.save) { - await loadSave(props.save); - } else if (resumeSource === "state" && props.state) { + // A state restores the whole machine, SRAM included, so a save applied + // alongside it would be discarded: the state wins when both are set. + if (props.state) { await new Promise((resolve) => setTimeout(resolve, STATE_APPLY_SETTLE_MS), ); await loadState(props.state); + } else if (props.save) { + await loadSave(props.save); } } diff --git a/frontend/src/views/Player/EmulatorJS/utils.test.ts b/frontend/src/views/Player/EmulatorJS/utils.test.ts index a81665cef..04d4210bb 100644 --- a/frontend/src/views/Player/EmulatorJS/utils.test.ts +++ b/frontend/src/views/Player/EmulatorJS/utils.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest"; -import { installEJSDefaultOptionsTrap, resolveResumeSource } from "./utils"; +import { installEJSDefaultOptionsTrap } from "./utils"; const STORAGE_KEY = "ejs-7-n64-Test Game-settings"; @@ -133,52 +133,3 @@ describe("installEJSDefaultOptionsTrap", () => { expect(emulator.preGetSetting).toBe(patched); }); }); - -describe("resolveResumeSource", () => { - it("honours an explicit save choice while a state is armed", () => { - expect( - resolveResumeSource({ - resumeFrom: "save", - hasSave: true, - hasState: true, - }), - ).toBe("save"); - }); - - it("honours an explicit state choice while a save is bound", () => { - expect( - resolveResumeSource({ - resumeFrom: "state", - hasSave: true, - hasState: true, - }), - ).toBe("state"); - }); - - it("boots fresh when the chosen side has nothing selected", () => { - expect( - resolveResumeSource({ - resumeFrom: "save", - hasSave: false, - hasState: true, - }), - ).toBeNull(); - expect( - resolveResumeSource({ - resumeFrom: "state", - hasSave: true, - hasState: false, - }), - ).toBeNull(); - }); - - it("prefers the state when no choice is given", () => { - expect(resolveResumeSource({ hasSave: true, hasState: true })).toBe( - "state", - ); - expect(resolveResumeSource({ hasSave: true, hasState: false })).toBe( - "save", - ); - expect(resolveResumeSource({ hasSave: false, hasState: false })).toBeNull(); - }); -}); diff --git a/frontend/src/views/Player/EmulatorJS/utils.ts b/frontend/src/views/Player/EmulatorJS/utils.ts index f1e98167b..877386382 100644 --- a/frontend/src/views/Player/EmulatorJS/utils.ts +++ b/frontend/src/views/Player/EmulatorJS/utils.ts @@ -154,29 +154,6 @@ export function loadEmulatorJSState(state: Uint8Array) { window.EJS_emulator.gameManager.loadState(state); } -export type ResumeSource = "save" | "state"; - -/** - * Which asset the emulator applies at boot. A state restores the whole - * machine (SRAM included), so applying both would silently discard the save. - * Callers that keep a save bound as the write-back target while resuming from - * a state pass `resumeFrom` to say which one they actually mean; without it, - * a state wins (v1 keeps the two mutually exclusive, so only one is ever set). - */ -export function resolveResumeSource({ - resumeFrom, - hasSave, - hasState, -}: { - resumeFrom?: ResumeSource | null; - hasSave: boolean; - hasState: boolean; -}): ResumeSource | null { - const source = resumeFrom ?? (hasState ? "state" : "save"); - if (source === "state") return hasState ? "state" : null; - return hasSave ? "save" : null; -} - export function invalidateEmulatorJSRomCacheIfRenamed(rom: { id: number; fs_name: string;