working on unified API and major refactoring
This commit is contained in:
@@ -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]);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user