From b6f5d7ae9f7d1a8858337b990ee7591361e5fac5 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Sun, 19 Oct 2025 13:32:01 +0100 Subject: [PATCH] player moving, hjkl and counts... anchors not working yet --- src/useCursor/useGameKeys.ts | 2 +- src/useCursor/useHero.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/useCursor/useGameKeys.ts b/src/useCursor/useGameKeys.ts index 4263cb9..2b8aca2 100644 --- a/src/useCursor/useGameKeys.ts +++ b/src/useCursor/useGameKeys.ts @@ -112,7 +112,7 @@ export const useGameKeys = (props: UseGameKeysParams) => { window.addEventListener("keydown", handler); return () => window.removeEventListener("keydown", handler); - }, [gameStatus]); + }, [gameStatus, cursor, hero]); return { keyLog, diff --git a/src/useCursor/useHero.ts b/src/useCursor/useHero.ts index dfe9c75..1163ecf 100644 --- a/src/useCursor/useHero.ts +++ b/src/useCursor/useHero.ts @@ -39,7 +39,7 @@ export function useHero(board: BoardManager, gameStatusManager: GameStatusManage function moveTo(coord: Coord): void { if (!heroPos || !canMoveTo(coord)) return; - if (gameStatus !== "started" && gameStatus !== "has-key") return; + // Note: gameStatus check will be done in moveHero if (animation.isAnimating()) return; const m = mazeRef.current; @@ -114,6 +114,8 @@ export function useHero(board: BoardManager, gameStatusManager: GameStatusManage currentSetGameStatus: (s: GameStatus) => void ) { if (!heroPos) return; + if (currentGameStatus !== "started" && currentGameStatus !== "has-key") return; + if (animation.isAnimating()) return; const n = Math.max(1, steps ?? 1); const targetCoord = { @@ -126,9 +128,6 @@ export function useHero(board: BoardManager, gameStatusManager: GameStatusManage return; } - if (currentGameStatus !== "started" && currentGameStatus !== "has-key") return; - if (animation.isAnimating()) return; - const m = mazeRef.current; if (!m.length) return;