refactor(phase1.3): remove old duplicate hook files
- Delete src/useGame/useSnake.ts (replaced by src/useCursor/useCursor.ts) - Delete src/useGame/useRenderer.ts (replaced by src/useBoard/useBoard.ts) - Delete src/useGame/useGameStatus.ts (replaced by src/useGameStatus/useGameStatus.ts) - Update useFood.ts to import from useBoard instead of useRenderer - Fix TypeScript type annotations in useFood.ts - Cleaner codebase with no duplicate implementations - Build and example app still work correctly
This commit is contained in:
+17
-17
@@ -1,13 +1,13 @@
|
||||
import { useState, useRef } from "react";
|
||||
import type { Position, SnakeBody } from "../types";
|
||||
import type { UseRendererType } from "./useRenderer";
|
||||
import type { UseBoardType } from "../useBoard";
|
||||
|
||||
export function useFood(
|
||||
cols: number,
|
||||
rows: number,
|
||||
rendererManager: UseRendererType
|
||||
boardManager: UseBoardType
|
||||
) {
|
||||
const { containerRef } = rendererManager;
|
||||
const { containerRef } = boardManager;
|
||||
const [foodPositions, setFoodPositions] = useState<Position[]>([]);
|
||||
const foodPositionsRef = useRef<Position[]>([]);
|
||||
|
||||
@@ -38,22 +38,22 @@ export function useFood(
|
||||
renderFood(newFood);
|
||||
};
|
||||
|
||||
const clearFood = () => {
|
||||
setFoodPositions([]);
|
||||
foodPositionsRef.current = [];
|
||||
const container = containerRef.current;
|
||||
container?.querySelectorAll(".food").forEach((el) => {
|
||||
el.classList.remove("food");
|
||||
});
|
||||
};
|
||||
const clearFood = () => {
|
||||
setFoodPositions([]);
|
||||
foodPositionsRef.current = [];
|
||||
const container = containerRef.current;
|
||||
container?.querySelectorAll(".food").forEach((el: Element) => {
|
||||
(el as HTMLElement).classList.remove("food");
|
||||
});
|
||||
};
|
||||
|
||||
const renderFood = (positions: Position[]) => {
|
||||
const container = containerRef.current;
|
||||
if (!container) return;
|
||||
const renderFood = (positions: Position[]) => {
|
||||
const container = containerRef.current;
|
||||
if (!container) return;
|
||||
|
||||
container.querySelectorAll(".food").forEach((el) => {
|
||||
el.classList.remove("food");
|
||||
});
|
||||
container.querySelectorAll(".food").forEach((el: Element) => {
|
||||
(el as HTMLElement).classList.remove("food");
|
||||
});
|
||||
|
||||
positions.forEach((pos) => {
|
||||
const cell = container.querySelector(
|
||||
|
||||
Reference in New Issue
Block a user