mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 10:01:00 +01:00
feat(player): warn when the armed state is older than the latest save
The newest compatible state is still armed by default, but when a save postdates it the resume panel shows a warning with a one-click "Boot from save" action, so a handheld's newer in-game progress is not silently rolled back by an older browser state. The save preview row also shows the save's own screenshot when it has one. Closes #4278 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XXrMndq8eYexafm6nhajLo
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Към галерията",
|
||||
"back-to-game-details": "Към детайлите на играта",
|
||||
"background-color": "Цвят на фона",
|
||||
"boot-from-save": "Стартирай от записа",
|
||||
"cancel-launch": "Отказ на стартирането",
|
||||
"change-save": "Смени записа",
|
||||
"change-state": "Смени бързия запис",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Заглушаване",
|
||||
"new-memory-card": "Нова карта",
|
||||
"new-slot": "Нов слот…",
|
||||
"newer-save-warning": "Има запис от {time}, по-нов от този бърз запис. Продължаването от бързия запис може да върне напредъка ти назад.",
|
||||
"no-memory-cards": "Все още няма карти памет",
|
||||
"no-save-selected": "Няма избран запис",
|
||||
"no-saves-available": "Няма налични записи",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Zpět do galerie",
|
||||
"back-to-game-details": "Zpět k detailům hry",
|
||||
"background-color": "Barva pozadí",
|
||||
"boot-from-save": "Spustit z uložené pozice",
|
||||
"cancel-launch": "Zrušit spuštění",
|
||||
"change-save": "Změnit uloženou pozici",
|
||||
"change-state": "Změnit stav",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Ztlumit",
|
||||
"new-memory-card": "Nová karta",
|
||||
"new-slot": "Nový slot…",
|
||||
"newer-save-warning": "Uložená pozice z {time} je novější než tento stav. Pokračování ze stavu může vrátit váš postup zpět.",
|
||||
"no-memory-cards": "Zatím žádné paměťové karty",
|
||||
"no-save-selected": "Není vybrána žádná uložená pozice",
|
||||
"no-saves-available": "Nejsou k dispozici žádné uložené pozice",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Zurück zur Plattformübersicht",
|
||||
"back-to-game-details": "Zurück zu den Spieldetails",
|
||||
"background-color": "Hintergrundfarbe",
|
||||
"boot-from-save": "Vom Spielstand starten",
|
||||
"cancel-launch": "Start abbrechen",
|
||||
"change-save": "Speicherstand ändern",
|
||||
"change-state": "Speicherstand ändern",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Stummschalten",
|
||||
"new-memory-card": "Neue Karte",
|
||||
"new-slot": "Neuer Slot…",
|
||||
"newer-save-warning": "Ein Spielstand von {time} ist neuer als dieser Zustand. Vom Zustand fortzusetzen kann deinen Fortschritt zurücksetzen.",
|
||||
"no-memory-cards": "Noch keine Speicherkarten",
|
||||
"no-save-selected": "Kein Speicherstand ausgewählt",
|
||||
"no-saves-available": "Keine Speicherstände verfügbar",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Back to gallery",
|
||||
"back-to-game-details": "Back to game details",
|
||||
"background-color": "Background colour",
|
||||
"boot-from-save": "Boot from save",
|
||||
"cancel-launch": "Cancel launch",
|
||||
"change-save": "Change save",
|
||||
"change-state": "Change state",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Mute",
|
||||
"new-memory-card": "New card",
|
||||
"new-slot": "New slot…",
|
||||
"newer-save-warning": "A save from {time} is newer than this state. Resuming the state may roll your progress back.",
|
||||
"no-memory-cards": "No memory cards yet",
|
||||
"no-save-selected": "No save selected",
|
||||
"no-saves-available": "No saves available",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Back to gallery",
|
||||
"back-to-game-details": "Back to game details",
|
||||
"background-color": "Background color",
|
||||
"boot-from-save": "Boot from save",
|
||||
"cancel-launch": "Cancel launch",
|
||||
"change-save": "Change save",
|
||||
"change-state": "Change state",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Mute",
|
||||
"new-memory-card": "New card",
|
||||
"new-slot": "New slot…",
|
||||
"newer-save-warning": "A save from {time} is newer than this state. Resuming the state may roll your progress back.",
|
||||
"no-memory-cards": "No memory cards yet",
|
||||
"no-save-selected": "No save selected",
|
||||
"no-saves-available": "No saves available",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Volver a galería",
|
||||
"back-to-game-details": "Volver a detalles",
|
||||
"background-color": "Color de fondo",
|
||||
"boot-from-save": "Arrancar desde la partida guardada",
|
||||
"cancel-launch": "Cancelar inicio",
|
||||
"change-save": "Cambiar guardado",
|
||||
"change-state": "Cambiar estado",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Silenciar",
|
||||
"new-memory-card": "Nueva tarjeta",
|
||||
"new-slot": "Nueva ranura…",
|
||||
"newer-save-warning": "Hay una partida guardada de {time} más reciente que este estado. Continuar desde el estado puede hacerte perder progreso.",
|
||||
"no-memory-cards": "Aún no hay tarjetas de memoria",
|
||||
"no-save-selected": "Ningún guardado seleccionado",
|
||||
"no-saves-available": "No hay guardados disponibles",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Retour à la galerie",
|
||||
"back-to-game-details": "Retour aux détails du jeu",
|
||||
"background-color": "Couleur d'arrière-plan",
|
||||
"boot-from-save": "Démarrer depuis la sauvegarde",
|
||||
"cancel-launch": "Annuler le lancement",
|
||||
"change-save": "Changer la sauvegarde",
|
||||
"change-state": "Changer l'état",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Couper le son",
|
||||
"new-memory-card": "Nouvelle carte",
|
||||
"new-slot": "Nouvel emplacement…",
|
||||
"newer-save-warning": "Une sauvegarde de {time} est plus récente que cet état. Reprendre l'état peut vous faire perdre de la progression.",
|
||||
"no-memory-cards": "Aucune carte mémoire pour le moment",
|
||||
"no-save-selected": "Aucune sauvegarde sélectionnée",
|
||||
"no-saves-available": "Aucune sauvegarde disponible",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Vissza a galériába",
|
||||
"back-to-game-details": "Vissza a játék részleteihez",
|
||||
"background-color": "Háttérszín",
|
||||
"boot-from-save": "Indítás mentésből",
|
||||
"cancel-launch": "Indítás megszakítása",
|
||||
"change-save": "Mentés cseréje",
|
||||
"change-state": "Állás cseréje",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Némítás",
|
||||
"new-memory-card": "Új kártya",
|
||||
"new-slot": "Új hely…",
|
||||
"newer-save-warning": "Egy {time} mentés újabb ennél az állásnál. Az állás folytatása visszavetheti a haladásodat.",
|
||||
"no-memory-cards": "Még nincsenek memóriakártyák",
|
||||
"no-save-selected": "Nincs kiválasztott mentés",
|
||||
"no-saves-available": "Nincs elérhető mentés",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Ritorna alla galleria",
|
||||
"back-to-game-details": "Ritorna ai dettagli del gioco",
|
||||
"background-color": "Colore di sfondo",
|
||||
"boot-from-save": "Avvia dal salvataggio",
|
||||
"cancel-launch": "Annulla avvio",
|
||||
"change-save": "Cambia Salvataggio",
|
||||
"change-state": "Cambia Stato",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Disattiva audio",
|
||||
"new-memory-card": "Nuova card",
|
||||
"new-slot": "Nuovo slot…",
|
||||
"newer-save-warning": "Un salvataggio di {time} è più recente di questo stato. Riprendere lo stato può farti perdere progressi.",
|
||||
"no-memory-cards": "Nessuna memory card",
|
||||
"no-save-selected": "Nessun salvataggio selezionato",
|
||||
"no-saves-available": "Nessun salvataggio disponibile",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "ギャラリーへ戻る",
|
||||
"back-to-game-details": "ゲーム詳細へ戻る",
|
||||
"background-color": "背景色",
|
||||
"boot-from-save": "セーブから起動",
|
||||
"cancel-launch": "起動をキャンセル",
|
||||
"change-save": "セーブデータを変更",
|
||||
"change-state": "ステートを変更",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "ミュート",
|
||||
"new-memory-card": "新しいカード",
|
||||
"new-slot": "新しいスロット…",
|
||||
"newer-save-warning": "{time}のセーブはこのステートセーブより新しいです。ステートから再開すると進行状況が戻る可能性があります。",
|
||||
"no-memory-cards": "メモリーカードはまだありません",
|
||||
"no-save-selected": "セーブデータが選択されていません",
|
||||
"no-saves-available": "利用可能なセーブデータがありません",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "갤러리로 가기",
|
||||
"back-to-game-details": "게임 설명으로 가기",
|
||||
"background-color": "배경색",
|
||||
"boot-from-save": "세이브에서 시작",
|
||||
"cancel-launch": "시작 취소",
|
||||
"change-save": "세이브 변경",
|
||||
"change-state": "상태 변경",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "음소거",
|
||||
"new-memory-card": "새 카드",
|
||||
"new-slot": "새 슬롯…",
|
||||
"newer-save-warning": "{time}의 세이브가 이 상태보다 최신입니다. 상태에서 이어하면 진행 상황이 되돌아갈 수 있습니다.",
|
||||
"no-memory-cards": "메모리 카드가 아직 없습니다",
|
||||
"no-save-selected": "선택된 세이브 없음",
|
||||
"no-saves-available": "사용 가능한 세이브 없음",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Powrót do galerii",
|
||||
"back-to-game-details": "Powrót do szczegółów gry",
|
||||
"background-color": "Kolor tła",
|
||||
"boot-from-save": "Uruchom z zapisu",
|
||||
"cancel-launch": "Anuluj uruchamianie",
|
||||
"change-save": "Zmień zapis",
|
||||
"change-state": "Zmień stan",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Wycisz",
|
||||
"new-memory-card": "Nowa karta",
|
||||
"new-slot": "Nowy slot…",
|
||||
"newer-save-warning": "Zapis z {time} jest nowszy niż ten stan. Wznowienie stanu może cofnąć twój postęp.",
|
||||
"no-memory-cards": "Brak kart pamięci",
|
||||
"no-save-selected": "Nie wybrano zapisu",
|
||||
"no-saves-available": "Brak dostępnych zapisów",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Voltar à galeria",
|
||||
"back-to-game-details": "Voltar aos detalhes do jogo",
|
||||
"background-color": "Cor de fundo",
|
||||
"boot-from-save": "Iniciar a partir do save",
|
||||
"cancel-launch": "Cancelar inicialização",
|
||||
"change-save": "Alterar save",
|
||||
"change-state": "Alterar estado",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Silenciar",
|
||||
"new-memory-card": "Novo cartão",
|
||||
"new-slot": "Novo slot…",
|
||||
"newer-save-warning": "Um save de {time} é mais recente que este state. Retomar o state pode desfazer seu progresso.",
|
||||
"no-memory-cards": "Nenhum cartão de memória ainda",
|
||||
"no-save-selected": "Nenhum save selecionado",
|
||||
"no-saves-available": "Nenhum save disponível",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Înapoi la galerie",
|
||||
"back-to-game-details": "Înapoi la detaliile jocului",
|
||||
"background-color": "Culoare de fundal",
|
||||
"boot-from-save": "Pornește din salvare",
|
||||
"cancel-launch": "Anulează pornirea",
|
||||
"change-save": "Schimbă salvare",
|
||||
"change-state": "Schimbă stare",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Dezactivează sunetul",
|
||||
"new-memory-card": "Card nou",
|
||||
"new-slot": "Slot nou…",
|
||||
"newer-save-warning": "O salvare de {time} este mai nouă decât această stare. Reluarea stării îți poate da progresul înapoi.",
|
||||
"no-memory-cards": "Încă niciun card de memorie",
|
||||
"no-save-selected": "Nicio salvare selectată",
|
||||
"no-saves-available": "Nicio salvare disponibilă",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Вернуться в галерею",
|
||||
"back-to-game-details": "Вернуться к деталям игры",
|
||||
"background-color": "Цвет фона",
|
||||
"boot-from-save": "Запустить с сохранения",
|
||||
"cancel-launch": "Отменить запуск",
|
||||
"change-save": "Изменить сохранение",
|
||||
"change-state": "Изменить состояние",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Отключить звук",
|
||||
"new-memory-card": "Новая карта",
|
||||
"new-slot": "Новый слот…",
|
||||
"newer-save-warning": "Сохранение от {time} новее этого состояния. Продолжение с состояния может откатить ваш прогресс.",
|
||||
"no-memory-cards": "Пока нет карт памяти",
|
||||
"no-save-selected": "Сохранение не выбрано",
|
||||
"no-saves-available": "Нет доступных сохранений",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "Galeriye dön",
|
||||
"back-to-game-details": "Oyun ayrıntılarına dön",
|
||||
"background-color": "Arka plan rengi",
|
||||
"boot-from-save": "Kayıttan başlat",
|
||||
"cancel-launch": "Başlatmayı iptal et",
|
||||
"change-save": "Kaydı değiştir",
|
||||
"change-state": "Durum kaydını değiştir",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "Sessize al",
|
||||
"new-memory-card": "Yeni kart",
|
||||
"new-slot": "Yeni yuva…",
|
||||
"newer-save-warning": "{time} tarihli kayıt bu durum kaydından daha yeni. Durumdan devam etmek ilerlemenizi geri alabilir.",
|
||||
"no-memory-cards": "Henüz hafıza kartı yok",
|
||||
"no-save-selected": "Kayıt seçilmedi",
|
||||
"no-saves-available": "Mevcut kayıt yok",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "返回游戏库",
|
||||
"back-to-game-details": "返回游戏详情",
|
||||
"background-color": "背景颜色",
|
||||
"boot-from-save": "从存档启动",
|
||||
"cancel-launch": "取消启动",
|
||||
"change-save": "更改存档",
|
||||
"change-state": "更改状态",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "静音",
|
||||
"new-memory-card": "新建卡",
|
||||
"new-slot": "新建存档位…",
|
||||
"newer-save-warning": "{time}的存档比此状态更新。从状态继续可能会回退你的进度。",
|
||||
"no-memory-cards": "尚无记忆卡",
|
||||
"no-save-selected": "未选择存档",
|
||||
"no-saves-available": "无可用存档",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"back-to-gallery": "返回遊戲庫",
|
||||
"back-to-game-details": "返回遊戲詳情",
|
||||
"background-color": "背景顏色",
|
||||
"boot-from-save": "從存檔啟動",
|
||||
"cancel-launch": "取消啟動",
|
||||
"change-save": "更改存檔",
|
||||
"change-state": "更改即時存檔",
|
||||
@@ -101,6 +102,7 @@
|
||||
"mute": "靜音",
|
||||
"new-memory-card": "新增卡",
|
||||
"new-slot": "新增存檔格…",
|
||||
"newer-save-warning": "{time}的存檔比此即時存檔更新。從即時存檔繼續可能會回退你的進度。",
|
||||
"no-memory-cards": "尚無記憶卡",
|
||||
"no-save-selected": "未選擇存檔",
|
||||
"no-saves-available": "無可用存檔",
|
||||
|
||||
@@ -123,6 +123,30 @@ export const SaveSelected: Story = {
|
||||
}),
|
||||
};
|
||||
|
||||
export const SaveWithScreenshot: Story = {
|
||||
name: "Save · with screenshot",
|
||||
render: () => ({
|
||||
components: { AssetPreview },
|
||||
setup: () => ({
|
||||
asset: makeSave({
|
||||
screenshot: {
|
||||
id: 2,
|
||||
rom_id: 1,
|
||||
user_id: 1,
|
||||
file_name: "main_quest.png",
|
||||
file_name_no_tags: "main_quest.png",
|
||||
file_name_no_ext: "main_quest",
|
||||
file_extension: "png",
|
||||
file_path: "/screenshots/snes",
|
||||
download_path:
|
||||
"https://placehold.co/640x360/1a3d2e/ffffff?text=Main+Quest",
|
||||
} as SaveSchema["screenshot"],
|
||||
}),
|
||||
}),
|
||||
template: `<AssetPreview :asset="asset" type="save" />`,
|
||||
}),
|
||||
};
|
||||
|
||||
// A state is armed, so the save is the write-back target, not what boots.
|
||||
export const SaveAsWriteTarget: Story = {
|
||||
name: "Save · write-back target",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
// Preview of the asset to resume from: a screenshot stage for states, one
|
||||
// compact row for saves (relabelled as the write target when a state is armed).
|
||||
// compact row for saves (thumbnail when the save has a screenshot; relabelled
|
||||
// as the write target when a state is armed).
|
||||
import { RIcon, RTag, RTooltip } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
@@ -118,8 +119,18 @@ const emptyText = computed(() =>
|
||||
class="r-asset-preview__body"
|
||||
:class="{ 'r-asset-preview__body--empty': !asset }"
|
||||
>
|
||||
<div v-if="type === 'save'" class="r-asset-preview__save-badge">
|
||||
<div
|
||||
v-if="type === 'save'"
|
||||
class="r-asset-preview__save-badge"
|
||||
:class="{ 'r-asset-preview__save-badge--shot': screenshotUrl }"
|
||||
:style="
|
||||
screenshotUrl
|
||||
? { backgroundImage: toCssUrl(screenshotUrl) }
|
||||
: undefined
|
||||
"
|
||||
>
|
||||
<RIcon
|
||||
v-if="!screenshotUrl"
|
||||
:icon="asset ? 'mdi-content-save' : 'mdi-content-save-outline'"
|
||||
size="22"
|
||||
/>
|
||||
@@ -314,6 +325,12 @@ const emptyText = computed(() =>
|
||||
background: color-mix(in srgb, var(--r-color-brand-primary) 22%, transparent);
|
||||
color: var(--r-color-brand-primary);
|
||||
}
|
||||
.r-asset-preview__save-badge--shot {
|
||||
width: 71px;
|
||||
border-radius: var(--r-radius-sm);
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
}
|
||||
.r-asset-preview__body--empty .r-asset-preview__save-badge {
|
||||
background: var(--r-color-bg-elevated);
|
||||
color: var(--r-color-fg-muted);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
// wiring — not worth rewriting). The v1 SelectSaveDialog / SelectStateDialog
|
||||
// + CacheDialog are mounted in GlobalDialogs so the emitter bridge works.
|
||||
import {
|
||||
RAlert,
|
||||
RBtn,
|
||||
RCard,
|
||||
RIcon,
|
||||
@@ -46,7 +47,11 @@ import storeConfig from "@/stores/config";
|
||||
import storePlaying from "@/stores/playing";
|
||||
import type { DetailedRom } from "@/stores/roms";
|
||||
import type { Events } from "@/types/emitter";
|
||||
import { areThreadsRequiredForEJSCore, getSupportedEJSCores } from "@/utils";
|
||||
import {
|
||||
areThreadsRequiredForEJSCore,
|
||||
formatRelativeDate,
|
||||
getSupportedEJSCores,
|
||||
} from "@/utils";
|
||||
import AssetPreview from "@/v2/components/Player/AssetPreview.vue";
|
||||
import AssetList from "@/v2/components/shared/AssetList.vue";
|
||||
import AssetStrip from "@/v2/components/shared/AssetStrip.vue";
|
||||
@@ -83,6 +88,7 @@ import { installIOSFullscreenShim } from "@/views/Player/EmulatorJS/utils";
|
||||
import { rememberCore, resolveRememberedCore } from "./coreStorage";
|
||||
import {
|
||||
defaultResumeSelection,
|
||||
newerSaveThanState,
|
||||
pickSave,
|
||||
pickState,
|
||||
slotOptions,
|
||||
@@ -465,6 +471,13 @@ const selectedAsset = computed<SaveSchema | StateSchema | null>(() =>
|
||||
);
|
||||
const selectedAssetId = computed(() => selectedAsset.value?.id ?? null);
|
||||
|
||||
// A state older than the latest save would roll progress back (#4278).
|
||||
const newerSave = computed(() =>
|
||||
resume.value.state
|
||||
? newerSaveThanState(rom.value?.user_saves ?? [], resume.value.state)
|
||||
: null,
|
||||
);
|
||||
|
||||
// Slot for saves the session creates. A bound save with a slot fixes it; a
|
||||
// slot-less legacy save stays as an archive and progress goes to the pick.
|
||||
const NEW_SLOT = "__new__";
|
||||
@@ -565,6 +578,22 @@ const saveSlot = computed(() =>
|
||||
</div>
|
||||
|
||||
<div class="r-v2-ejs__resume-body">
|
||||
<RAlert
|
||||
v-if="newerSave"
|
||||
type="warning"
|
||||
density="compact"
|
||||
:text="
|
||||
t('play.newer-save-warning', {
|
||||
time: formatRelativeDate(newerSave.updated_at),
|
||||
})
|
||||
"
|
||||
>
|
||||
<template #append>
|
||||
<RBtn variant="text" size="small" @click="selectSave(newerSave)">
|
||||
{{ t("play.boot-from-save") }}
|
||||
</RBtn>
|
||||
</template>
|
||||
</RAlert>
|
||||
<AssetPreview
|
||||
:asset="selectedAsset"
|
||||
:type="activeAssetTab"
|
||||
|
||||
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
import type { SaveSchema, StateSchema } from "@/__generated__";
|
||||
import {
|
||||
defaultResumeSelection,
|
||||
newerSaveThanState,
|
||||
pickSave,
|
||||
pickState,
|
||||
slotOptions,
|
||||
@@ -95,3 +96,25 @@ describe("slotOptions", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("newerSaveThanState", () => {
|
||||
const at = (updated_at: string) => ({ updated_at }) as SaveSchema;
|
||||
const stateAt = (updated_at: string) => ({ updated_at }) as StateSchema;
|
||||
|
||||
it("returns the newest save when it postdates the state", () => {
|
||||
const saves = [at("2026-09-01T10:00:00Z"), at("2026-09-03T10:00:00Z")];
|
||||
|
||||
expect(newerSaveThanState(saves, stateAt("2026-09-02T10:00:00Z"))).toBe(
|
||||
saves[1],
|
||||
);
|
||||
});
|
||||
|
||||
it("returns null when the state is the latest progress", () => {
|
||||
const saves = [at("2026-09-01T10:00:00Z")];
|
||||
|
||||
expect(newerSaveThanState(saves, stateAt("2026-09-02T10:00:00Z"))).toBe(
|
||||
null,
|
||||
);
|
||||
expect(newerSaveThanState([], stateAt("2026-09-02T10:00:00Z"))).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,3 +48,15 @@ export function slotOptions(saves: readonly SaveSchema[]): string[] {
|
||||
.filter((slot): slot is string => !!slot && slot !== AUTOSAVE_SLOT);
|
||||
return [AUTOSAVE_SLOT, ...new Set(named)];
|
||||
}
|
||||
|
||||
/** The newest save when it postdates the armed state, so the user can be warned. */
|
||||
export function newerSaveThanState(
|
||||
saves: readonly SaveSchema[],
|
||||
state: StateSchema,
|
||||
): SaveSchema | null {
|
||||
const newest = saves.reduce<SaveSchema | null>(
|
||||
(best, save) => (!best || save.updated_at > best.updated_at ? save : best),
|
||||
null,
|
||||
);
|
||||
return newest && newest.updated_at > state.updated_at ? newest : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user