feat: implement Phase 30 - useGameStatus hook
Extract game status logic into dedicated hook following vim-maze pattern: New Module Structure: - src/useGameStatus/types.ts: GameStatus and GameStatusManager types - src/useGameStatus/useGameStatus.ts: Hook implementation - src/useGameStatus/index.ts: Public exports Hook Implementation: - State machine with 5 states (waiting/started/paused/game-over/game-won) - Methods: startGame, togglePause, quitGame, setGameStatus - Clean state transitions with useState - Simpler than vim-maze (no intermediate 'has-key' state) Updated Core Files: - src/useGame.ts: Use useGameStatus() instead of inline useState - Compose gameStatusManager into GameManager - Cleaner separation of concerns - src/types.ts: Import and re-export GameStatus types - GameManager extends GameStatusManager (intersection type) - Single source of truth for status types - src/index.ts: Export useGameStatus hook publicly Benefits: - Reusable state machine - Easier to test in isolation - Follows unified API architecture - Matches vim-maze patterns State Transitions: waiting → startGame() → started ↔ togglePause() ↔ paused started → (win/lose) → game-won/game-over * → quitGame() → waiting Phase 30 complete. Next: Phase 40 (useCursor composition).
This commit is contained in:
@@ -93,10 +93,12 @@ src/
|
||||
|
||||
### Phase 30: useGameStatus Hook
|
||||
|
||||
- [ ] Implement GameStatus state machine
|
||||
- [x] Implement GameStatus state machine
|
||||
- 'waiting' → 'started' → 'game-won' / 'game-over'
|
||||
- 'paused' state support
|
||||
- [ ] Methods: startGame, togglePause, quitGame, setGameStatus
|
||||
- [x] Methods: startGame, togglePause, quitGame, setGameStatus
|
||||
- [x] Extract from inline useState in useGame
|
||||
- [x] Create dedicated hook following vim-maze pattern
|
||||
|
||||
### Phase 40: useCursor Hook Composition
|
||||
|
||||
|
||||
Reference in New Issue
Block a user