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);
|
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 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) => {
|
const merged = [...prev.top5, next].sort((a, b) => {
|
||||||
if (b.stage !== a.stage) return b.stage - a.stage;
|
if (b.stage !== a.stage) return b.stage - a.stage;
|
||||||
return b.date.localeCompare(a.date);
|
return b.date.localeCompare(a.date);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { fade, fly } from 'svelte/transition';
|
import { fade, fly } from 'svelte/transition';
|
||||||
import type { Target } from '../game/tasks';
|
import type { Target } from '../game/tasks';
|
||||||
import { progress } from '../stores/progress';
|
import { lastRun } from '../stores/progress';
|
||||||
import { startGame } from '../stores/game';
|
import { startGame } from '../stores/game';
|
||||||
import { goHome, goGame } from '../stores/route';
|
import { goHome, goGame } from '../stores/route';
|
||||||
import { play, unlockAudio } from '../audio/soundManager';
|
import { play, unlockAudio } from '../audio/soundManager';
|
||||||
|
|
@ -12,9 +12,10 @@
|
||||||
type Props = { target: Target };
|
type Props = { target: Target };
|
||||||
let { target }: Props = $props();
|
let { target }: Props = $props();
|
||||||
|
|
||||||
// Aktueller Run = top-Eintrag mit dem letzten Datum
|
// Genau der gerade gespielte Lauf (kann auch ein nicht-bester Versuch sein).
|
||||||
const lastRunDate = $derived($progress.perTarget[target]?.top5[0]?.date ?? null);
|
const current = $derived($lastRun?.target === target ? $lastRun : null);
|
||||||
const lastStage = $derived(($progress.perTarget[target]?.top5[0]?.stage ?? 0) as number);
|
const lastRunDate = $derived(current?.date ?? null);
|
||||||
|
const lastStage = $derived(current?.stage ?? 0);
|
||||||
const isWin = $derived(lastStage >= 4);
|
const isWin = $derived(lastStage >= 4);
|
||||||
|
|
||||||
function retry() {
|
function retry() {
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,16 @@ const initial: Progress = typeof window === 'undefined' ? emptyProgress() : load
|
||||||
|
|
||||||
export const progress = writable<Progress>(initial);
|
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) => {
|
progress.subscribe((p) => {
|
||||||
if (typeof window !== 'undefined') saveProgress(p);
|
if (typeof window !== 'undefined') saveProgress(p);
|
||||||
});
|
});
|
||||||
|
|
||||||
export function recordResult(target: Target, stage: Stage): void {
|
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