zahlzerlegung/src/lib/stores/progress.ts
2026-04-28 01:54:27 +02:00

23 lines
608 B
TypeScript

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<Progress>(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));
}