refactor: standardize activeTool casing and enhance trigger mechanics with bufferTime

This commit is contained in:
Jerald-Golden-B 2025-03-29 10:24:47 +05:30
parent 01588cf6c1
commit 1ce24a64f1
9 changed files with 179 additions and 58 deletions

View File

@ -243,6 +243,7 @@ const ConveyorMechanics: React.FC = () => {
uuid: THREE.MathUtils.generateUUID(), uuid: THREE.MathUtils.generateUUID(),
name: `Trigger ${triggerIndex + 1}`, name: `Trigger ${triggerIndex + 1}`,
type: '', type: '',
bufferTime: 0,
isUsed: false isUsed: false
}; };
@ -298,8 +299,19 @@ const ConveyorMechanics: React.FC = () => {
); );
setSimulationPaths(updatedPaths); setSimulationPaths(updatedPaths);
// Ensure the selectedItem is updated immediately
const updatedTrigger = updatedPaths
.flatMap((path) => (path.type === "Conveyor" ? path.points : []))
.flatMap((point) => point.triggers)
.find((trigger) => trigger.uuid === uuid);
if (updatedTrigger) {
setSelectedItem({ type: "trigger", item: updatedTrigger });
}
}; };
// Update the toggle handlers to immediately update the selected item // Update the toggle handlers to immediately update the selected item
const handleActionToggle = (uuid: string) => { const handleActionToggle = (uuid: string) => {
if (!selectedActionSphere) return; if (!selectedActionSphere) return;
@ -373,10 +385,45 @@ const ConveyorMechanics: React.FC = () => {
} }
}; };
const handleTriggerBufferTimeChange = (uuid: string, bufferTime: number) => {
if (!selectedActionSphere) return;
const updatedPaths = simulationPaths.map((path) =>
path.type === "Conveyor"
? {
...path,
points: path.points.map((point) =>
point.uuid === selectedActionSphere.point.uuid
? {
...point,
triggers: point.triggers.map((trigger) =>
trigger.uuid === uuid ? { ...trigger, bufferTime } : trigger
),
}
: point
),
}
: path
);
setSimulationPaths(updatedPaths);
// Immediately update selectedItem if it's the currently selected trigger
if (selectedItem?.type === "trigger" && selectedItem.item.uuid === uuid) {
setSelectedItem({
...selectedItem,
item: {
...selectedItem.item,
bufferTime
}
});
}
};
const [selectedItem, setSelectedItem] = useState<{ type: "action" | "trigger"; item: any; } | null>(null); const [selectedItem, setSelectedItem] = useState<{ type: "action" | "trigger"; item: any; } | null>(null);
useEffect(() => { useEffect(() => {
setSelectedItem(null); // Reset selectedItem when selectedActionSphere changes setSelectedItem(null);
}, [selectedActionSphere]); }, [selectedActionSphere]);
return ( return (
@ -559,8 +606,19 @@ const ConveyorMechanics: React.FC = () => {
options={["On-Hit", "Buffer"]} options={["On-Hit", "Buffer"]}
onSelect={(option) => handleTriggerSelect(selectedItem.item.uuid, option)} onSelect={(option) => handleTriggerSelect(selectedItem.item.uuid, option)}
/> />
{selectedItem.item.type === "Buffer" && (
<InputWithDropDown
label="Buffer Time"
value={selectedItem.item.bufferTime.toString()}
onChange={(value) => {
handleTriggerBufferTimeChange(selectedItem.item.uuid, parseInt(value));
}}
/>
)}
</> </>
)} )}
</> </>
)} )}

View File

@ -243,6 +243,7 @@ const VehicleMechanics: React.FC = () => {
uuid: THREE.MathUtils.generateUUID(), uuid: THREE.MathUtils.generateUUID(),
name: `Trigger ${triggerIndex + 1}`, name: `Trigger ${triggerIndex + 1}`,
type: '', type: '',
bufferTime: 0,
isUsed: false isUsed: false
}; };

View File

