no more ReturnType<typeof>
This commit is contained in:
+68
-12
@@ -1,6 +1,5 @@
|
||||
import type { RefObject } from 'react';
|
||||
import { MazeRenderer, MazeGenerator } from "./useBoard";
|
||||
import type { ScoreManager } from './useScore';
|
||||
export * from './useGame';
|
||||
export * from './useBoard';
|
||||
export * from './useCursor';
|
||||
@@ -35,7 +34,7 @@ export type CellTag = "wall" | "door" | PositionTag;
|
||||
|
||||
export type MazeCell = CellTag[];
|
||||
|
||||
export interface MazeData {
|
||||
export type MazeData = {
|
||||
maze: MazeCell[][];
|
||||
width: number;
|
||||
height: number;
|
||||
@@ -70,14 +69,15 @@ export type GameStatusManager = {
|
||||
export type CursorMode = 'normal' | 'insert' | 'replace' | 'visual' | 'visual-line';
|
||||
|
||||
export type UseHeroType = {
|
||||
heroPos: Coord | null;
|
||||
setHeroPos: (pos: Coord | null) => void;
|
||||
moveHero: (dr: number, dc: number, steps: number, gameStatus: GameStatus, setGameStatus: (s: GameStatus) => void) => void;
|
||||
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 = {
|
||||
@@ -93,13 +93,13 @@ export type CursorManager = {
|
||||
moveToTop: () => void;
|
||||
moveToBottom: () => void;
|
||||
repeatLastMotion: () => void;
|
||||
resetCount: () => void;
|
||||
getCount: () => string;
|
||||
hasCount: () => boolean;
|
||||
setCount: (digit: string) => void;
|
||||
setLastKey: (key: string) => void;
|
||||
getLastKey: () => string;
|
||||
hero?: UseHeroType;
|
||||
resetCount: () => void;
|
||||
getCount: () => string;
|
||||
hasCount: () => boolean;
|
||||
setCount: (digit: string) => void;
|
||||
setLastKey: (key: string) => void;
|
||||
getLastKey: () => string;
|
||||
hero?: UseHeroType;
|
||||
}
|
||||
|
||||
export type HeroManager = {
|
||||
@@ -119,3 +119,59 @@ export type HeroRenderer = {
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import type { Coord, MazeCell } from '../types';
|
||||
import type { Coord, MazeCell, MazeNavigator } from '../types';
|
||||
|
||||
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 { MazeNavigator } from '../types';
|
||||
|
||||
export function useMazeNavigation(maze: MazeCell[][]): MazeNavigator {
|
||||
function isValidMove(_from: Coord, to: Coord): boolean {
|
||||
@@ -81,11 +77,9 @@ export function useMazeNavigation(maze: MazeCell[][]): MazeNavigator {
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
isValidMove,
|
||||
findAnchorTarget,
|
||||
validatePath
|
||||
};
|
||||
}
|
||||
|
||||
export type MazeNavigationManager = ReturnType<typeof useMazeNavigation>;
|
||||
return {
|
||||
isValidMove,
|
||||
findAnchorTarget,
|
||||
validatePath
|
||||
};
|
||||
}
|
||||
@@ -1,11 +1,7 @@
|
||||
import { useRef } from 'react';
|
||||
import type { Coord } from '../types';
|
||||
import type { Coord, AnimationSystem } from '../types';
|
||||
|
||||
export type AnimationSystem = {
|
||||
animateMovement: (from: Coord, to: Coord, steps: number, onStep: (coord: Coord) => void, onComplete: () => void) => void;
|
||||
cancelAnimation: () => void;
|
||||
isAnimating: () => boolean;
|
||||
};
|
||||
export type { AnimationSystem } from '../types';
|
||||
|
||||
export function useAnimation(): AnimationSystem {
|
||||
const animatingRef = useRef(false);
|
||||
@@ -88,6 +84,4 @@ export function useAnimation(): AnimationSystem {
|
||||
cancelAnimation,
|
||||
isAnimating
|
||||
};
|
||||
}
|
||||
|
||||
export type AnimationManager = ReturnType<typeof useAnimation>;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import type { BoardManager, GameStatusManager, GameStatus, Coord } from "../types";
|
||||
import type { BoardManager, GameStatusManager, GameStatus, Coord, UseHeroType } from "../types";
|
||||
import { useHeroRender } from "./useHeroRender";
|
||||
import { useMazeNavigation } from "../useBoard";
|
||||
import { useAnimation } from "./useAnimation";
|
||||
|
||||
export function useHero(board: BoardManager, gameStatusManager: GameStatusManager) {
|
||||
export function useHero(board: BoardManager, gameStatusManager: GameStatusManager): UseHeroType {
|
||||
const { mazeRef } = board;
|
||||
const [heroPos, setHeroPos] = useState<Coord | null>(null);
|
||||
const { gameStatus, setGameStatus } = gameStatusManager;
|
||||
@@ -185,7 +185,5 @@ export function useHero(board: BoardManager, gameStatusManager: GameStatusManage
|
||||
|
||||
useHeroRender({ gameStatus, board, hero });
|
||||
|
||||
return hero;
|
||||
return hero;
|
||||
}
|
||||
|
||||
export type UseHeroType = ReturnType<typeof useHero>;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useEffect } from "react";
|
||||
import type { BoardManager, GameStatus, Coord } from "../types";
|
||||
import type { UseHeroType } from "./useHero";
|
||||
import type { BoardManager, GameStatus, Coord, UseHeroType, HeroRenderManager } from "../types";
|
||||
|
||||
export type { HeroRenderManager } from "../types";
|
||||
|
||||
type UseHeroRenderParams = {
|
||||
gameStatus: GameStatus;
|
||||
@@ -9,7 +10,7 @@ type UseHeroRenderParams = {
|
||||
relative?: boolean;
|
||||
};
|
||||
|
||||
export function useHeroRender(params: UseHeroRenderParams) {
|
||||
export function useHeroRender(params: UseHeroRenderParams): HeroRenderManager {
|
||||
const { gameStatus, board, hero, relative = true } = params;
|
||||
const { containerRef } = board;
|
||||
const playerPos = hero.heroPos;
|
||||
@@ -157,11 +158,9 @@ export function useHeroRender(params: UseHeroRenderParams) {
|
||||
};
|
||||
}, [playerPos, containerRef]);
|
||||
|
||||
return {
|
||||
render,
|
||||
updatePosition,
|
||||
showCoordinates
|
||||
};
|
||||
return {
|
||||
render,
|
||||
updatePosition,
|
||||
showCoordinates
|
||||
};
|
||||
}
|
||||
|
||||
export type UseHeroRenderType = ReturnType<typeof useHeroRender>;
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import { useRef } from 'react';
|
||||
import type { VimMotionSystem, Motion } from '../types';
|
||||
|
||||
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 { Motion } from '../types';
|
||||
export type { VimMotionSystem } from '../types';
|
||||
|
||||
export function useVimMotions(): VimMotionSystem {
|
||||
const countRef = useRef<string>('');
|
||||
@@ -111,6 +104,4 @@ export function useVimMotions(): VimMotionSystem {
|
||||
setLastMotion,
|
||||
repeatLastMotion
|
||||
};
|
||||
}
|
||||
|
||||
export type VimMotionManager = ReturnType<typeof useVimMotions>;
|
||||
}
|
||||
+12
-14
@@ -118,18 +118,16 @@ export function useScore({ board, hero, gameStatusManager, keyManager }: UseScor
|
||||
setFinalScore(score);
|
||||
}, [gameStatus, logicFirst, logicLast, timeValue, optimalSteps]);
|
||||
|
||||
return {
|
||||
timeValue,
|
||||
startTimer,
|
||||
stopTimer,
|
||||
resetTimer,
|
||||
distToKey,
|
||||
distToExit,
|
||||
keystrokes,
|
||||
optimalSteps,
|
||||
efficiency,
|
||||
finalScore,
|
||||
};
|
||||
return {
|
||||
timeValue,
|
||||
startTimer,
|
||||
stopTimer,
|
||||
resetTimer,
|
||||
distToKey,
|
||||
distToExit,
|
||||
keystrokes,
|
||||
optimalSteps,
|
||||
efficiency,
|
||||
finalScore,
|
||||
};
|
||||
}
|
||||
|
||||
export type ScoreManager = ReturnType<typeof useScore>;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import type { BoardManager } from "../types";
|
||||
import type { BoardManager, Coord, ScorePathsResult } from "../types";
|
||||
|
||||
export type { ScorePathsResult } from "../types";
|
||||
|
||||
type UseScorePathsParams = {
|
||||
board: BoardManager;
|
||||
heroPos: { row: number; col: number } | null;
|
||||
heroPos: Coord | null;
|
||||
};
|
||||
|
||||
export function useScorePaths({ board, heroPos }: UseScorePathsParams) {
|
||||
export function useScorePaths({ board, heroPos }: UseScorePathsParams): ScorePathsResult {
|
||||
const { mazeInstanceRef } = board;
|
||||
|
||||
const [distances, setDistances] = useState({
|
||||
@@ -38,7 +40,5 @@ export function useScorePaths({ board, heroPos }: UseScorePathsParams) {
|
||||
}));
|
||||
}, [heroPos, mazeInstanceRef]);
|
||||
|
||||
return distances;
|
||||
return distances;
|
||||
}
|
||||
|
||||
export type UseScorePathsReturn = ReturnType<typeof useScorePaths>;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import type { UseTimerReturn } from "./useTimer";
|
||||
import type { GameStatus } from "../types";
|
||||
import type { TimerManager, GameStatus } from "../types";
|
||||
|
||||
type UseScoreTimeParams = {
|
||||
gameStatus: GameStatus;
|
||||
timer: UseTimerReturn;
|
||||
timer: TimerManager;
|
||||
};
|
||||
|
||||
export function useScoreTime({ gameStatus, timer }: UseScoreTimeParams) {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
import type { TimerManager } from '../types';
|
||||
|
||||
export function useTimer() {
|
||||
export type { TimerManager } from '../types';
|
||||
|
||||
export function useTimer(): TimerManager {
|
||||
const [timeValue, setTimeValue] = useState(0);
|
||||
const startTimeRef = useRef<number | null>(null);
|
||||
const frameRef = useRef<number | null>(null);
|
||||
@@ -42,7 +45,5 @@ export function useTimer() {
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { timeValue, startTimer, stopTimer, resetTimer };
|
||||
return { timeValue, startTimer, stopTimer, resetTimer };
|
||||
}
|
||||
|
||||
export type UseTimerReturn = ReturnType<typeof useTimer>;
|
||||
|
||||
Reference in New Issue
Block a user