import React, { useRef, useMemo } from "react"; import { InfoIcon } from "../../../icons/ExportCommonIcons"; import InputWithDropDown from "../../../ui/inputs/InputWithDropDown"; import EyeDropInput from "../../../ui/inputs/EyeDropInput"; import { useSelectedActionSphere, useSimulationPaths } from "../../../../store/store"; import * as Types from '../../../../types/world/worldTypes'; const VehicleMechanics: React.FC = () => { const { selectedActionSphere } = useSelectedActionSphere(); const { simulationPaths, setSimulationPaths } = useSimulationPaths(); const propertiesContainerRef = useRef(null); const selectedPoint = useMemo(() => { if (!selectedActionSphere?.point?.uuid) return null; const vehiclePaths = simulationPaths.filter( (path): path is Types.VehicleEventsSchema => path.type === "Vehicle" ); return vehiclePaths.find( (path) => path.point.uuid === selectedActionSphere.point.uuid )?.point; }, [selectedActionSphere, simulationPaths, selectedActionSphere?.point?.uuid]); const handleActionUpdate = React.useCallback((updatedAction: Partial) => { if (!selectedActionSphere?.point?.uuid) return; const updatedPaths = simulationPaths.map((path) => { if (path.type === "Vehicle" && path.point.uuid === selectedActionSphere.point.uuid) { return { ...path, point: { ...path.point, actions: { ...path.point.actions, ...updatedAction } } }; } return path; }); setSimulationPaths(updatedPaths); }, [selectedActionSphere?.point?.uuid, simulationPaths, setSimulationPaths]); const handleStartPositionChange = React.useCallback((position: string) => { handleActionUpdate({ start: position }); }, [handleActionUpdate]); const handleEndPositionChange = React.useCallback((position: string) => { handleActionUpdate({ end: position }); }, [handleActionUpdate]); const handleHitCountChange = React.useCallback((hitCount: number) => { handleActionUpdate({ hitCount }); }, [handleActionUpdate]); const handleBufferChange = React.useCallback((buffer: number) => { handleActionUpdate({ buffer }); }, [handleActionUpdate]); const handleSpeedChange = React.useCallback((speed: number) => { if (!selectedActionSphere?.point?.uuid) return; const updatedPaths = simulationPaths.map((path) => { if (path.type === "Vehicle" && path.point.uuid === selectedActionSphere.point.uuid) { return { ...path, point: { ...path.point, speed: speed } }; } return path; }); setSimulationPaths(updatedPaths); }, [selectedActionSphere?.point?.uuid, simulationPaths, setSimulationPaths]); return (
{selectedActionSphere?.path?.modelName || "Vehicle point not found"}
Vehicle Properties
{selectedPoint && ( <> handleHitCountChange(parseInt(value))} /> handleBufferChange(parseInt(value))} /> handleSpeedChange(parseFloat(value))} /> )}
Configure vehicle's movement and interaction properties.
); }; export default React.memo(VehicleMechanics);