From a69b7bbb5f80f217479583ecc6c35f24d5034046 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Sun, 19 Oct 2025 16:11:38 +0100 Subject: [PATCH] organized types --- UNIFIED_API.md | 43 +++++-- example/src/App.tsx | 2 - example/src/useMounted.ts | 11 -- src/types.ts | 176 +++-------------------------- src/useBoard/MazeGenerator.ts | 2 +- src/useBoard/MazeRenderer.ts | 2 +- src/useBoard/index.ts | 1 + src/useBoard/types.ts | 32 ++++++ src/useBoard/useBoard.ts | 2 +- src/useBoard/useMazeNavigation.ts | 4 +- src/useCursor/index.ts | 1 + src/useCursor/types.ts | 74 ++++++++++++ src/useCursor/useAnimation.ts | 4 +- src/useCursor/useCursor.ts | 4 +- src/useCursor/useGameKeys.ts | 4 +- src/useCursor/useHero.ts | 4 +- src/useCursor/useHeroRender.ts | 6 +- src/useCursor/useVimMotions.ts | 6 +- src/useGameStatus/index.ts | 1 + src/useGameStatus/types.ts | 9 ++ src/useGameStatus/useGameStatus.ts | 3 +- src/useScore/index.ts | 1 + src/useScore/types.ts | 26 +++++ src/useScore/useScore.ts | 4 +- src/useScore/useScorePaths.ts | 5 +- src/useScore/useScoreTime.ts | 3 +- src/useScore/useTimer.ts | 4 +- 27 files changed, 231 insertions(+), 203 deletions(-) delete mode 100644 example/src/useMounted.ts create mode 100644 src/useBoard/types.ts create mode 100644 src/useCursor/types.ts create mode 100644 src/useGameStatus/types.ts create mode 100644 src/useScore/types.ts diff --git a/UNIFIED_API.md b/UNIFIED_API.md index 9b14f73..ead3e5b 100644 --- a/UNIFIED_API.md +++ b/UNIFIED_API.md @@ -59,18 +59,22 @@ return { ``` src/ ├── index.ts # Main package exports -├── types.ts # All shared TypeScript types +├── types.ts # Re-exports all types from modules, useGame-specific types ├── useGame.ts # Main orchestrator hook ├── useGameStatus/ +│ ├── index.ts # Public exports +│ ├── types.ts # GameStatus, GameStatusManager │ └── useGameStatus.ts # Game state management ├── useBoard/ │ ├── index.ts # Public exports +│ ├── types.ts # Coord, MazeCell, MazeData, BoardManager, MazeNavigator │ ├── useBoard.ts # Board/maze management hook │ ├── MazeGenerator.ts # Maze generation algorithm │ ├── MazeRenderer.ts # DOM rendering for maze │ └── useMazeNavigation.ts # Pathfinding and validation ├── useCursor/ │ ├── index.ts # Public exports +│ ├── types.ts # CursorMode, CursorManager, HeroManager, Motion, AnimationSystem, VimMotionSystem │ ├── useCursor.ts # Main cursor/input hook │ ├── useHero.ts # Player position and movement │ ├── useHeroRender.ts # Hero rendering on DOM @@ -79,6 +83,7 @@ src/ │ └── useAnimation.ts # Multi-step movement animation └── useScore/ ├── index.ts # Public exports + ├── types.ts # TimerManager, ScorePathsResult, ScoreManager ├── useScore.ts # Main scoring hook ├── useScorePaths.ts # Distance calculations ├── useScoreTime.ts # Timer integration @@ -89,7 +94,15 @@ src/ ## Type System -All types are centralized in `src/types.ts` for consistency and maintainability. +Types are organized by module for clarity and maintainability: + +- **`src/useBoard/types.ts`**: Board, maze, and navigation types +- **`src/useCursor/types.ts`**: Cursor, hero, vim motions, and animation types +- **`src/useGameStatus/types.ts`**: Game status and lifecycle types +- **`src/useScore/types.ts`**: Scoring and timer types +- **`src/types.ts`**: Re-exports all module types + useGame-specific types (GameOptions, GameKeyManager, GameManager) + +This modular organization keeps types colocated with their related hooks while maintaining a unified `src/types.ts` entry point for convenience. ### Main Types @@ -938,13 +951,28 @@ Rendering updates via refs ### Hook Return Types -All hook return types are explicitly defined in `src/types.ts`. Import them directly: +All hook return types are explicitly defined and organized by module: ```typescript +// Import from main types.ts (re-exports all modules) import type { GameManager, CursorManager, ScoreManager } from './types'; import type { TimerManager, HeroRenderManager, AnimationSystem } from './types'; +import type { BoardManager, Coord } from './types'; +import type { GameStatus, GameStatusManager } from './types'; + +// Or import directly from module types for clarity +import type { CursorManager } from './useCursor/types'; +import type { BoardManager } from './useBoard/types'; +import type { ScoreManager } from './useScore/types'; ``` +### Type Organization + +- **Module-local types**: Defined in each hook's `types.ts` file +- **Cross-module types**: Imported as needed within modules +- **Public API types**: Re-exported through `src/types.ts` +- **useGame-specific types**: Defined in main `src/types.ts` (GameOptions, GameKeyManager, GameManager) + ### Type Imports Always import types with `import type`: @@ -979,9 +1007,10 @@ const same = pos1.row === pos2.row && pos1.col === pos2.col; The vim-maze unified API provides a composable, type-safe game engine: - **Single Entry Point**: `useGame()` for all initialization -- **Modular Design**: Independent, reusable hooks -- **Type Safe**: Comprehensive TypeScript support +- **Modular Design**: Independent, reusable hooks with colocated types +- **Type Safe**: Comprehensive TypeScript support with explicit type definitions +- **Organized Types**: Types organized by module with main `types.ts` re-exporting all - **Extensible**: Platform hook system for customization -- **Well Structured**: Clear separation of concerns +- **Well Structured**: Clear separation of concerns with intuitive file structure -For detailed implementation, refer to source files in `src/`. +For detailed implementation, refer to source files in `src/`. Each module's `types.ts` provides the interface definitions for that domain. diff --git a/example/src/App.tsx b/example/src/App.tsx index 4339d62..6edfe27 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,12 +1,10 @@ import { useGame } from "../../src/useGame"; import { useKeyBindings } from "./useKeyBindings"; -import { useMounted } from "./useMounted"; import { useIsMobile } from "./useIsMobile"; import '../../src/game.css'; function App() { const isMobile = useIsMobile(); - const mounted = useMounted(); const cols = isMobile ? 12 : 32; const rows = isMobile ? 8 : 24; diff --git a/example/src/useMounted.ts b/example/src/useMounted.ts deleted file mode 100644 index 7da354e..0000000 --- a/example/src/useMounted.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useState, useEffect } from 'react'; - -export const useMounted = () => { - const [mounted, setMounted] = useState(false); - - useEffect(() => { - setMounted(true); - }, []); - - return mounted; -}; diff --git a/src/types.ts b/src/types.ts index 9d84b02..4439d32 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,48 +1,12 @@ import type { RefObject } from 'react'; -import { MazeRenderer, MazeGenerator } from "./useBoard"; -export * from './useGame'; -export * from './useBoard'; -export * from './useCursor'; -export * from './useScore'; - -export type GameStatus = 'waiting' | 'started' | 'has-key' | 'paused' | 'game-over' | 'game-won' - -export type GameManager = { - containerRef: RefObject; - renderBoard: () => void; - cursor: CursorManager; - hero: HeroManager; - renderer: HeroRenderer; - scoreManager: ScoreManager; -} & GameStatusManager & GameKeyManager; - - -export type BoardManager = { - containerRef: RefObject - mazeRef: RefObject - mazeInstanceRef: RefObject - rendererRef: RefObject - renderBoard: () => void -} - - -export type PositionTag = "entrance" | "exit" | "key" | "hero"; - -export type Coord = { row: number, col: number }; - -export type CellTag = "wall" | "door" | PositionTag; - -export type MazeCell = CellTag[]; - -export type MazeData = { - maze: MazeCell[][]; - width: number; - height: number; - cols: number; - rows: number; - totalSteps: number; -} +import type { CursorManager, HeroManager, HeroRenderManager } from './useCursor/types'; +import type { GameStatusManager } from './useGameStatus/types'; +import type { ScoreManager } from './useScore/types'; +export * from './useBoard/types'; +export * from './useCursor/types'; +export * from './useGameStatus/types'; +export * from './useScore/types'; export type GameOptions = { rows: number; @@ -57,121 +21,11 @@ export type GameKeyManager = { getKeyLog: () => KeyLogEntry[]; }; -export type GameStatusManager = { - gameStatus: GameStatus; - setGameStatus: (status: GameStatus) => void; - startGame: () => void; - togglePause: (pause?: boolean) => void; - quitGame: () => void; -}; - -//Cursor Stuff -export type CursorMode = 'normal' | 'insert' | 'replace' | 'visual' | 'visual-line'; - -export type UseHeroType = { - position: Coord | null; - canMoveTo: (coord: Coord) => boolean; - moveTo: (coord: Coord) => void; - pickupKey: () => void; - reachExit: () => void; - reset: () => void; - heroPos: Coord | null; - setHeroPos: (pos: Coord | null) => void; - moveHero: (dr: number, dc: number, steps: number, gameStatus: GameStatus, setGameStatus: (s: GameStatus) => void) => void; -}; - -export type CursorManager = { - position: () => Coord; - mode: () => CursorMode; - move: (dCols: number, dRows: number, count: number) => void; - moveLeft: (count?: number) => void; - moveRight: (count?: number) => void; - moveUp: (count?: number) => void; - moveDown: (count?: number) => void; - moveToStart: () => void; - moveToEnd: () => void; - moveToTop: () => void; - moveToBottom: () => void; - repeatLastMotion: () => void; - resetCount: () => void; - getCount: () => string; - hasCount: () => boolean; - setCount: (digit: string) => void; - setLastKey: (key: string) => void; - getLastKey: () => string; - hero?: UseHeroType; -} - -export type HeroManager = { - position: Coord | null; - canMoveTo: (coord: Coord) => boolean; - moveTo: (coord: Coord) => void; - pickupKey: () => void; - reachExit: () => void; - reset: () => void; -} - -export type HeroRenderer = { - render: () => void; - updatePosition: (coord: Coord) => void; - showCoordinates: (show: boolean) => void; -} - -// Legacy type for backward compatibility -export type Cursor = CursorManager; - -export type Motion = { dr: number; dc: number; steps: number }; - -export type VimMotionSystem = { - processKey: (key: string) => { type: 'move'|'anchor'|'repeat'|'count', data: any } | null; - resetCount: () => void; - getCount: () => number; - hasCount: () => boolean; - setLastMotion: (motion: Motion) => void; - repeatLastMotion: () => Motion | null; -}; - -export type AnimationSystem = { - animateMovement: (from: Coord, to: Coord, steps: number, onStep: (coord: Coord) => void, onComplete: () => void) => void; - cancelAnimation: () => void; - isAnimating: () => boolean; -}; - -export type MazeNavigator = { - isValidMove: (from: Coord, to: Coord) => boolean; - findAnchorTarget: (from: Coord, direction: 'left'|'right'|'top'|'bottom') => Coord | null; - validatePath: (from: Coord, direction: Coord, steps: number) => boolean; -}; - -export type HeroRenderManager = { - render: () => void; - updatePosition: (coord: Coord) => void; - showCoordinates: (show: boolean) => void; -}; - -export type TimerManager = { - timeValue: number; - startTimer: () => void; - stopTimer: () => void; - resetTimer: () => void; -}; - -export type ScorePathsResult = { - entranceToKey: number; - entranceToExit: number; - heroToKey: number; - heroToExit: number; -}; - -export type ScoreManager = { - timeValue: number; - startTimer: () => void; - stopTimer: () => void; - resetTimer: () => void; - distToKey: number; - distToExit: number; - keystrokes: number; - optimalSteps: number; - efficiency: number; - finalScore: number | null; -}; +export type GameManager = { + containerRef: RefObject; + renderBoard: () => void; + cursor: CursorManager; + hero: HeroManager; + renderer: HeroRenderManager; + scoreManager: ScoreManager; +} & GameStatusManager & GameKeyManager; diff --git a/src/useBoard/MazeGenerator.ts b/src/useBoard/MazeGenerator.ts index fe9a8b4..ccab1c6 100644 --- a/src/useBoard/MazeGenerator.ts +++ b/src/useBoard/MazeGenerator.ts @@ -1,4 +1,4 @@ -import type { PositionTag, Coord, CellTag, MazeCell, MazeData } from "../types"; +import type { PositionTag, Coord, CellTag, MazeCell, MazeData } from "./types"; export class MazeGenerator { width: number; diff --git a/src/useBoard/MazeRenderer.ts b/src/useBoard/MazeRenderer.ts index b8fcc35..066e00c 100644 --- a/src/useBoard/MazeRenderer.ts +++ b/src/useBoard/MazeRenderer.ts @@ -1,4 +1,4 @@ -import type { MazeData } from "../types"; +import type { MazeData } from "./types"; export class MazeRenderer { private mazeData: MazeData; diff --git a/src/useBoard/index.ts b/src/useBoard/index.ts index 82f2a4b..8c6b31a 100644 --- a/src/useBoard/index.ts +++ b/src/useBoard/index.ts @@ -2,3 +2,4 @@ export * from './useBoard'; export * from './MazeGenerator'; export * from './MazeRenderer'; export * from './useMazeNavigation'; +export * from './types'; diff --git a/src/useBoard/types.ts b/src/useBoard/types.ts new file mode 100644 index 0000000..b573977 --- /dev/null +++ b/src/useBoard/types.ts @@ -0,0 +1,32 @@ +import type { RefObject } from 'react'; + +export type PositionTag = "entrance" | "exit" | "key" | "hero"; + +export type Coord = { row: number; col: number }; + +export type CellTag = "wall" | "door" | PositionTag; + +export type MazeCell = CellTag[]; + +export type MazeData = { + maze: MazeCell[][]; + width: number; + height: number; + cols: number; + rows: number; + totalSteps: number; +}; + +export type BoardManager = { + containerRef: RefObject; + mazeRef: RefObject; + mazeInstanceRef: RefObject; + rendererRef: RefObject; + renderBoard: () => void; +}; + +export type MazeNavigator = { + isValidMove: (from: Coord, to: Coord) => boolean; + findAnchorTarget: (from: Coord, direction: 'left' | 'right' | 'top' | 'bottom') => Coord | null; + validatePath: (from: Coord, direction: Coord, steps: number) => boolean; +}; diff --git a/src/useBoard/useBoard.ts b/src/useBoard/useBoard.ts index a57f049..561a905 100644 --- a/src/useBoard/useBoard.ts +++ b/src/useBoard/useBoard.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from "react"; import { MazeGenerator } from "./MazeGenerator"; import { MazeRenderer } from "./MazeRenderer"; -import type { MazeCell } from "../types"; +import type { MazeCell } from "./types"; export function useBoard(cols: number, rows: number) { const containerRef = useRef(null); diff --git a/src/useBoard/useMazeNavigation.ts b/src/useBoard/useMazeNavigation.ts index 19edd66..f2f43b7 100644 --- a/src/useBoard/useMazeNavigation.ts +++ b/src/useBoard/useMazeNavigation.ts @@ -1,6 +1,6 @@ -import type { Coord, MazeCell, MazeNavigator } from '../types'; +import type { Coord, MazeCell, MazeNavigator } from './types'; -export type { MazeNavigator } from '../types'; +export type { MazeNavigator } from './types'; export function useMazeNavigation(maze: MazeCell[][]): MazeNavigator { function isValidMove(_from: Coord, to: Coord): boolean { diff --git a/src/useCursor/index.ts b/src/useCursor/index.ts index 086dc1a..3b53b5e 100644 --- a/src/useCursor/index.ts +++ b/src/useCursor/index.ts @@ -1,3 +1,4 @@ +export * from './types'; export * from './useCursor'; export * from './useHero'; export * from './useHeroRender'; diff --git a/src/useCursor/types.ts b/src/useCursor/types.ts new file mode 100644 index 0000000..7aa2140 --- /dev/null +++ b/src/useCursor/types.ts @@ -0,0 +1,74 @@ +import type { Coord } from '../useBoard/types'; +import type { GameStatus } from '../useGameStatus/types'; + +export type { Coord } from '../useBoard/types'; + +export type CursorMode = 'normal' | 'insert' | 'replace' | 'visual' | 'visual-line'; + +export type Motion = { dr: number; dc: number; steps: number }; + +export type VimMotionSystem = { + processKey: (key: string) => { type: 'move' | 'anchor' | 'repeat' | 'count'; data: any } | null; + resetCount: () => void; + getCount: () => number; + hasCount: () => boolean; + setLastMotion: (motion: Motion) => void; + repeatLastMotion: () => Motion | null; +}; + +export type AnimationSystem = { + animateMovement: (from: Coord, to: Coord, steps: number, onStep: (coord: Coord) => void, onComplete: () => void) => void; + cancelAnimation: () => void; + isAnimating: () => boolean; +}; + +export type UseHeroType = { + position: Coord | null; + canMoveTo: (coord: Coord) => boolean; + moveTo: (coord: Coord) => void; + pickupKey: () => void; + reachExit: () => void; + reset: () => void; + heroPos: Coord | null; + setHeroPos: (pos: Coord | null) => void; + moveHero: (dr: number, dc: number, steps: number, gameStatus: GameStatus, setGameStatus: (s: GameStatus) => void) => void; +}; + +export type CursorManager = { + position: () => Coord; + mode: () => CursorMode; + move: (dCols: number, dRows: number, count: number) => void; + moveLeft: (count?: number) => void; + moveRight: (count?: number) => void; + moveUp: (count?: number) => void; + moveDown: (count?: number) => void; + moveToStart: () => void; + moveToEnd: () => void; + moveToTop: () => void; + moveToBottom: () => void; + repeatLastMotion: () => void; + resetCount: () => void; + getCount: () => string; + hasCount: () => boolean; + setCount: (digit: string) => void; + setLastKey: (key: string) => void; + getLastKey: () => string; + hero?: UseHeroType; +}; + +export type HeroManager = { + position: Coord | null; + canMoveTo: (coord: Coord) => boolean; + moveTo: (coord: Coord) => void; + pickupKey: () => void; + reachExit: () => void; + reset: () => void; +}; + +export type HeroRenderManager = { + render: () => void; + updatePosition: (coord: Coord) => void; + showCoordinates: (show: boolean) => void; +}; + +export type Cursor = CursorManager; diff --git a/src/useCursor/useAnimation.ts b/src/useCursor/useAnimation.ts index 8d61b50..6ed7be7 100644 --- a/src/useCursor/useAnimation.ts +++ b/src/useCursor/useAnimation.ts @@ -1,7 +1,7 @@ import { useRef } from 'react'; -import type { Coord, AnimationSystem } from '../types'; +import type { Coord, AnimationSystem } from './types'; -export type { AnimationSystem } from '../types'; +export type { AnimationSystem } from './types'; export function useAnimation(): AnimationSystem { const animatingRef = useRef(false); diff --git a/src/useCursor/useCursor.ts b/src/useCursor/useCursor.ts index 5887199..6e37054 100644 --- a/src/useCursor/useCursor.ts +++ b/src/useCursor/useCursor.ts @@ -1,5 +1,7 @@ import { useRef, useEffect } from 'react' -import type { CursorMode, Coord, BoardManager, GameStatusManager } from '../types' +import type { CursorMode, Coord } from './types'; +import type { BoardManager } from '../useBoard/types'; +import type { GameStatusManager } from '../useGameStatus/types'; import { useHero } from './useHero'; import { useGameKeys } from './useGameKeys'; import { useMazeNavigation } from '../useBoard'; diff --git a/src/useCursor/useGameKeys.ts b/src/useCursor/useGameKeys.ts index 68b2f41..32c27d9 100644 --- a/src/useCursor/useGameKeys.ts +++ b/src/useCursor/useGameKeys.ts @@ -1,4 +1,6 @@ -import type { GameStatusManager, KeyLogEntry, Cursor } from "../types"; +import type { GameStatusManager } from "../useGameStatus/types"; +import type { KeyLogEntry } from "../types"; +import type { Cursor } from "./types"; import { useEffect, useRef, useState } from "react"; diff --git a/src/useCursor/useHero.ts b/src/useCursor/useHero.ts index 51716d3..d273859 100644 --- a/src/useCursor/useHero.ts +++ b/src/useCursor/useHero.ts @@ -1,5 +1,7 @@ import { useState, useEffect } from "react"; -import type { BoardManager, GameStatusManager, GameStatus, Coord, UseHeroType } from "../types"; +import type { BoardManager } from "../useBoard/types"; +import type { GameStatusManager, GameStatus } from "../useGameStatus/types"; +import type { UseHeroType, Coord } from "./types"; import { useHeroRender } from "./useHeroRender"; import { useMazeNavigation } from "../useBoard"; import { useAnimation } from "./useAnimation"; diff --git a/src/useCursor/useHeroRender.ts b/src/useCursor/useHeroRender.ts index 783cd6b..8825dad 100644 --- a/src/useCursor/useHeroRender.ts +++ b/src/useCursor/useHeroRender.ts @@ -1,7 +1,9 @@ import { useEffect } from "react"; -import type { BoardManager, GameStatus, Coord, UseHeroType, HeroRenderManager } from "../types"; +import type { BoardManager } from "../useBoard/types"; +import type { GameStatus } from "../useGameStatus/types"; +import type { UseHeroType, HeroRenderManager, Coord } from "./types"; -export type { HeroRenderManager } from "../types"; +export type { HeroRenderManager } from "./types"; type UseHeroRenderParams = { gameStatus: GameStatus; diff --git a/src/useCursor/useVimMotions.ts b/src/useCursor/useVimMotions.ts index 9dacfe0..efc10db 100644 --- a/src/useCursor/useVimMotions.ts +++ b/src/useCursor/useVimMotions.ts @@ -1,8 +1,8 @@ import { useRef } from 'react'; -import type { VimMotionSystem, Motion } from '../types'; +import type { VimMotionSystem, Motion } from './types'; -export type { Motion } from '../types'; -export type { VimMotionSystem } from '../types'; +export type { Motion } from './types'; +export type { VimMotionSystem } from './types'; export function useVimMotions(): VimMotionSystem { const countRef = useRef(''); diff --git a/src/useGameStatus/index.ts b/src/useGameStatus/index.ts index a2b084d..ba276cc 100644 --- a/src/useGameStatus/index.ts +++ b/src/useGameStatus/index.ts @@ -1 +1,2 @@ +export * from './types'; export * from './useGameStatus'; \ No newline at end of file diff --git a/src/useGameStatus/types.ts b/src/useGameStatus/types.ts new file mode 100644 index 0000000..b532e3c --- /dev/null +++ b/src/useGameStatus/types.ts @@ -0,0 +1,9 @@ +export type GameStatus = 'waiting' | 'started' | 'has-key' | 'paused' | 'game-over' | 'game-won'; + +export type GameStatusManager = { + gameStatus: GameStatus; + setGameStatus: (status: GameStatus) => void; + startGame: () => void; + togglePause: (pause?: boolean) => void; + quitGame: () => void; +}; diff --git a/src/useGameStatus/useGameStatus.ts b/src/useGameStatus/useGameStatus.ts index 9223110..ed594a7 100644 --- a/src/useGameStatus/useGameStatus.ts +++ b/src/useGameStatus/useGameStatus.ts @@ -1,5 +1,6 @@ import { useState } from 'react'; -import type { GameStatus, BoardManager, Coord } from '../types'; +import type { GameStatus } from './types'; +import type { BoardManager, Coord } from '../useBoard/types'; export function useGameStatus(board?: BoardManager, setHeroPos?: (pos: Coord) => void) { const [gameStatus, setGameStatus] = useState('waiting'); diff --git a/src/useScore/index.ts b/src/useScore/index.ts index 81500d3..cb6c144 100644 --- a/src/useScore/index.ts +++ b/src/useScore/index.ts @@ -1,3 +1,4 @@ +export * from './types'; export * from './useScore'; export * from './useScorePaths'; export * from './useScoreTime'; diff --git a/src/useScore/types.ts b/src/useScore/types.ts new file mode 100644 index 0000000..b02a135 --- /dev/null +++ b/src/useScore/types.ts @@ -0,0 +1,26 @@ +export type TimerManager = { + timeValue: number; + startTimer: () => void; + stopTimer: () => void; + resetTimer: () => void; +}; + +export type ScorePathsResult = { + entranceToKey: number; + entranceToExit: number; + heroToKey: number; + heroToExit: number; +}; + +export type ScoreManager = { + timeValue: number; + startTimer: () => void; + stopTimer: () => void; + resetTimer: () => void; + distToKey: number; + distToExit: number; + keystrokes: number; + optimalSteps: number; + efficiency: number; + finalScore: number | null; +}; diff --git a/src/useScore/useScore.ts b/src/useScore/useScore.ts index 2de5491..7c1c054 100644 --- a/src/useScore/useScore.ts +++ b/src/useScore/useScore.ts @@ -2,7 +2,9 @@ import { useEffect, useRef, useState } from "react"; import { useTimer } from "./useTimer"; import { useScoreTime } from "./useScoreTime"; import { useScorePaths } from "./useScorePaths"; -import type { BoardManager, GameStatusManager, UseHeroType } from "../types"; +import type { BoardManager } from "../useBoard/types"; +import type { GameStatusManager } from "../useGameStatus/types"; +import type { UseHeroType } from "../useCursor/types"; type UseScoreParams = { board: BoardManager; diff --git a/src/useScore/useScorePaths.ts b/src/useScore/useScorePaths.ts index 03cd8e1..a6ceae6 100644 --- a/src/useScore/useScorePaths.ts +++ b/src/useScore/useScorePaths.ts @@ -1,7 +1,8 @@ import { useEffect, useState } from "react"; -import type { BoardManager, Coord, ScorePathsResult } from "../types"; +import type { BoardManager, Coord } from "../useBoard/types"; +import type { ScorePathsResult } from "./types"; -export type { ScorePathsResult } from "../types"; +export type { ScorePathsResult } from "./types"; type UseScorePathsParams = { board: BoardManager; diff --git a/src/useScore/useScoreTime.ts b/src/useScore/useScoreTime.ts index d8e517a..a2dac4d 100644 --- a/src/useScore/useScoreTime.ts +++ b/src/useScore/useScoreTime.ts @@ -1,5 +1,6 @@ import { useEffect, useRef } from "react"; -import type { TimerManager, GameStatus } from "../types"; +import type { TimerManager } from "./types"; +import type { GameStatus } from "../useGameStatus/types"; type UseScoreTimeParams = { gameStatus: GameStatus; diff --git a/src/useScore/useTimer.ts b/src/useScore/useTimer.ts index 74fd42a..bf2d46c 100644 --- a/src/useScore/useTimer.ts +++ b/src/useScore/useTimer.ts @@ -1,7 +1,7 @@ import { useState, useRef, useEffect } from "react"; -import type { TimerManager } from '../types'; +import type { TimerManager } from './types'; -export type { TimerManager } from '../types'; +export type { TimerManager } from './types'; export function useTimer(): TimerManager { const [timeValue, setTimeValue] = useState(0);