refactor: implement clean architecture with separation of concerns

- Add useMazeNavigation for pure maze geometry and path validation
- Add useVimMotions for pure Vim-style input parsing
- Add useAnimation for pure movement animation system
- Refactor useCursor to use specialized hooks with cleaner interface
- Refactor useHero to pure game logic without DOM manipulation
- Refactor useHeroRender to pure visual presentation layer
- Fix dual position system - hero position now authoritative
- Replace global events with callback props and return values
- Implement state-driven rendering instead of direct DOM queries
- Update GameManager interface with new HeroManager and HeroRenderer
- Maintain backward compatibility with legacy Cursor type
- Update UNIFIED_API.md with new architecture and interfaces
This commit is contained in:
2025-10-19 13:27:35 +01:00
parent 2c7816306c
commit 70a8167fb0
12 changed files with 1012 additions and 338 deletions
+6
View File
@@ -2,6 +2,7 @@ import type { GameManager, GameOptions } from './types';
import { useBoard } from './useBoard';
import { useCursor } from './useCursor';
import { useGameStatus } from './useGameStatus';
import { useHeroRender } from './useCursor';
export function useGame(options: GameOptions, platformHook?: unknown): GameManager {
const { cols, rows } = options;
@@ -9,6 +10,9 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
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 gameManager = {
containerRef,
@@ -16,6 +20,8 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
...gameStatusManager,
renderBoard,
cursor,
hero,
renderer,
}
if (typeof platformHook === 'function') {