diff --git a/src/App.svelte b/src/App.svelte index 09b8a59..41b2f50 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -2,6 +2,7 @@ import Grid from './components/Grid.svelte'; import ScoreBoard from './components/ScoreBoard.svelte'; import GameMessage from './components/GameMessage.svelte'; + import { untrack } from 'svelte'; import { initGame, move, isGameOver } from './lib/game-logic.js'; import { GRID_SIZE } from './lib/constants.js'; import { getDirectionFromKey, getDirectionFromSwipe } from './lib/input-handler.js'; @@ -27,9 +28,14 @@ }); $effect(() => { - if (gameState.score > bestScore) { - bestScore = gameState.score; + const score = gameState.score; + const best = untrack(() => bestScore); + if (score > best) { + bestScore = score; } + }); + + $effect(() => { saveBestScore(bestScore); }); diff --git a/src/components/ScoreBoard.svelte b/src/components/ScoreBoard.svelte index ebca622..3bc890d 100644 --- a/src/components/ScoreBoard.svelte +++ b/src/components/ScoreBoard.svelte @@ -1,4 +1,6 @@