Im Ergebnis den gerade gespielten Versuch korrekt markieren
This commit is contained in:
parent
cac6d1810c
commit
9c971ad717
|
|
@ -83,9 +83,14 @@ export function saveProgress(p: Progress): void {
|
|||
writeJson(PROGRESS_KEY, p);
|
||||
}
|
||||
|
||||
export function recordRun(p: Progress, target: Target, stage: Stage): Progress {
|
||||
export function recordRun(
|
||||
p: Progress,
|
||||
target: Target,
|
||||
stage: Stage,
|
||||
date: string = new Date().toISOString()
|
||||
): Progress {
|
||||
const prev = p.perTarget[target] ?? { runs: 0, top5: [] };
|
||||
const next: RunRecord = { stage, date: new Date().toISOString() };
|
||||
const next: RunRecord = { stage, date };
|
||||
const merged = [...prev.top5, next].sort((a, b) => {
|
||||
if (b.stage !== a.stage) return b.stage - a.stage;
|
||||
return b.date.localeCompare(a.date);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { fade, fly } from 'svelte/transition';
|
||||
import type { Target } from '../game/tasks';
|
||||
import { progress } from '../stores/progress';
|
||||
import { lastRun } from '../stores/progress';
|
||||
import { startGame } from '../stores/game';
|
||||
import { goHome, goGame } from '../stores/route';
|
||||
import { play, unlockAudio } from '../audio/soundManager';
|
||||
|
|
@ -12,9 +12,10 @@
|
|||
type Props = { target: Target };
|
||||
let { target }: Props = $props();
|
||||
|
||||
// Aktueller Run = top-Eintrag mit dem letzten Datum
|
||||
const lastRunDate = $derived($progress.perTarget[target]?.top5[0]?.date ?? null);
|
||||
const lastStage = $derived(($progress.perTarget[target]?.top5[0]?.stage ?? 0) as number);
|
||||
// Genau der gerade gespielte Lauf (kann auch ein nicht-bester Versuch sein).
|
||||
const current = $derived($lastRun?.target === target ? $lastRun : null);
|
||||
const lastRunDate = $derived(current?.date ?? null);
|
||||
const lastStage = $derived(current?.stage ?? 0);
|
||||
const isWin = $derived(lastStage >= 4);
|
||||
|
||||
function retry() {
|
||||
|
|
|
|||
|
|
@ -13,10 +13,16 @@ const initial: Progress = typeof window === 'undefined' ? emptyProgress() : load
|
|||
|
||||
export const progress = writable<Progress>(initial);
|
||||
|
||||
// Letzter abgeschlossener Lauf — damit der ResultScreen genau diesen Versuch
|
||||
// hervorheben kann, auch wenn er nicht der beste ist.
|
||||
export const lastRun = writable<{ target: Target; stage: Stage; date: string } | null>(null);
|
||||
|
||||
progress.subscribe((p) => {
|
||||
if (typeof window !== 'undefined') saveProgress(p);
|
||||
});
|
||||
|
||||
export function recordResult(target: Target, stage: Stage): void {
|
||||
progress.update((p) => recordRun(p, target, stage));
|
||||
const date = new Date().toISOString();
|
||||
progress.update((p) => recordRun(p, target, stage, date));
|
||||
lastRun.set({ target, stage, date });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user