chore: address code quality audit findings
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { createSceneDataFromFiles } from "@/utils/editor/loadEditorScene";
|
||||
import { loadMapSceneData } from "@/utils/map/loadMapSceneData";
|
||||
import type { SceneData } from "@/types/editor/editor";
|
||||
import type { SceneData } from "@/types/map/mapScene";
|
||||
|
||||
interface UseEditorSceneDataResult {
|
||||
hasMapJson: boolean;
|
||||
|
||||
@@ -2,8 +2,6 @@ import { useGameStore } from "@/managers/stores/useGameStore";
|
||||
import type { MissionStep } from "@/types/gameplay/repairMission";
|
||||
|
||||
export function useRepairMovementLocked(): boolean {
|
||||
return false;
|
||||
|
||||
return useGameStore((state) => {
|
||||
switch (state.mainState) {
|
||||
case "bike":
|
||||
|
||||
@@ -4,7 +4,3 @@ import type { CloudState } from "@/data/world/cloudConfig";
|
||||
export function useCloudSettings(): CloudState {
|
||||
return useWorldSettingsStore((state) => state.clouds);
|
||||
}
|
||||
|
||||
export function useSetCloudSettings(): (clouds: Partial<CloudState>) => void {
|
||||
return useWorldSettingsStore((state) => state.setClouds);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,3 @@ import type { FogState } from "@/data/world/fogConfig";
|
||||
export function useFogSettings(): FogState {
|
||||
return useWorldSettingsStore((state) => state.fog);
|
||||
}
|
||||
|
||||
export function useSetFogSettings(): (fog: Partial<FogState>) => void {
|
||||
return useWorldSettingsStore((state) => state.setFog);
|
||||
}
|
||||
|
||||
@@ -1,58 +1,13 @@
|
||||
import { useWorldSettingsStore } from "@/managers/stores/useWorldSettingsStore";
|
||||
import type { GraphicsState } from "@/data/world/graphicsConfig";
|
||||
|
||||
export function useGraphicsSettings(): GraphicsState {
|
||||
return useWorldSettingsStore((state) => state.graphics);
|
||||
}
|
||||
|
||||
export function useSetGraphicsSettings(): (
|
||||
graphics: Partial<GraphicsState>,
|
||||
) => void {
|
||||
return useWorldSettingsStore((state) => state.setGraphics);
|
||||
}
|
||||
|
||||
export function useDynamicGrass(): boolean {
|
||||
return useWorldSettingsStore((state) => state.graphics.dynamicGrass);
|
||||
}
|
||||
|
||||
export function useDynamicTrees(): boolean {
|
||||
return useWorldSettingsStore((state) => state.graphics.dynamicTrees);
|
||||
}
|
||||
|
||||
export function useDynamicClouds(): boolean {
|
||||
return useWorldSettingsStore((state) => state.graphics.dynamicClouds);
|
||||
}
|
||||
|
||||
export function useShadowsEnabled(): boolean {
|
||||
return useWorldSettingsStore((state) => state.graphics.shadowsEnabled);
|
||||
}
|
||||
|
||||
export function useGrassDensity(): number {
|
||||
return useWorldSettingsStore((state) => state.graphics.grassDensity);
|
||||
}
|
||||
|
||||
export function useGraphicsSetters() {
|
||||
const setDynamicGrass = useWorldSettingsStore(
|
||||
(state) => state.setDynamicGrass,
|
||||
);
|
||||
const setDynamicTrees = useWorldSettingsStore(
|
||||
(state) => state.setDynamicTrees,
|
||||
);
|
||||
const setDynamicClouds = useWorldSettingsStore(
|
||||
(state) => state.setDynamicClouds,
|
||||
);
|
||||
const setShadowsEnabled = useWorldSettingsStore(
|
||||
(state) => state.setShadowsEnabled,
|
||||
);
|
||||
const setGrassDensity = useWorldSettingsStore(
|
||||
(state) => state.setGrassDensity,
|
||||
);
|
||||
|
||||
return {
|
||||
setDynamicGrass,
|
||||
setDynamicTrees,
|
||||
setDynamicClouds,
|
||||
setShadowsEnabled,
|
||||
setGrassDensity,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
MAP_INSTANCING_ASSETS,
|
||||
MAP_INSTANCING_ASSET_TYPES,
|
||||
type MapInstancingAssetType,
|
||||
} from "@/data/world/mapInstancingConfig";
|
||||
import type { MapNode } from "@/types/map/mapScene";
|
||||
import {
|
||||
type MapNodeInstanceTransform,
|
||||
mapNodeToInstanceTransform,
|
||||
} from "@/utils/map/mapInstanceTransform";
|
||||
import { logger } from "@/utils/core/Logger";
|
||||
import { getMapNodes, loadMapSceneData } from "@/utils/map/loadMapSceneData";
|
||||
|
||||
export type MapAssetInstance = MapNodeInstanceTransform;
|
||||
|
||||
export type MapInstancingData = Map<MapInstancingAssetType, MapAssetInstance[]>;
|
||||
|
||||
function extractMapInstancingData(mapNodes: MapNode[]): MapInstancingData {
|
||||
const data: MapInstancingData = new Map();
|
||||
|
||||
for (const type of MAP_INSTANCING_ASSET_TYPES) {
|
||||
const config = MAP_INSTANCING_ASSETS[type];
|
||||
|
||||
if (!config.enabled) continue;
|
||||
|
||||
const instances = mapNodes
|
||||
.filter(
|
||||
(node) => node.name === config.mapName && node.type === "Object3D",
|
||||
)
|
||||
.map(mapNodeToInstanceTransform);
|
||||
|
||||
if (instances.length > 0) {
|
||||
data.set(type, instances);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export function useMapInstancingData(): {
|
||||
data: MapInstancingData | null;
|
||||
isLoading: boolean;
|
||||
} {
|
||||
const [data, setData] = useState<MapInstancingData | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
async function load() {
|
||||
const cachedNodes = getMapNodes();
|
||||
|
||||
if (cachedNodes) {
|
||||
if (!cancelled) {
|
||||
setData(extractMapInstancingData(cachedNodes));
|
||||
setIsLoading(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await loadMapSceneData();
|
||||
} catch (error) {
|
||||
logger.error("MapInstancing", "Failed to load map instancing data", {
|
||||
error: error instanceof Error ? error : String(error),
|
||||
});
|
||||
}
|
||||
|
||||
const nodes = getMapNodes();
|
||||
|
||||
if (!cancelled) {
|
||||
setData(nodes ? extractMapInstancingData(nodes) : new Map());
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
void load();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { data, isLoading };
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { INSTANCED_MAP_EXCEPTIONS } from "@/world/vegetation/vegetationConfig";
|
||||
import type { MapNode } from "@/types/map/mapScene";
|
||||
import {
|
||||
type MapNodeInstanceTransform,
|
||||
mapNodeToInstanceTransform,
|
||||
} from "@/utils/map/mapInstanceTransform";
|
||||
import { logger } from "@/utils/core/Logger";
|
||||
import { loadMapSceneData } from "@/utils/map/loadMapSceneData";
|
||||
|
||||
export type VegetationInstance = MapNodeInstanceTransform;
|
||||
|
||||
interface InstancedMapEntry {
|
||||
modelPath: string;
|
||||
instances: VegetationInstance[];
|
||||
}
|
||||
|
||||
export type VegetationData = Map<string, InstancedMapEntry>;
|
||||
|
||||
function extractVegetationData(
|
||||
mapNodes: MapNode[],
|
||||
models: Map<string, string>,
|
||||
): VegetationData {
|
||||
const data: VegetationData = new Map();
|
||||
|
||||
for (const node of mapNodes) {
|
||||
if (node.type !== "Object3D") continue;
|
||||
if (INSTANCED_MAP_EXCEPTIONS.has(node.name)) continue;
|
||||
|
||||
const modelPath = models.get(node.name);
|
||||
if (!modelPath) continue;
|
||||
|
||||
const entry = data.get(node.name);
|
||||
|
||||
if (entry) {
|
||||
entry.instances.push(mapNodeToInstanceTransform(node));
|
||||
} else {
|
||||
data.set(node.name, {
|
||||
modelPath,
|
||||
instances: [mapNodeToInstanceTransform(node)],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export function useVegetationData(): {
|
||||
data: VegetationData | null;
|
||||
isLoading: boolean;
|
||||
} {
|
||||
const [data, setData] = useState<VegetationData | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
async function load() {
|
||||
let sceneData: Awaited<ReturnType<typeof loadMapSceneData>> | null = null;
|
||||
|
||||
try {
|
||||
sceneData = await loadMapSceneData();
|
||||
} catch (error) {
|
||||
logger.error("Vegetation", "Failed to load vegetation data", {
|
||||
error: error instanceof Error ? error : String(error),
|
||||
});
|
||||
}
|
||||
|
||||
if (!cancelled) {
|
||||
setData(
|
||||
sceneData
|
||||
? extractVegetationData(sceneData.mapNodes, sceneData.models)
|
||||
: new Map(),
|
||||
);
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
void load();
|
||||
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { data, isLoading };
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { useCallback, useRef, useState } from "react";
|
||||
import { useFrame, useThree } from "@react-three/fiber";
|
||||
import { CHUNK_CONFIG } from "@/data/world/chunkStreamingConfig";
|
||||
|
||||
export interface WorldChunkLike {
|
||||
centerX: number;
|
||||
centerZ: number;
|
||||
key: string;
|
||||
}
|
||||
|
||||
function areSetsEqual(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {
|
||||
return a.size === b.size && [...a].every((key) => b.has(key));
|
||||
}
|
||||
|
||||
export function useVisibleWorldChunks<TChunk extends WorldChunkLike>(
|
||||
chunks: readonly TChunk[],
|
||||
streamingEnabled: boolean,
|
||||
): readonly TChunk[] {
|
||||
const camera = useThree((state) => state.camera);
|
||||
const lastUpdateRef = useRef(-CHUNK_CONFIG.updateInterval);
|
||||
const [activeChunkKeys, setActiveChunkKeys] = useState<Set<string>>(
|
||||
() => new Set(),
|
||||
);
|
||||
|
||||
const updateActiveChunks = useCallback(() => {
|
||||
const nextKeys = new Set<string>();
|
||||
const cameraX = camera.position.x;
|
||||
const cameraZ = camera.position.z;
|
||||
|
||||
for (const chunk of chunks) {
|
||||
const distance = Math.hypot(
|
||||
chunk.centerX - cameraX,
|
||||
chunk.centerZ - cameraZ,
|
||||
);
|
||||
const wasActive = activeChunkKeys.has(chunk.key);
|
||||
const radius = wasActive
|
||||
? CHUNK_CONFIG.unloadRadius
|
||||
: CHUNK_CONFIG.loadRadius;
|
||||
|
||||
if (distance <= radius) {
|
||||
nextKeys.add(chunk.key);
|
||||
}
|
||||
}
|
||||
|
||||
if (areSetsEqual(nextKeys, activeChunkKeys)) return;
|
||||
|
||||
setActiveChunkKeys(nextKeys);
|
||||
}, [activeChunkKeys, camera, chunks]);
|
||||
|
||||
useFrame(({ clock }) => {
|
||||
if (!streamingEnabled) return;
|
||||
|
||||
const now = clock.elapsedTime * 1000;
|
||||
if (now - lastUpdateRef.current < CHUNK_CONFIG.updateInterval) return;
|
||||
lastUpdateRef.current = now;
|
||||
|
||||
updateActiveChunks();
|
||||
});
|
||||
|
||||
if (!streamingEnabled) return chunks;
|
||||
|
||||
return chunks.filter((chunk) => {
|
||||
if (activeChunkKeys.size > 0) {
|
||||
return activeChunkKeys.has(chunk.key);
|
||||
}
|
||||
|
||||
return (
|
||||
Math.hypot(
|
||||
chunk.centerX - camera.position.x,
|
||||
chunk.centerZ - camera.position.z,
|
||||
) <= CHUNK_CONFIG.loadRadius
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -4,19 +4,3 @@ import type { WindState } from "@/data/world/windConfig";
|
||||
export function useWind(): WindState {
|
||||
return useWorldSettingsStore((state) => state.wind);
|
||||
}
|
||||
|
||||
export function useSetWind(): (wind: Partial<WindState>) => void {
|
||||
return useWorldSettingsStore((state) => state.setWind);
|
||||
}
|
||||
|
||||
export function useWindSpeed(): number {
|
||||
return useWorldSettingsStore((state) => state.wind.speed);
|
||||
}
|
||||
|
||||
export function useWindDirection(): number {
|
||||
return useWorldSettingsStore((state) => state.wind.direction);
|
||||
}
|
||||
|
||||
export function useWindStrength(): number {
|
||||
return useWorldSettingsStore((state) => state.wind.strength);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user