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
|
// Wrap renderBoard to match Unified API signature
|
||||||
const renderBoardWrapped = () => {
|
const renderBoardWrapped = () => {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { useTimer } from "./hooks/useTimer";
|
import { useTimer } from "./hooks/useTimer";
|
||||||
import { useScoreTime } from "./useScoreTime";
|
import { useScoreTime } from "./useScoreTime";
|
||||||
import type { GameStatus } from "../types";
|
import type { GameStatus, KeyLogEntry } from "../types";
|
||||||
|
|
||||||
export type UseScoreParams = {
|
export type UseScoreParams = {
|
||||||
gameStatus: GameStatus;
|
gameStatus: GameStatus;
|
||||||
|
keyLog: KeyLogEntry[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useScore({ gameStatus }: UseScoreParams) {
|
export function useScore({ gameStatus, keyLog }: UseScoreParams) {
|
||||||
const timer = useTimer();
|
const timer = useTimer();
|
||||||
const { timeValue, startTimer, stopTimer, resetTimer } = timer;
|
const { timeValue, startTimer, stopTimer, resetTimer } = timer;
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ export function useScore({ gameStatus }: UseScoreParams) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
timeValue,
|
timeValue,
|
||||||
totalKeystrokes: 0, // TODO: Track from keyBindings
|
totalKeystrokes: keyLog.length,
|
||||||
finalScore: null, // TODO: Calculate on game-won
|
finalScore: null, // TODO: Calculate on game-won
|
||||||
startTimer,
|
startTimer,
|
||||||
stopTimer,
|
stopTimer,
|
||||||
|
|||||||
Reference in New Issue
Block a user