Spaces:
Running
Running
| // Played-case memory: ids of every case this browser has STARTED, oldest first. | |
| // Sent with New Case so the server never deals this player a mystery they've seen. | |
| const KEY = 'cz-played' | |
| const CAP = 200 | |
| interface Stored { | |
| v: 1 | |
| ids: string[] | |
| } | |
| export function getPlayed(): string[] { | |
| try { | |
| const raw = localStorage.getItem(KEY) | |
| if (!raw) return [] | |
| const data = JSON.parse(raw) as Stored | |
| if (data?.v !== 1 || !Array.isArray(data.ids)) return [] | |
| return data.ids.filter((x) => typeof x === 'string') | |
| } catch { | |
| return [] | |
| } | |
| } | |
| export function markPlayed(id: string): void { | |
| if (!id) return | |
| try { | |
| const ids = getPlayed().filter((x) => x !== id) | |
| ids.push(id) // most recent last; the server uses order for its repeat-of-last-resort | |
| localStorage.setItem(KEY, JSON.stringify({ v: 1, ids: ids.slice(-CAP) })) | |
| } catch { | |
| /* private mode etc. — repeats become possible, nothing breaks */ | |
| } | |
| } | |