From f50bab76096386cb90bee0da0f076348d1ff0c09 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Sat, 28 Mar 2026 00:31:16 +0000 Subject: [PATCH] fix: prevent accidental new game start when mouse held during game end When the cursor is held down during gameplay and the game ends, releasing the mouse button would previously start a new game immediately. Now, a fresh click (pointerdown + pointerup) is required to start a new game from both the menu and gameover screens. Uses a freshClickRef to track whether pointerdown occurred in a non-playing phase before allowing pointerup to trigger a new game. Co-Authored-By: bot_apk --- src/DitherGame.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/DitherGame.tsx b/src/DitherGame.tsx index 1c03310..e68c140 100644 --- a/src/DitherGame.tsx +++ b/src/DitherGame.tsx @@ -74,6 +74,7 @@ export default function DitherGame() { const canvasRef = useRef(null); const stateRef = useRef(null); const gameRef = useRef(createGameState()); + const freshClickRef = useRef(false); const [uiState, setUiState] = useState<{ phase: GamePhase; @@ -446,6 +447,8 @@ export default function DitherGame() { if (game.phase === "playing") { game.charging = true; game.chargeStart = performance.now(); + } else if (game.phase === "menu" || game.phase === "gameover") { + freshClickRef.current = true; } if (!raf) raf = requestAnimationFrame(tick); }; @@ -456,7 +459,8 @@ export default function DitherGame() { const game = gameRef.current; const { x, y } = getLocalPos(e); - if (game.phase === "menu") { + if (game.phase === "menu" && freshClickRef.current) { + freshClickRef.current = false; gameRef.current = createGameState(); gameRef.current.phase = "playing"; setUiState((prev) => ({ @@ -480,7 +484,8 @@ export default function DitherGame() { } game.charging = false; game.chargeStart = 0; - } else if (game.phase === "gameover") { + } else if (game.phase === "gameover" && freshClickRef.current) { + freshClickRef.current = false; gameRef.current = createGameState(); gameRef.current.phase = "playing"; setUiState((prev) => ({