Files
vim-maze/src/useGame.ts
T
pastilhas 7b0b8ee0aa feat: add runtime gameInfo enrichment with gameOver condition
- Add gameOverCondition to GameManager for runtime tracking
- Create enrichGameInfo() function to merge runtime condition with static gameInfo
- Add formatGameOverCondition() utility to stringify boolean/function conditions
- Returns enriched info with:
  - condition: formatted string representation
  - type: 'none' | 'static' | 'function'
- Platform can call enrichGameInfo(gameManager) to get complete game configuration
- Handles all condition types: undefined, boolean, function
- Truncates long function strings at 200 chars
2025-11-02 17:20:21 +00:00

37 lines
1.1 KiB
TypeScript

import type { GameManager, GameOptions } from './types';
import { useBoard } from './useBoard';
import { useCursor } from './useCursor';
import { useGameStatus } from './useGameStatus';
import { useHeroRender } from './useCursor';
import { useScore } from './useScore';
export function useGame(options: GameOptions, platformHook?: unknown): GameManager {
const { cols, rows, gameOver } = options;
const board = useBoard(cols, rows);
const { containerRef, renderBoard } = board;
const gameStatusManager = useGameStatus();
const { keyManager, ...cursor } = useCursor(board, gameStatusManager);
const hero = cursor.hero;
const renderer = useHeroRender({ gameStatus: gameStatusManager.gameStatus, board, hero });
const scoreManager = useScore({ board, hero, gameStatusManager, keyManager, gameOver });
const gameManager: GameManager = {
containerRef,
...keyManager,
...gameStatusManager,
renderBoard,
cursor,
hero,
renderer,
scoreManager,
gameOverCondition: gameOver,
}
if (typeof platformHook === 'function') {
platformHook(gameManager);
}
return gameManager;
}