fix: cursor now shows immediately on game start
Added boardRendered counter to track when board DOM is rebuilt: - Increments after each renderBoard() call - useCursorRender depends on boardRendered - Forces cursor re-application after board rebuilds DOM Flow: 1. Game starts 2. renderBoard() rebuilds DOM 3. boardRendered increments 4. useCursorRender triggers 5. Cursor class applied to (0,0) This ensures cursor is visible immediately when pressing Space.
This commit is contained in:
+7
-3
@@ -13,23 +13,27 @@ export function useGame(options: GameOptions = {}, platformHook?: unknown): Game
|
||||
const gameStatusManager = useGameStatus();
|
||||
const { gameStatus } = gameStatusManager;
|
||||
|
||||
const [keyLog, setKeyLog] = useState<{ key: string; timestamp: number }[]>([]);
|
||||
const [boardRendered, setBoardRendered] = useState(0);
|
||||
|
||||
const cursor = useCursor(gameStatusManager);
|
||||
const cursorPosition = cursor.position();
|
||||
|
||||
useCursorRender(containerRef, cursorPosition, gameStatus);
|
||||
|
||||
const [keyLog, setKeyLog] = useState<{ key: string; timestamp: number }[]>([]);
|
||||
useCursorRender(containerRef, cursorPosition, gameStatus, boardRendered);
|
||||
|
||||
useEffect(() => {
|
||||
renderBoard();
|
||||
setBoardRendered(prev => prev + 1);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (gameStatus === 'started') {
|
||||
generateBoard(difficulty);
|
||||
renderBoard();
|
||||
setBoardRendered(prev => prev + 1);
|
||||
} else if (gameStatus === 'waiting') {
|
||||
renderBoard();
|
||||
setBoardRendered(prev => prev + 1);
|
||||
}
|
||||
}, [gameStatus, difficulty]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user