Refactor simulation paths to simulation states
- Updated all instances of `simulationPaths` to `simulationStates` across multiple components including copyPasteControls, duplicationControls, moveControls, rotateControls, selectionControls, and others. - Adjusted related state management hooks in the store to reflect the change from `simulationPaths` to `simulationStates`. - Ensured that all references to simulation paths in the simulation logic and UI components are consistent with the new naming convention.
This commit is contained in:
@@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react';
|
||||
import * as THREE from 'three';
|
||||
import * as Types from '../../../types/world/worldTypes';
|
||||
import { QuadraticBezierLine } from '@react-three/drei';
|
||||
import { useIsConnecting, useSimulationPaths } from '../../../store/store';
|
||||
import { useIsConnecting, useSimulationStates } from '../../../store/store';
|
||||
import useModuleStore from '../../../store/useModuleStore';
|
||||
import { usePlayButtonStore } from '../../../store/usePlayButtonStore';
|
||||
|
||||
@@ -11,7 +11,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
const { activeModule } = useModuleStore();
|
||||
const { gl, raycaster, scene, pointer, camera } = useThree();
|
||||
const { setIsConnecting } = useIsConnecting();
|
||||
const { simulationPaths, setSimulationPaths } = useSimulationPaths();
|
||||
const { simulationStates, setSimulationStates } = useSimulationStates();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
|
||||
const [firstSelected, setFirstSelected] = useState<{
|
||||
@@ -29,7 +29,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
toPathUUID: string,
|
||||
toPointUUID: string
|
||||
) => {
|
||||
const updatedPaths = simulationPaths.map(path => {
|
||||
const updatedPaths = simulationStates.map(path => {
|
||||
if (path.type === 'Conveyor') {
|
||||
if (path.modeluuid === fromPathUUID) {
|
||||
return {
|
||||
@@ -99,7 +99,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
const existingTargets = path.points.connections.targets || [];
|
||||
|
||||
// Check if target is a Conveyor
|
||||
const toPath = simulationPaths.find(p => p.modeluuid === toPathUUID);
|
||||
const toPath = simulationStates.find(p => p.modeluuid === toPathUUID);
|
||||
if (toPath?.type !== 'Conveyor') {
|
||||
console.log("Vehicle can only connect to Conveyors");
|
||||
return path;
|
||||
@@ -136,7 +136,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
const existingTargets = path.points.connections.targets || [];
|
||||
|
||||
// Check if source is a Conveyor
|
||||
const fromPath = simulationPaths.find(p => p.modeluuid === fromPathUUID);
|
||||
const fromPath = simulationStates.find(p => p.modeluuid === fromPathUUID);
|
||||
if (fromPath?.type !== 'Conveyor') {
|
||||
console.log("Vehicle can only connect to Conveyors");
|
||||
return path;
|
||||
@@ -169,7 +169,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
return path;
|
||||
});
|
||||
|
||||
setSimulationPaths(updatedPaths);
|
||||
setSimulationStates(updatedPaths);
|
||||
};
|
||||
|
||||
const handleAddConnection = (fromPathUUID: string, fromUUID: string, toPathUUID: string, toUUID: string) => {
|
||||
@@ -227,8 +227,8 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
}
|
||||
|
||||
if (pathUUID) {
|
||||
const firstPath = simulationPaths.find(p => p.modeluuid === firstSelected?.pathUUID);
|
||||
const secondPath = simulationPaths.find(p => p.modeluuid === pathUUID);
|
||||
const firstPath = simulationStates.find(p => p.modeluuid === firstSelected?.pathUUID);
|
||||
const secondPath = simulationStates.find(p => p.modeluuid === pathUUID);
|
||||
|
||||
// Prevent vehicle-to-vehicle connections
|
||||
if (firstPath && secondPath && firstPath.type === 'Vehicle' && secondPath.type === 'Vehicle') {
|
||||
@@ -247,7 +247,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
|
||||
// Check if this specific connection already exists
|
||||
const isDuplicateConnection = firstSelected
|
||||
? simulationPaths.some(path => {
|
||||
? simulationStates.some(path => {
|
||||
if (path.modeluuid === firstSelected.pathUUID) {
|
||||
if (path.type === 'Conveyor') {
|
||||
const point = path.points.find(p => p.uuid === firstSelected.sphereUUID);
|
||||
@@ -281,7 +281,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
|
||||
// For non-Vehicle paths, check if already connected
|
||||
if (intersected.userData.path.type !== 'Vehicle') {
|
||||
const isAlreadyConnected = simulationPaths.some(path => {
|
||||
const isAlreadyConnected = simulationStates.some(path => {
|
||||
if (path.type === 'Conveyor') {
|
||||
return path.points.some(point =>
|
||||
point.uuid === sphereUUID &&
|
||||
@@ -361,7 +361,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
canvasElement.removeEventListener("mousemove", onMouseMove);
|
||||
canvasElement.removeEventListener("contextmenu", onContextMenu);
|
||||
};
|
||||
}, [camera, scene, raycaster, firstSelected, simulationPaths]);
|
||||
}, [camera, scene, raycaster, firstSelected, simulationStates]);
|
||||
|
||||
useFrame(() => {
|
||||
if (firstSelected) {
|
||||
@@ -397,8 +397,8 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
const pathData = sphere.userData.path;
|
||||
const pathUUID = pathData.modeluuid;
|
||||
|
||||
const firstPath = simulationPaths.find(p => p.modeluuid === firstSelected.pathUUID);
|
||||
const secondPath = simulationPaths.find(p => p.modeluuid === pathUUID);
|
||||
const firstPath = simulationStates.find(p => p.modeluuid === firstSelected.pathUUID);
|
||||
const secondPath = simulationStates.find(p => p.modeluuid === pathUUID);
|
||||
const isVehicleToVehicle = firstPath?.type === 'Vehicle' && secondPath?.type === 'Vehicle';
|
||||
|
||||
// Inside the useFrame hook, where we check for snapped spheres:
|
||||
@@ -413,7 +413,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
!firstSelected.isCorner);
|
||||
|
||||
// Check for duplicate connection (regardless of path type)
|
||||
const isDuplicateConnection = simulationPaths.some(path => {
|
||||
const isDuplicateConnection = simulationStates.some(path => {
|
||||
if (path.modeluuid === firstSelected.pathUUID) {
|
||||
if (path.type === 'Conveyor') {
|
||||
const point = path.points.find(p => p.uuid === firstSelected.sphereUUID);
|
||||
@@ -431,7 +431,7 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
|
||||
// For non-Vehicle paths, check if already connected
|
||||
const isNonVehicleAlreadyConnected = pathData.type !== 'Vehicle' &&
|
||||
simulationPaths.some(path => {
|
||||
simulationStates.some(path => {
|
||||
if (path.type === 'Conveyor') {
|
||||
return path.points.some(point =>
|
||||
point.uuid === sphereUUID &&
|
||||
@@ -505,11 +505,11 @@ function PathConnector({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObjec
|
||||
|
||||
return (
|
||||
<group name='simulationConnectionGroup' visible={!isPlaying} >
|
||||
{simulationPaths.flatMap(path => {
|
||||
{simulationStates.flatMap(path => {
|
||||
if (path.type === 'Conveyor') {
|
||||
return path.points.flatMap(point =>
|
||||
point.connections.targets.map((target, index) => {
|
||||
const targetPath = simulationPaths.find(p => p.modeluuid === target.pathUUID);
|
||||
const targetPath = simulationStates.find(p => p.modeluuid === target.pathUUID);
|
||||
if (targetPath?.type === 'Vehicle') return null;
|
||||
|
||||
const fromSphere = pathsGroupRef.current?.getObjectByProperty('uuid', point.uuid);
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
useRenderDistance,
|
||||
useSelectedActionSphere,
|
||||
useSelectedPath,
|
||||
useSimulationPaths,
|
||||
useSimulationStates,
|
||||
} from "../../../store/store";
|
||||
import { useFrame, useThree } from "@react-three/fiber";
|
||||
import { useSubModuleStore } from "../../../store/useModuleStore";
|
||||
@@ -32,7 +32,7 @@ function PathCreation({
|
||||
const { raycaster, camera, pointer, gl } = useThree();
|
||||
const plane = useMemo(() => new THREE.Plane(new THREE.Vector3(0, 1, 0), 0), []);
|
||||
const { setSelectedPath } = useSelectedPath();
|
||||
const { simulationPaths, setSimulationPaths } = useSimulationPaths();
|
||||
const { simulationStates, setSimulationStates } = useSimulationStates();
|
||||
const { isConnecting } = useIsConnecting();
|
||||
|
||||
const groupRefs = useRef<{ [key: string]: THREE.Group }>({});
|
||||
@@ -71,7 +71,7 @@ function PathCreation({
|
||||
const updateSimulationPaths = () => {
|
||||
if (!selectedActionSphere) return;
|
||||
|
||||
const updatedPaths = simulationPaths.map((path) => {
|
||||
const updatedPaths = simulationStates.map((path) => {
|
||||
if (path.type === "Conveyor") {
|
||||
return {
|
||||
...path,
|
||||
@@ -97,7 +97,7 @@ function PathCreation({
|
||||
return path;
|
||||
}) as Types.ConveyorEventsSchema[];
|
||||
|
||||
setSimulationPaths(updatedPaths);
|
||||
setSimulationStates(updatedPaths);
|
||||
};
|
||||
|
||||
useFrame(() => {
|
||||
@@ -173,7 +173,7 @@ function PathCreation({
|
||||
z: number
|
||||
) => {
|
||||
if (!selectedActionSphere?.points?.uuid) return;
|
||||
const updatedPaths = simulationPaths.map((path) => {
|
||||
const updatedPaths = simulationStates.map((path) => {
|
||||
|
||||
if (
|
||||
path.type === "Vehicle" &&
|
||||
@@ -204,12 +204,12 @@ function PathCreation({
|
||||
);
|
||||
updateBackend(updatedPath);
|
||||
|
||||
setSimulationPaths(updatedPaths);
|
||||
setSimulationStates(updatedPaths);
|
||||
};
|
||||
|
||||
return (
|
||||
<group visible={!isPlaying} name="simulation-simulationPaths-group" ref={pathsGroupRef}>
|
||||
{simulationPaths.map((path) => {
|
||||
<group visible={!isPlaying} name="simulation-simulationStates-group" ref={pathsGroupRef}>
|
||||
{simulationStates.map((path) => {
|
||||
if (path.type === "Conveyor") {
|
||||
const points = path.points.map(
|
||||
(point) => new THREE.Vector3(...point.position)
|
||||
|
||||
Reference in New Issue
Block a user