From 9e19931d8b01f11d6ae6a73bce5ef70b1b0f716b Mon Sep 17 00:00:00 2001 From: Yuriy Mayatnikov Date: Sat, 27 Jun 2026 11:15:18 +0300 Subject: [PATCH] Add preserved-progress main menu flow --- src/lib/components/GameResult.svelte | 9 +- src/lib/components/HostControls.svelte | 10 +-- src/lib/components/QuestionSetSelector.svelte | 82 +++++++++++++++++- src/routes/+page.svelte | 83 +++++++++++++++---- 4 files changed, 155 insertions(+), 29 deletions(-) diff --git a/src/lib/components/GameResult.svelte b/src/lib/components/GameResult.svelte index ce2726a..840692a 100644 --- a/src/lib/components/GameResult.svelte +++ b/src/lib/components/GameResult.svelte @@ -3,10 +3,11 @@ score: number; playedCount: number; onPlayAgain: () => void; - onChangeSet: () => void; + /** Вернуться в главное меню, не сбрасывая прогресс сразу. */ + onMainMenu: () => void; } - let { score, playedCount, onPlayAgain, onChangeSet }: Props = $props(); + let { score, playedCount, onPlayAgain, onMainMenu }: Props = $props(); // Мягкая финальная фраза в зависимости от результата. const finalPhrase = $derived.by(() => { @@ -66,10 +67,10 @@ diff --git a/src/lib/components/HostControls.svelte b/src/lib/components/HostControls.svelte index 3faf726..7ea12bf 100644 --- a/src/lib/components/HostControls.svelte +++ b/src/lib/components/HostControls.svelte @@ -6,11 +6,11 @@ played: QuestionRef[]; onRandom: () => void; onNewGame: () => void; - /** Полный сброс к экрану выбора набора. */ - onChangeSet: () => void; + /** Открыть главное меню (выбор набора), не сбрасывая прогресс. */ + onMainMenu: () => void; } - let { set, played, onRandom, onNewGame, onChangeSet }: Props = $props(); + let { set, played, onRandom, onNewGame, onMainMenu }: Props = $props(); /** Есть ли ещё несыгранные вопросы (для кнопки «Случайный вопрос»). */ const hasUnplayed = $derived( @@ -38,9 +38,9 @@ diff --git a/src/lib/components/QuestionSetSelector.svelte b/src/lib/components/QuestionSetSelector.svelte index 8a549c0..d1dfd69 100644 --- a/src/lib/components/QuestionSetSelector.svelte +++ b/src/lib/components/QuestionSetSelector.svelte @@ -5,11 +5,34 @@ interface Props { sets: QuestionSet[]; onSelect: (id: string) => void; + /** Текущий сохранённый набор (если есть) — для блока «Продолжить партию». */ + currentSet?: QuestionSet | null; + /** Счёт сохранённой партии. */ + currentScore?: number; + /** Сыграно вопросов в сохранённой партии. */ + currentPlayedCount?: number; + /** Всего вопросов в сохранённой партии. */ + currentTotalCount?: number; + /** Продолжить текущую партию (закрыть главное меню без сброса). */ + onContinue?: () => void; } - let { sets, onSelect }: Props = $props(); + let { + sets, + onSelect, + currentSet = null, + currentScore = 0, + currentPlayedCount = 0, + currentTotalCount = 0, + onContinue + }: Props = $props(); let hovered = $state(null); + + // Прогресс сохранённой партии в процентах — для полоски в блоке «Продолжить». + const continuePct = $derived( + currentTotalCount > 0 ? Math.round((currentPlayedCount / currentTotalCount) * 100) : 0 + );
@@ -29,15 +52,59 @@

+ {#if currentSet} + +
+
+
+
+ ▶️ Сохранённая партия +
+

+ {currentSet.title} +

+
+ ⭐ {(currentScore ?? 0).toLocaleString('ru-RU')} + 🎯 {currentPlayedCount ?? 0} из {currentTotalCount ?? 0} +
+
+
+
+
+ +
+
+ {/if} +
{#each sets as set, i (set.id)} + {@const isCurrent = currentSet?.id === set.id}