@ -18,15 +18,19 @@ import { usePlayButtonStore } from "../../store/usePlayButtonStore";
import useTemplateStore from "../../store/useTemplateStore"; import useTemplateStore from "../../store/useTemplateStore";
import { useSelectedZoneStore } from "../../store/useZoneStore"; import { useSelectedZoneStore } from "../../store/useZoneStore";
import { import {
useActiveTool,
useAddAction, useAddAction,
useDeleteModels, useDeleteModels,
useDeletePointOrLine,
useMovePoint,
useSelectedWallItem, useSelectedWallItem,
useToggleView, useToggleView,
useToolMode,
useTransformMode,
} from "../../store/store"; } from "../../store/store";
const Tools: React.FC = () => { const Tools: React.FC = () => {
const { templates } = useTemplateStore(); const { templates } = useTemplateStore();
const [activeTool, setActiveTool] = useState("cursor");
const [activeSubTool, setActiveSubTool] = useState("cursor"); const [activeSubTool, setActiveSubTool] = useState("cursor");
const [toggleThreeD, setToggleThreeD] = useState(true); const [toggleThreeD, setToggleThreeD] = useState(true);
@ -39,11 +43,17 @@ const Tools: React.FC = () => {
const { selectedZone } = useSelectedZoneStore(); const { selectedZone } = useSelectedZoneStore();
// wall options // wall options
const { setToggleView } = useToggleView(); const { toggleView, setToggleView } = useToggleView();
const { setDeleteModels } = useDeleteModels(); const { setDeleteModels } = useDeleteModels();
const { setAddAction } = useAddAction(); const { setAddAction } = useAddAction();
const { setSelectedWallItem } = useSelectedWallItem(); const { setSelectedWallItem } = useSelectedWallItem();
const { transformMode, setTransformMode } = useTransformMode();
const { deletePointOrLine, setDeletePointOrLine } = useDeletePointOrLine();
const { movePoint, setMovePoint } = useMovePoint();
const { toolMode, setToolMode } = useToolMode();
const { activeTool, setActiveTool } = useActiveTool();
// Reset activeTool whenever activeModule changes // Reset activeTool whenever activeModule changes
useEffect(() => { useEffect(() => {
setActiveTool(activeSubTool); setActiveTool(activeSubTool);
@ -60,6 +70,7 @@ const Tools: React.FC = () => {
setToggleView(false); setToggleView(false);
} }
setToggleThreeD(!toggleThreeD); setToggleThreeD(!toggleThreeD);
setActiveTool("cursor");
}; };
useEffect(() => { useEffect(() => {
@ -85,6 +96,84 @@ const Tools: React.FC = () => {
}; };
}, []); }, []);
useEffect(() => {
setToolMode(null);
setDeleteModels(false);
setAddAction(null);
setTransformMode(null);
setMovePoint(false);
setDeletePointOrLine(false);
switch (activeTool) {
case "Move":
if (toggleView) {
setMovePoint(true);
} else {
setTransformMode("translate");
}
break;
case "Rotate":
if (!toggleView) {
setTransformMode("rotate");
}
break;
case "Scale":
if (!toggleView) {
setTransformMode("scale");
}
break;
case "draw-wall":
if (toggleView) {
setToolMode("Wall");
}
break;
case "Draw Aisle":
if (toggleView) {
setToolMode("Aisle");
}
break;
case "Mark zone":
if (toggleView) {
setToolMode("Zone");
}
break;
case "Draw Floor":
if (toggleView) {
setToolMode("Floor");
}
break;
case "Measurement Tool":
setToolMode("MeasurementScale");
break;
case "Add pillar":
if (!toggleView) {
setAddAction("pillar");
}
break;
case "Delete":
if (toggleView) {
setDeletePointOrLine(true);
} else {
setDeleteModels(true);
}
break;
default:
break;
}
setActiveTool(activeTool);
}, [activeTool]);
return ( return (
<> <>
{!isPlaying ? ( {!isPlaying ? (
@ -94,8 +183,7 @@ const Tools: React.FC = () => {
<div className="activeDropicon"> <div className="activeDropicon">
{activeSubTool == "cursor" && ( {activeSubTool == "cursor" && (
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "cursor" ? "active" : ""
activeTool === "cursor" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("cursor"); setActiveTool("cursor");
@ -106,8 +194,7 @@ const Tools: React.FC = () => {
)} )}
{activeSubTool == "free-hand" && ( {activeSubTool == "free-hand" && (
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "free-hand" ? "active" : ""
activeTool === "free-hand" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("free-hand"); setActiveTool("free-hand");
@ -167,8 +254,7 @@ const Tools: React.FC = () => {
<div className="split"></div> <div className="split"></div>
<div className="draw-tools"> <div className="draw-tools">
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "draw-wall" ? "active" : ""
activeTool === "draw-wall" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("draw-wall"); setActiveTool("draw-wall");
@ -177,8 +263,7 @@ const Tools: React.FC = () => {
<WallIcon isActive={activeTool === "draw-wall"} /> <WallIcon isActive={activeTool === "draw-wall"} />
</div> </div>
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "draw-zone" ? "active" : ""
activeTool === "draw-zone" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("draw-zone"); setActiveTool("draw-zone");
@ -187,8 +272,7 @@ const Tools: React.FC = () => {
<ZoneIcon isActive={activeTool === "draw-zone"} /> <ZoneIcon isActive={activeTool === "draw-zone"} />
</div> </div>
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "draw-aisle" ? "active" : ""
activeTool === "draw-aisle" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("draw-aisle"); setActiveTool("draw-aisle");
@ -197,8 +281,7 @@ const Tools: React.FC = () => {
<AsileIcon isActive={activeTool === "draw-aisle"} /> <AsileIcon isActive={activeTool === "draw-aisle"} />
</div> </div>
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "draw-floor" ? "active" : ""
activeTool === "draw-floor" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("draw-floor"); setActiveTool("draw-floor");
@ -214,8 +297,7 @@ const Tools: React.FC = () => {
<div className="split"></div> <div className="split"></div>
<div className="draw-tools"> <div className="draw-tools">
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "pen" ? "active" : ""
activeTool === "pen" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("pen"); setActiveTool("pen");
@ -248,8 +330,7 @@ const Tools: React.FC = () => {
<div className="split"></div> <div className="split"></div>
<div className="general-options"> <div className="general-options">
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "comment" ? "active" : ""
activeTool === "comment" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setActiveTool("comment"); setActiveTool("comment");
@ -258,8 +339,7 @@ const Tools: React.FC = () => {
<CommentIcon isActive={activeTool === "comment"} /> <CommentIcon isActive={activeTool === "comment"} />
</div> </div>
<div <div
className={`tool-button ${ className={`tool-button ${activeTool === "play" ? "active" : ""
activeTool === "play" ? "active" : ""
}`} }`}
onClick={() => { onClick={() => {
setIsPlaying(!isPlaying); setIsPlaying(!isPlaying);
@ -270,8 +350,7 @@ const Tools: React.FC = () => {
</div> </div>
<div className="split"></div> <div className="split"></div>
<div <div
className={`toggle-threed-button${ className={`toggle-threed-button${toggleThreeD ? " toggled" : ""
toggleThreeD ? " toggled" : ""
}`} }`}
onClick={toggleSwitch} onClick={toggleSwitch}
> >

View File

@ -193,7 +193,7 @@ const FloorItemsGroup = ({ itemsGroup, hoveredDeletableFloorItem, AttachedObject
} }
const Mode = transformMode; const Mode = transformMode;
if (Mode !== null || activeTool === "Cursor") { if (Mode !== null || activeTool === "cursor") {
if (!itemsGroup.current) return; if (!itemsGroup.current) return;
let intersects = raycaster.intersectObjects(itemsGroup.current.children, true); let intersects = raycaster.intersectObjects(itemsGroup.current.children, true);
if (intersects.length > 0 && intersects[0]?.object?.parent?.parent?.position && intersects[0]?.object?.parent?.parent?.scale && intersects[0]?.object?.parent?.parent?.rotation) { if (intersects.length > 0 && intersects[0]?.object?.parent?.parent?.position && intersects[0]?.object?.parent?.parent?.scale && intersects[0]?.object?.parent?.parent?.rotation) {
@ -225,7 +225,7 @@ const FloorItemsGroup = ({ itemsGroup, hoveredDeletableFloorItem, AttachedObject
const Mode = transformMode; const Mode = transformMode;
if (Mode !== null || activeTool === "Cursor") { if (Mode !== null || activeTool === "cursor") {
if (!itemsGroup.current) return; if (!itemsGroup.current) return;
let intersects = raycaster.intersectObjects(itemsGroup.current.children, true); let intersects = raycaster.intersectObjects(itemsGroup.current.children, true);
if (intersects.length > 0 && intersects[0]?.object?.parent?.parent?.position && intersects[0]?.object?.parent?.parent?.scale && intersects[0]?.object?.parent?.parent?.rotation) { if (intersects.length > 0 && intersects[0]?.object?.parent?.parent?.position && intersects[0]?.object?.parent?.parent?.scale && intersects[0]?.object?.parent?.parent?.rotation) {

View File

@ -67,7 +67,7 @@ function Behaviour() {
point: { point: {
uuid: pointUUID, uuid: pointUUID,
position: [pointPosition.x, pointPosition.y, pointPosition.z], position: [pointPosition.x, pointPosition.y, pointPosition.z],
actions: [{ uuid: THREE.MathUtils.generateUUID(), name: 'Action 1', type: 'Start', start: THREE.MathUtils.generateUUID(), hitCount: 1, end: THREE.MathUtils.generateUUID(), buffer: 0, isUsed: false }], actions: [{ uuid: THREE.MathUtils.generateUUID(), name: 'Action 1', type: 'Start', start: '', hitCount: 1, end: '', buffer: 0, isUsed: false }],
triggers: [], triggers: [],
connections: { source: { pathUUID: item.modeluuid, pointUUID: pointUUID }, targets: [] }, connections: { source: { pathUUID: item.modeluuid, pointUUID: pointUUID }, targets: [] },
}, },

View File

@ -1,27 +1,10 @@
import * as THREE from 'three'; import * as THREE from 'three';
import * as Types from '../../../types/world/worldTypes';
import { useRef, useState, useEffect } from 'react'; import { useRef, useState, useEffect } from 'react';
import { Sphere, TransformControls } from '@react-three/drei'; import { Sphere, TransformControls } from '@react-three/drei';
import { useIsConnecting, useRenderDistance, useSelectedActionSphere, useSelectedPath, useSimulationPaths } from '../../../store/store'; import { useIsConnecting, useRenderDistance, useSelectedActionSphere, useSelectedPath, useSimulationPaths } from '../../../store/store';
import { useFrame, useThree } from '@react-three/fiber'; import { useFrame, useThree } from '@react-three/fiber';
import { useSubModuleStore } from '../../../store/useModuleStore'; import { useSubModuleStore } from '../../../store/useModuleStore';
import { point } from '@turf/helpers';
interface ConveyorEventsSchema {
modeluuid: string;
modelName: string;
type: 'Conveyor';
points: {
uuid: string;
position: [number, number, number];
rotation: [number, number, number];
actions: { uuid: string; name: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | [];
triggers: { uuid: string; name: string; type: string; isUsed: boolean }[] | [];
connections: { source: { pathUUID: string; pointUUID: string }; targets: { pathUUID: string; pointUUID: string }[] };
}[];
assetPosition: [number, number, number];
assetRotation: [number, number, number];
speed: number;
}
function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject<THREE.Group> }) { function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject<THREE.Group> }) {
const { renderDistance } = useRenderDistance(); const { renderDistance } = useRenderDistance();
@ -89,7 +72,7 @@ function PathCreation({ pathsGroupRef }: { pathsGroupRef: React.MutableRefObject
}; };
} }
return path; return path;
}) as ConveyorEventsSchema[]; }) as Types.ConveyorEventsSchema[];
setSimulationPaths(updatedPaths); setSimulationPaths(updatedPaths);
}; };

View File

@ -14,7 +14,7 @@ function Simulation() {
const [processes, setProcesses] = useState([]); const [processes, setProcesses] = useState([]);
useEffect(() => { useEffect(() => {
console.log('simulationPaths: ', simulationPaths);
}, [simulationPaths]); }, [simulationPaths]);
// useEffect(() => { // useEffect(() => {

View File

@ -214,7 +214,7 @@ export const useAddAction = create<any>((set: any) => ({
})); }));
export const useActiveTool = create<any>((set: any) => ({ export const useActiveTool = create<any>((set: any) => ({
activeTool: "Cursor", activeTool: "cursor",
setActiveTool: (x: any) => set({ activeTool: x }), setActiveTool: (x: any) => set({ activeTool: x }),
})); }));

View File

@ -295,7 +295,7 @@ interface ConveyorEventsSchema {
position: [number, number, number]; position: [number, number, number];
rotation: [number, number, number]; rotation: [number, number, number];
actions: { uuid: string; name: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | []; actions: { uuid: string; name: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | [];
triggers: { uuid: string; name: string; type: string; isUsed: boolean }[] | []; triggers: { uuid: string; name: string; type: string; isUsed: boolean; bufferTime: number }[] | [];
connections: { source: { pathUUID: string; pointUUID: string }; targets: { pathUUID: string; pointUUID: string }[] }; connections: { source: { pathUUID: string; pointUUID: string }; targets: { pathUUID: string; pointUUID: string }[] };
}[]; }[];
assetPosition: [number, number, number]; assetPosition: [number, number, number];