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:
@@ -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 = () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user