// Versioned local save. Never leaves the device. export interface SaveV1 { v: 1; candy: number; caughtEver: string[]; trophies: { date: string; seconds: number; candy: number; difficulty: number }[]; names: Record; /** Cat home decorations and wardrobe items the player has bought with candy. */ owned: string[]; /** What the player is wearing: hoodie colour id, hat id. */ outfit: { hood: string; hat: string }; settings: { difficulty: number; music: number; sfx: number; reducedMotion: boolean }; } const KEY = 'fck-save-v1'; export function fresh(): SaveV1 { return { v: 1, candy: 0, caughtEver: [], trophies: [], names: {}, owned: ['bed', 'yarn'], outfit: { hood: 'lilac', hat: 'none' }, settings: { difficulty: 0, music: 0.7, sfx: 1, reducedMotion: false } }; } export function loadSave(): SaveV1 { try { const raw = localStorage.getItem(KEY); if (!raw) return fresh(); const s = JSON.parse(raw) as Partial; if (s.v !== 1) return fresh(); const f = fresh(); return { ...f, ...s, settings: { ...f.settings, ...(s.settings ?? {}) }, outfit: { ...f.outfit, ...(s.outfit ?? {}) }, owned: Array.isArray(s.owned) ? s.owned : f.owned } as SaveV1; } catch { return fresh(); } } export function persist(s: SaveV1) { try { localStorage.setItem(KEY, JSON.stringify(s)); } catch { /* storage blocked: play on */ } }