From d1eb2d070652025f0753d1dd83b9aeb9db51d535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Sat, 22 Aug 2026 19:56:26 +0200 Subject: [PATCH] feat(web): add click-only interaction --- web/src/App.svelte | 94 +++++++++++++++++--------- web/src/components/SolverOutput.svelte | 9 +++ web/src/components/WordleLine.svelte | 14 +++- 3 files changed, 83 insertions(+), 34 deletions(-) diff --git a/web/src/App.svelte b/web/src/App.svelte index b66f846..5be8643 100644 --- a/web/src/App.svelte +++ b/web/src/App.svelte @@ -40,10 +40,21 @@ let best_words: Promise | null = $state(null); let best_words_progress: EvaluateWordsProgress | null = $state(null); + let solving: boolean = $state(false); - let w_lines: WordleLine[] = []; + let w_lines: WordleLine[] = $state([]); let cursor = $state(0); + async function toggleSolver() { + if (solving) { + await stopSolver(); + } else { + best_words = solver_evaluate_words(5, (p) => { + best_words_progress = p; + }); + } + } + async function reset() { await solver_reset(use_default_wordle_answers); @@ -73,6 +84,38 @@ } } + async function doGuess() { + const guess = guesses[guesses.length - 1]; + + if (guess.letters.join("").length != 5) { + return; + } + + infos_gained[infos_gained.length - 1] = solver_guess( + guess.letters, + guess.colors, + ); + infos_gained.push(null); + solution_space = solver_solution_space(); + + cursor = 0; + + guesses.push({ + letters: ["", "", "", "", ""], + colors: [ + Color.GREY, + Color.GREY, + Color.GREY, + Color.GREY, + Color.GREY, + ], + }); + + await tick(); + + w_lines[w_lines.length - 1].focus(); + } + async function handleKey(event: KeyboardEvent) { if (/^[a-zA-Z ]$/.test(event.key)) { w_lines[guesses.length - 1].focus(); @@ -85,35 +128,7 @@ } else if (event.key === "Escape") { await stopSolver(); } else if (event.key === "Enter") { - const guess = guesses[guesses.length - 1]; - - if (guess.letters.join("").length != 5) { - return; - } - - infos_gained[infos_gained.length - 1] = solver_guess( - guess.letters, - guess.colors, - ); - infos_gained.push(null); - solution_space = solver_solution_space(); - - cursor = 0; - - guesses.push({ - letters: ["", "", "", "", ""], - colors: [ - Color.GREY, - Color.GREY, - Color.GREY, - Color.GREY, - Color.GREY, - ], - }); - - await tick(); - - w_lines[w_lines.length - 1].focus(); + await doGuess(); } } @@ -168,6 +183,7 @@ {#each guesses as g, i (g)} -

+

Type letters · ← → navigate · Space cycle color · Backspace delete · Enter apply · Shift+Enter solve · Escape abort solver · Ctrl+Esc reset

+ {#if best_words} { - console.log("CB"); guesses[guesses.length - 1].letters = g; }} + bind:solving /> {/if} diff --git a/web/src/components/SolverOutput.svelte b/web/src/components/SolverOutput.svelte index 0c1bcf5..cb9f1cc 100644 --- a/web/src/components/SolverOutput.svelte +++ b/web/src/components/SolverOutput.svelte @@ -10,12 +10,21 @@ data, progress = null, insert_guess = null, + solving = $bindable(true), }: { data: Promise; progress: EvaluateWordsProgress | null; insert_guess: ((word: string[]) => void) | null; + solving: boolean; } = $props(); + $effect(() => { + solving = true; + data.finally(() => { + solving = false; + }); + }); + function renderMath(txt: string | null) { return (element: HTMLElement) => { if (txt) { diff --git a/web/src/components/WordleLine.svelte b/web/src/components/WordleLine.svelte index 28d43ec..fdb76a2 100644 --- a/web/src/components/WordleLine.svelte +++ b/web/src/components/WordleLine.svelte @@ -1,5 +1,6 @@