import { writable } from 'svelte/store'; import { emptyProgress, loadProgress, recordRun, saveProgress, type Progress, } from '../game/persistence'; import type { Target } from '../game/tasks'; import type { Stage } from '../game/stages'; const initial: Progress = typeof window === 'undefined' ? emptyProgress() : loadProgress(); export const progress = writable(initial); progress.subscribe((p) => { if (typeof window !== 'undefined') saveProgress(p); }); export function recordResult(target: Target, stage: Stage): void { progress.update((p) => recordRun(p, target, stage)); }