feat: Doing more polishing (M8b)

This commit is contained in:
gauvainboiche
2026-10-25 18:50:17 +01:00
parent c2103c32e7
commit c55e5a2484
34 changed files with 1605 additions and 106 deletions
+12 -1
View File
@@ -46,6 +46,13 @@ export function encodeSave(state) {
export const MIGRATIONS = {
// v2 added the world cycle: older saves start it at neutral.
1: (s) => ({ ...s, version: 2, world: { cycle: 0 } }),
// v3 replaced the single pending card by the in-tray queue.
2: ({ pendingCard, ...s }) => ({
...s,
version: 3,
inbox: pendingCard ? [{ id: pendingCard.id, day: pendingCard.day }] : [],
pending: { ...s.pending, weeklyCard: Boolean(s.pending?.weeklyCard) && !pendingCard, inboxFull: false },
}),
};
export function migrate(state) {
@@ -55,7 +62,11 @@ export function migrate(state) {
while (s.version < STATE_VERSION) {
const step = MIGRATIONS[s.version];
if (!step) return { ok: false, error: "version" };
s = step(s);
try {
s = step(s);
} catch {
return { ok: false, error: "format" }; // a damaged or hostile save must never throw
}
}
return { ok: true, state: s };
}
+3 -1
View File
@@ -88,7 +88,7 @@ export function readSave(store, key) {
// ---- Settings ----
const DEFAULT_SETTINGS = { lang: null, slow: false };
const DEFAULT_SETTINGS = { lang: null, slow: false, sound: true, volume: 0.6 };
export function loadSettings(store) {
try {
@@ -96,6 +96,8 @@ export function loadSettings(store) {
return {
lang: s.lang === "en" || s.lang === "fr" ? s.lang : DEFAULT_SETTINGS.lang,
slow: s.slow === true,
sound: s.sound !== false,
volume: typeof s.volume === "number" && s.volume >= 0 && s.volume <= 1 ? s.volume : DEFAULT_SETTINGS.volume,
};
} catch {
return { ...DEFAULT_SETTINGS };