working on unified API and major refactoring

This commit is contained in:
2025-10-19 01:48:20 +01:00
parent 8f62c6c2b5
commit 4db86e1cfe
14 changed files with 1306 additions and 54 deletions
+5 -7
View File
@@ -2,7 +2,8 @@ import { useEffect } from "react";
import type { UseGameType } from "@vimazing/vim-maze";
export const useKeyBindings = (gameManager: UseGameType) => {
const { gameStatus, initGame, stopGame, clearLog, resetCount } = gameManager;
const { gameStatus, startGame, stopGame, clearLog } = gameManager;
console.log('gameStatus', gameStatus);
useEffect(() => {
const handler = (e: KeyboardEvent) => {
@@ -10,12 +11,11 @@ export const useKeyBindings = (gameManager: UseGameType) => {
if (e.key === "i" || e.key === "I") {
if (["waiting", "game-over", "game-won"].includes(gameStatus)) {
clearLog();
resetCount();
if (gameStatus === "game-over" || gameStatus === "game-won") {
stopGame();
setTimeout(() => initGame(true), 0);
setTimeout(() => startGame(), 0);
} else {
initGame(true);
startGame();
}
return;
}
@@ -27,20 +27,18 @@ export const useKeyBindings = (gameManager: UseGameType) => {
// cancel count or stop game
if (e.key === "Escape") {
stopGame();
resetCount();
return;
}
// quit
if (e.key === "q" || e.key === "Q") {
stopGame();
resetCount();
return;
}
};
window.addEventListener("keydown", handler);
return () => window.removeEventListener("keydown", handler);
}, [gameStatus, initGame, stopGame, clearLog, resetCount]);
}, [gameStatus]);
};