refactor(player): simplify save/state loading (simplify)

- The shell passes the Load button's label as a prop, so the shared
  Player no longer reads the UI version to guess which picker answers.
- The file-picker fallback after a save or state download is gone:
  an arraybuffer response is always an ArrayBuffer, so it never ran.
- The picker keeps its saves and states lists in one place for the tabs
  and the lists.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CErWeM5xFMumPtHozLcCV
This commit is contained in:
zurdi
2026-09-18 12:31:46 +02:00
parent 0ed149ba85
commit bee249b7ea
3 changed files with 22 additions and 36 deletions

View File

@@ -3,7 +3,7 @@
// on `selectStateDialog`, emits `saveSelected` or `stateSelected`.
import { RBtn, RDialog, RSliderBtnGroup } from "@v2/lib";
import type { Emitter } from "mitt";
import { inject, onBeforeUnmount, ref } from "vue";
import { computed, inject, onBeforeUnmount, ref } from "vue";
import { useI18n } from "vue-i18n";
import type { SaveSchema, StateSchema } from "@/__generated__";
import type { DetailedRom } from "@/stores/roms";
@@ -25,9 +25,11 @@ const rom = ref<DetailedRom | null>(null);
// States apply on the fly, so they are what the button reaches for first.
const tab = ref<AssetType>("state");
const saves = computed(() => rom.value?.user_saves ?? []);
const states = computed(() => rom.value?.user_states ?? []);
const { tabs, stateDisabledReason } = useSaveStateTabs(
() => rom.value?.user_saves ?? [],
() => rom.value?.user_states ?? [],
saves,
states,
() => window.EJS_core,
);
@@ -96,14 +98,14 @@ function closeDialog() {
<template #content>
<AssetList
v-if="tab === 'save'"
:assets="rom?.user_saves ?? []"
:assets="saves"
type="save"
:scrollable="false"
@select="onSelect"
/>
<AssetStrip
v-else
:assets="rom?.user_states ?? []"
:assets="states"
type="state"
layout="flow"
group-by="emulator"

View File

@@ -866,6 +866,7 @@ const saveSlot = computed(() => chosenSlot(slotChoice.value, customSlot.value));
:state="resume.state"
:save="resume.save"
:save-slot="saveSlot"
:load-state-label="t('rom.load-save-or-state')"
:bios="selectedFirmware"
:core="selectedCore"
:disc="bootDiscId(selectedDisc)"

View File

@@ -18,7 +18,6 @@ import type {
StateSchema,
NetplayICEServer,
} from "@/__generated__";
import { useUiVersion } from "@/composables/useUiVersion";
import { ROUTES } from "@/plugins/router";
import { saveApi as api } from "@/services/api/save";
import pendingAssetStore, {
@@ -83,6 +82,8 @@ const props = defineProps<{
disc: number | null;
/** Slot for new saves when the loaded save has none; defaults to autosave. */
saveSlot?: string | null;
/** Load State button label; the shell names the picker it opens. */
loadStateLabel?: string;
}>();
const romRef = ref<DetailedRom>(props.rom);
// The save the session booted from, and the version this session has written
@@ -351,12 +352,7 @@ window.EJS_Buttons = {
pause: { displayName: t("play.pause") },
play: { displayName: t("play.resume") },
saveState: { displayName: t("play.save-state") },
loadState: {
displayName:
useUiVersion().value === "v2"
? t("rom.load-save-or-state")
: t("play.load-state"),
},
loadState: { displayName: props.loadStateLabel ?? t("play.load-state") },
gamepad: { displayName: t("play.control-settings") },
cheat: { displayName: t("play.cheats") },
cacheManager: { displayName: t("play.cache-manager") },
@@ -646,22 +642,16 @@ async function loadSave(save: SaveSchema) {
responseType: "arraybuffer",
params: { device_id: deviceIDRef.value },
});
const bytes = data
? new Uint8Array(data)
: new Uint8Array(
await (await window.EJS_emulator.selectFile()).arrayBuffer(),
);
const bytes = new Uint8Array(data);
loadEmulatorJSSave(bytes);
// Writes follow the picked save only once its bytes are in the core.
loadedSave = save;
sessionSaveRef.value = null;
if (data) {
saveTracker.seed(bytes);
displayMessage(t("play.save-loaded"), {
duration: 3000,
icon: "mdi-cloud-download-outline",
});
}
saveTracker.seed(bytes);
displayMessage(t("play.save-loaded"), {
duration: 3000,
icon: "mdi-cloud-download-outline",
});
} finally {
saveLoading = false;
}
@@ -704,18 +694,11 @@ async function loadState(state: StateSchema) {
const { data } = await api.get(state.download_path.replace("/api", ""), {
responseType: "arraybuffer",
});
const bytes = data
? new Uint8Array(data)
: new Uint8Array(
await (await window.EJS_emulator.selectFile()).arrayBuffer(),
);
await applyState(bytes);
if (data) {
displayMessage(t("play.state-loaded"), {
duration: 3000,
icon: "mdi-cloud-download-outline",
});
}
await applyState(new Uint8Array(data));
displayMessage(t("play.state-loaded"), {
duration: 3000,
icon: "mdi-cloud-download-outline",
});
} finally {
stateApplied();
}