feat(phase2.1): track total keystrokes via keyLog length

- Expose keyLog.length as totalKeystrokes in ScoreManager
- Pass keyLog from useKeyBindings to useScore hook
- All game inputs (hjkl and platform keys) automatically counted
- Keystroke counter resets when keyLog is cleared (game restart)
This commit is contained in:
2025-10-30 23:55:15 +00:00
parent b59da4881d
commit 2a7162abf3
2 changed files with 5 additions and 4 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ export function useGame(optionsOrCols: GameOptions | number, rows?: number, plat
},
});
const scoreManager = useScore({ gameStatus });
const scoreManager = useScore({ gameStatus, keyLog: keyBindings.keyLog });
// Wrap renderBoard to match Unified API signature
const renderBoardWrapped = () => {
+4 -3
View File
@@ -1,12 +1,13 @@
import { useTimer } from "./hooks/useTimer";
import { useScoreTime } from "./useScoreTime";
import type { GameStatus } from "../types";
import type { GameStatus, KeyLogEntry } from "../types";
export type UseScoreParams = {
gameStatus: GameStatus;
keyLog: KeyLogEntry[];
};
export function useScore({ gameStatus }: UseScoreParams) {
export function useScore({ gameStatus, keyLog }: UseScoreParams) {
const timer = useTimer();
const { timeValue, startTimer, stopTimer, resetTimer } = timer;
@@ -14,7 +15,7 @@ export function useScore({ gameStatus }: UseScoreParams) {
return {
timeValue,
totalKeystrokes: 0, // TODO: Track from keyBindings
totalKeystrokes: keyLog.length,
finalScore: null, // TODO: Calculate on game-won
startTimer,
stopTimer,