From dd0df64d769a3709a04412700c24929895daca9f Mon Sep 17 00:00:00 2001 From: jay Date: Fri, 12 Jun 2026 13:35:20 -0400 Subject: [PATCH] Games: cross-device sync + overlap colour-blend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two game polish items: - Word Search: overlapping cells now multiply-blend the crossing words' colours (deepening to a darker shade with readable text) instead of the newest colour stomping the rest — matches the new interlocking grids. - Cross-device game-state sync (signed-in): per-puzzle progress + stats now follow you between devices. New game_state table; server-side merge on every save so two devices converge regardless of push order, tailored per game: * Word Search → UNION of finds (monotonic; can't un-find), earliest start, best completion time. * Word → furthest-progress wins (terminal beats in-progress; more guesses beats fewer) — picks one device's game whole, never splices guesses. Stats (streak/distribution/best) derived server-side from the synced states, so they're consistent instead of per-device counters. Endpoints GET/PUT /api/games/state + GET /api/games/stats (signed-in; size-capped). Frontend is local-first: games paint instantly from localStorage, then reconcile in the background; both game components push debounced on each move and adopt the merge. Conflict handling unit-tested + an API two-device convergence test. 235→ tests + 11 vitest green. Co-Authored-By: Claude Opus 4.8 --- frontend/src/lib/components/WordGame.svelte | 28 +++++ .../src/lib/components/WordSearchGame.svelte | 73 ++++++++++-- frontend/src/lib/gamesync.js | 30 +++++ goodnews/api.py | 43 +++++++ goodnews/db.py | 10 ++ goodnews/games.py | 105 ++++++++++++++++++ tests/test_game_sync.py | 101 +++++++++++++++++ 7 files changed, 380 insertions(+), 10 deletions(-) create mode 100644 frontend/src/lib/gamesync.js create mode 100644 tests/test_game_sync.py diff --git a/frontend/src/lib/components/WordGame.svelte b/frontend/src/lib/components/WordGame.svelte index 98302f9..47c9780 100644 --- a/frontend/src/lib/components/WordGame.svelte +++ b/frontend/src/lib/components/WordGame.svelte @@ -1,5 +1,6 @@