feat: Implement socket responses for collaboration features including model updates, line management, and zone handling
feat: Add temporary markdown files for simulation actions, events, products, and triggers feat: Create events store with actions for managing events, points, actions, and triggers, including syncing with product store
This commit is contained in:
@@ -40,7 +40,7 @@ import loadWalls from "./geomentries/walls/loadWalls";
|
||||
|
||||
import * as Types from "../../types/world/worldTypes";
|
||||
|
||||
import SocketResponses from "../collaboration/socketResponses.dev";
|
||||
import SocketResponses from "../collaboration/socket/socketResponses.dev";
|
||||
import FloorItemsGroup from "./groups/floorItemsGroup";
|
||||
import FloorPlanGroup from "./groups/floorPlanGroup";
|
||||
import FloorGroup from "./groups/floorGroup";
|
||||
@@ -323,26 +323,6 @@ export default function Builder() {
|
||||
anglesnappedPoint={anglesnappedPoint}
|
||||
/>
|
||||
|
||||
{/* <ZoneGroup
|
||||
zoneGroup={zoneGroup}
|
||||
plane={plane}
|
||||
floorPlanGroupLine={floorPlanGroupLine}
|
||||
floorPlanGroupPoint={floorPlanGroupPoint}
|
||||
line={line}
|
||||
lines={lines}
|
||||
currentLayerPoint={currentLayerPoint}
|
||||
dragPointControls={dragPointControls}
|
||||
floorPlanGroup={floorPlanGroup}
|
||||
ReferenceLineMesh={ReferenceLineMesh}
|
||||
LineCreated={LineCreated}
|
||||
isSnapped={isSnapped}
|
||||
ispreSnapped={ispreSnapped}
|
||||
snappedPoint={snappedPoint}
|
||||
isSnappedUUID={isSnappedUUID}
|
||||
isAngleSnapped={isAngleSnapped}
|
||||
anglesnappedPoint={anglesnappedPoint}
|
||||
/> */}
|
||||
|
||||
<ZoneGroup />
|
||||
|
||||
<FloorGroupAilse
|
||||
@@ -367,7 +347,6 @@ export default function Builder() {
|
||||
|
||||
<MeasurementTool />
|
||||
|
||||
{/* <DrieHtmlTemp itemsGroup={itemsGroup} /> */}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,245 +0,0 @@
|
||||
import { useEffect } from "react";
|
||||
import * as THREE from 'three';
|
||||
import * as Types from '../../../types/world/worldTypes';
|
||||
import * as CONSTANTS from "../../../types/world/worldConstants";
|
||||
import { useActiveLayer, useSocketStore, useDeleteTool, useDeletePointOrLine, useMovePoint, useToggleView, useUpdateScene, useNewLines, useToolMode } from "../../../store/store";
|
||||
import { useThree } from "@react-three/fiber";
|
||||
import arrayLineToObject from "../geomentries/lines/lineConvertions/arrayLineToObject";
|
||||
import addPointToScene from "../geomentries/points/addPointToScene";
|
||||
import addLineToScene from "../geomentries/lines/addLineToScene";
|
||||
import removeSoloPoint from "../geomentries/points/removeSoloPoint";
|
||||
import removeReferenceLine from "../geomentries/lines/removeReferenceLine";
|
||||
import getClosestIntersection from "../geomentries/lines/getClosestIntersection";
|
||||
import loadZones from "../geomentries/zones/loadZones";
|
||||
|
||||
const ZoneGroup = ({ zoneGroup, plane, floorPlanGroupLine, floorPlanGroupPoint, line, lines, currentLayerPoint, dragPointControls, floorPlanGroup, ReferenceLineMesh, LineCreated, isSnapped, ispreSnapped, snappedPoint, isSnappedUUID, isAngleSnapped, anglesnappedPoint }: any) => {
|
||||
const { toggleView, setToggleView } = useToggleView();
|
||||
const { deleteTool, setDeleteTool } = useDeleteTool();
|
||||
const { deletePointOrLine, setDeletePointOrLine } = useDeletePointOrLine();
|
||||
const { toolMode, setToolMode } = useToolMode();
|
||||
const { movePoint, setMovePoint } = useMovePoint();
|
||||
const { socket } = useSocketStore();
|
||||
const { activeLayer } = useActiveLayer();
|
||||
const { gl, raycaster, camera, pointer } = useThree();
|
||||
const { updateScene, setUpdateScene } = useUpdateScene();
|
||||
const { newLines, setNewLines } = useNewLines();
|
||||
|
||||
useEffect(() => {
|
||||
if (updateScene) {
|
||||
loadZones(lines, zoneGroup);
|
||||
setUpdateScene(false);
|
||||
}
|
||||
}, [updateScene])
|
||||
|
||||
useEffect(() => {
|
||||
if (toolMode === "Zone") {
|
||||
setDeletePointOrLine(false);
|
||||
setMovePoint(false);
|
||||
setDeleteTool(false);
|
||||
} else {
|
||||
removeSoloPoint(line, floorPlanGroupLine, floorPlanGroupPoint);
|
||||
removeReferenceLine(floorPlanGroup, ReferenceLineMesh, LineCreated, line);
|
||||
}
|
||||
}, [toolMode])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const canvasElement = gl.domElement;
|
||||
|
||||
let drag = false;
|
||||
let isLeftMouseDown = false;
|
||||
|
||||
const onMouseDown = (evt: any) => {
|
||||
if (evt.button === 0) {
|
||||
isLeftMouseDown = true;
|
||||
drag = false;
|
||||
}
|
||||
};
|
||||
|
||||
const onMouseUp = (evt: any) => {
|
||||
if (evt.button === 0) {
|
||||
isLeftMouseDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
const onMouseMove = () => {
|
||||
if (isLeftMouseDown) {
|
||||
drag = true;
|
||||
}
|
||||
};
|
||||
|
||||
const onContextMenu = (e: any) => {
|
||||
e.preventDefault();
|
||||
if (toolMode === "Zone") {
|
||||
removeSoloPoint(line, floorPlanGroupLine, floorPlanGroupPoint);
|
||||
removeReferenceLine(floorPlanGroup, ReferenceLineMesh, LineCreated, line);
|
||||
}
|
||||
};
|
||||
|
||||
const onMouseClick = (evt: any) => {
|
||||
if (!plane.current || drag) return;
|
||||
const intersects = raycaster.intersectObject(plane.current, true);
|
||||
let intersectionPoint = intersects[0].point;
|
||||
const points = floorPlanGroupPoint.current?.children ?? [];
|
||||
const intersectsPoint = raycaster.intersectObjects(points, true).find(intersect => intersect.object.visible);
|
||||
let intersectsLines: any = raycaster.intersectObjects(floorPlanGroupLine.current.children, true);
|
||||
|
||||
if (intersectsLines.length > 0 && intersects && intersects.length > 0 && !intersectsPoint) {
|
||||
const lineType = intersectsLines[0].object.userData.linePoints[0][3];
|
||||
if (lineType === CONSTANTS.lineConfig.zoneName) {
|
||||
// console.log("intersected a zone line");
|
||||
|
||||
const ThroughPoint = (intersectsLines[0].object.geometry.parameters.path).getPoints(300);
|
||||
let intersection = getClosestIntersection(ThroughPoint, intersectionPoint);
|
||||
if (!intersection) return;
|
||||
const point = addPointToScene(intersection, CONSTANTS.pointConfig.zoneOuterColor, currentLayerPoint, floorPlanGroupPoint, dragPointControls, undefined, CONSTANTS.lineConfig.zoneName);
|
||||
(line.current as Types.Line).push([new THREE.Vector3(intersection.x, 0.01, intersection.z), point.uuid, activeLayer, CONSTANTS.lineConfig.zoneName,]);
|
||||
if (line.current.length >= 2 && line.current[0] && line.current[1]) {
|
||||
lines.current.push(line.current as Types.Line);
|
||||
|
||||
const data = arrayLineToObject(line.current as Types.Line);
|
||||
|
||||
const email = localStorage.getItem('email')
|
||||
const organization = (email!.split("@")[1]).split(".")[0];
|
||||
|
||||
//REST
|
||||
|
||||
// setLine(organization, data.layer!, data.line!, data.type!);
|
||||
|
||||
//SOCKET
|
||||
|
||||
const input = {
|
||||
organization: organization,
|
||||
layer: data.layer,
|
||||
line: data.line,
|
||||
type: data.type,
|
||||
socketId: socket.id
|
||||
}
|
||||
|
||||
socket.emit('v1:Line:create', input);
|
||||
|
||||
setNewLines([line.current]);
|
||||
|
||||
addLineToScene(line.current[0][0], line.current[1][0], CONSTANTS.lineConfig.zoneColor, line.current, floorPlanGroupLine);
|
||||
let lastPoint = line.current[line.current.length - 1];
|
||||
line.current = [lastPoint];
|
||||
}
|
||||
}
|
||||
} else if (intersectsPoint && intersects && intersects.length > 0) {
|
||||
if (intersectsPoint.object.userData.type === CONSTANTS.lineConfig.zoneName) {
|
||||
// console.log("intersected a zone point");
|
||||
|
||||
intersectionPoint = intersectsPoint.object.position;
|
||||
(line.current as Types.Line).push([new THREE.Vector3(intersectionPoint.x, 0.01, intersectionPoint.z), intersectsPoint.object.uuid, activeLayer, CONSTANTS.lineConfig.zoneName]);
|
||||
if (line.current.length >= 2 && line.current[0] && line.current[1]) {
|
||||
lines.current.push(line.current as Types.Line);
|
||||
|
||||
const data = arrayLineToObject(line.current as Types.Line);
|
||||
|
||||
const email = localStorage.getItem('email')
|
||||
const organization = (email!.split("@")[1]).split(".")[0];
|
||||
|
||||
//REST
|
||||
|
||||
// setLine(organization, data.layer!, data.line!, data.type!);
|
||||
|
||||
//SOCKET
|
||||
|
||||
const input = {
|
||||
organization: organization,
|
||||
layer: data.layer,
|
||||
line: data.line,
|
||||
type: data.type,
|
||||
socketId: socket.id
|
||||
}
|
||||
|
||||
socket.emit('v1:Line:create', input);
|
||||
|
||||
setNewLines([line.current]);
|
||||
|
||||
addLineToScene(line.current[0][0], line.current[1][0], CONSTANTS.lineConfig.zoneColor, line.current, floorPlanGroupLine);
|
||||
let lastPoint = line.current[line.current.length - 1];
|
||||
line.current = [lastPoint];
|
||||
ispreSnapped.current = false;
|
||||
isSnapped.current = false;
|
||||
}
|
||||
}
|
||||
} else if (intersects && intersects.length > 0) {
|
||||
// console.log("intersected a empty area");
|
||||
|
||||
let uuid: string = "";
|
||||
if (isAngleSnapped.current && anglesnappedPoint.current && line.current.length > 0) {
|
||||
intersectionPoint = anglesnappedPoint.current;
|
||||
const point = addPointToScene(intersectionPoint, CONSTANTS.pointConfig.zoneOuterColor, currentLayerPoint, floorPlanGroupPoint, dragPointControls, undefined, CONSTANTS.lineConfig.zoneName);
|
||||
uuid = point.uuid;
|
||||
} else if (isSnapped.current && snappedPoint.current && line.current.length > 0) {
|
||||
intersectionPoint = snappedPoint.current;
|
||||
uuid = isSnappedUUID.current!;
|
||||
} else if (ispreSnapped.current && snappedPoint.current) {
|
||||
intersectionPoint = snappedPoint.current;
|
||||
uuid = isSnappedUUID.current!;
|
||||
} else {
|
||||
const point = addPointToScene(intersectionPoint, CONSTANTS.pointConfig.zoneOuterColor, currentLayerPoint, floorPlanGroupPoint, dragPointControls, undefined, CONSTANTS.lineConfig.zoneName);
|
||||
uuid = point.uuid;
|
||||
}
|
||||
|
||||
(line.current as Types.Line).push([new THREE.Vector3(intersectionPoint.x, 0.01, intersectionPoint.z), uuid, activeLayer, CONSTANTS.lineConfig.zoneName]);
|
||||
if (line.current.length >= 2 && line.current[0] && line.current[1]) {
|
||||
lines.current.push(line.current as Types.Line);
|
||||
|
||||
const data = arrayLineToObject(line.current as Types.Line);
|
||||
|
||||
const email = localStorage.getItem('email')
|
||||
const organization = (email!.split("@")[1]).split(".")[0];
|
||||
|
||||
//REST
|
||||
|
||||
// setLine(organization, data.layer!, data.line!, data.type!);
|
||||
|
||||
//SOCKET
|
||||
|
||||
const input = {
|
||||
organization: organization,
|
||||
layer: data.layer,
|
||||
line: data.line,
|
||||
type: data.type,
|
||||
socketId: socket.id
|
||||
}
|
||||
|
||||
socket.emit('v1:Line:create', input);
|
||||
|
||||
setNewLines([line.current]);
|
||||
|
||||
addLineToScene(line.current[0][0], line.current[1][0], CONSTANTS.lineConfig.zoneColor, line.current, floorPlanGroupLine);
|
||||
let lastPoint = line.current[line.current.length - 1];
|
||||
line.current = [lastPoint];
|
||||
ispreSnapped.current = false;
|
||||
isSnapped.current = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toolMode === 'Zone') {
|
||||
canvasElement.addEventListener("mousedown", onMouseDown);
|
||||
canvasElement.addEventListener("mouseup", onMouseUp);
|
||||
canvasElement.addEventListener("mousemove", onMouseMove);
|
||||
canvasElement.addEventListener("click", onMouseClick);
|
||||
canvasElement.addEventListener("contextmenu", onContextMenu);
|
||||
}
|
||||
|
||||
return () => {
|
||||
canvasElement.removeEventListener("mousedown", onMouseDown);
|
||||
canvasElement.removeEventListener("mouseup", onMouseUp);
|
||||
canvasElement.removeEventListener("mousemove", onMouseMove);
|
||||
canvasElement.removeEventListener("click", onMouseClick);
|
||||
canvasElement.removeEventListener("contextmenu", onContextMenu);
|
||||
};
|
||||
}, [toolMode])
|
||||
|
||||
return (
|
||||
<group ref={zoneGroup} visible={!toggleView} name="zoneGroup">
|
||||
</group>
|
||||
)
|
||||
}
|
||||
|
||||
export default ZoneGroup;
|
||||
@@ -2,7 +2,7 @@ import * as THREE from "three";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useFrame } from "@react-three/fiber";
|
||||
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
|
||||
import camModel from "../../assets/gltf-glb/camera face 2.gltf";
|
||||
import camModel from "../../../assets/gltf-glb/camera face 2.gltf";
|
||||
import getActiveUsersData from "../../../services/factoryBuilder/collab/getActiveUsers";
|
||||
import { useActiveUsers, useSocketStore } from "../../../store/store";
|
||||
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
import { useEffect } from "react";
|
||||
import * as THREE from 'three';
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
||||
import gsap from 'gsap';
|
||||
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
|
||||
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
||||
import { toast } from 'react-toastify';
|
||||
import { useSocketStore, useActiveLayer, useWallItems, useFloorItems, useLayers, useUpdateScene, useWalls, useDeletedLines, useNewLines, useZonePoints, useZones } from "../../store/store";
|
||||
import { useSocketStore, useActiveLayer, useWallItems, useFloorItems, useLayers, useUpdateScene, useWalls, useDeletedLines, useNewLines, useZonePoints, useZones } from "../../../store/store";
|
||||
|
||||
import * as Types from "../../types/world/worldTypes";
|
||||
import * as CONSTANTS from '../../types/world/worldConstants';
|
||||
import TempLoader from "../builder/geomentries/assets/tempLoader";
|
||||
import * as Types from "../../../types/world/worldTypes";
|
||||
import * as CONSTANTS from '../../../types/world/worldConstants';
|
||||
import TempLoader from "../../builder/geomentries/assets/tempLoader";
|
||||
|
||||
// import { setFloorItemApi } from "../../services/factoryBuilder/assest/floorAsset/setFloorItemApi";
|
||||
import objectLineToArray from "../builder/geomentries/lines/lineConvertions/objectLineToArray";
|
||||
import addLineToScene from "../builder/geomentries/lines/addLineToScene";
|
||||
import updateLinesPositions from "../builder/geomentries/lines/updateLinesPositions";
|
||||
import updateLines from "../builder/geomentries/lines/updateLines";
|
||||
import updateDistanceText from "../builder/geomentries/lines/updateDistanceText";
|
||||
import updateFloorLines from "../builder/geomentries/floors/updateFloorLines";
|
||||
import loadWalls from "../builder/geomentries/walls/loadWalls";
|
||||
import RemoveConnectedLines from "../builder/geomentries/lines/removeConnectedLines";
|
||||
import Layer2DVisibility from "../builder/geomentries/layers/layer2DVisibility";
|
||||
import { DRACOLoader } from "three/examples/jsm/loaders/DRACOLoader";
|
||||
import { retrieveGLTF, storeGLTF } from "../../utils/indexDB/idbUtils";
|
||||
import { getZonesApi } from "../../services/factoryBuilder/zones/getZonesApi";
|
||||
import objectLineToArray from "../../builder/geomentries/lines/lineConvertions/objectLineToArray";
|
||||
import addLineToScene from "../../builder/geomentries/lines/addLineToScene";
|
||||
import updateLinesPositions from "../../builder/geomentries/lines/updateLinesPositions";
|
||||
import updateLines from "../../builder/geomentries/lines/updateLines";
|
||||
import updateDistanceText from "../../builder/geomentries/lines/updateDistanceText";
|
||||
import updateFloorLines from "../../builder/geomentries/floors/updateFloorLines";
|
||||
import loadWalls from "../../builder/geomentries/walls/loadWalls";
|
||||
import RemoveConnectedLines from "../../builder/geomentries/lines/removeConnectedLines";
|
||||
import Layer2DVisibility from "../../builder/geomentries/layers/layer2DVisibility";
|
||||
import { retrieveGLTF, storeGLTF } from "../../../utils/indexDB/idbUtils";
|
||||
import { getZonesApi } from "../../../services/factoryBuilder/zones/getZonesApi";
|
||||
|
||||
|
||||
export default function SocketResponses({
|
||||
@@ -6,6 +6,7 @@ import Builder from "../builder/builder";
|
||||
import Visualization from "../visualization/visualization";
|
||||
import Setup from "./setup/setup";
|
||||
import Simulation from "../simulation/simulation";
|
||||
import Collaboration from "../collaboration/collaboration";
|
||||
|
||||
export default function Scene() {
|
||||
const map = useMemo(() => [
|
||||
@@ -21,6 +22,8 @@ export default function Scene() {
|
||||
|
||||
<Setup />
|
||||
|
||||
<Collaboration />
|
||||
|
||||
<Builder />
|
||||
|
||||
<Simulation />
|
||||
|
||||
0
app/src/modules/simulation/actions/temp.md
Normal file
0
app/src/modules/simulation/actions/temp.md
Normal file
0
app/src/modules/simulation/events/points/temp.md
Normal file
0
app/src/modules/simulation/events/points/temp.md
Normal file
0
app/src/modules/simulation/events/temp.md
Normal file
0
app/src/modules/simulation/events/temp.md
Normal file
0
app/src/modules/simulation/products/temp.md
Normal file
0
app/src/modules/simulation/products/temp.md
Normal file
0
app/src/modules/simulation/triggers/temp.md
Normal file
0
app/src/modules/simulation/triggers/temp.md
Normal file
@@ -6,11 +6,11 @@ import UI from "./ui";
|
||||
import { useEffect } from "react";
|
||||
import { useThree } from "@react-three/fiber";
|
||||
|
||||
export default function DrieHtmlTemp({ itemsGroup }: { itemsGroup: Types.RefGroup }) {
|
||||
export default function DrieHtmlTemp() {
|
||||
const { drieTemp, setDrieTemp } = useDrieTemp();
|
||||
const { drieUIValue, setDrieUIValue } = useDrieUIValue();
|
||||
const state = useThree();
|
||||
const { camera, raycaster } = state;
|
||||
const { camera, raycaster, scene } = state;
|
||||
|
||||
useEffect(() => {
|
||||
const canvasElement = state.gl.domElement;
|
||||
@@ -34,8 +34,8 @@ export default function DrieHtmlTemp({ itemsGroup }: { itemsGroup: Types.RefGrou
|
||||
if (evt.button === 0) {
|
||||
isLeftMouseDown = false;
|
||||
if (drag) return;
|
||||
if (!itemsGroup.current) return
|
||||
let intersects = raycaster.intersectObjects(itemsGroup.current.children, true);
|
||||
if (!scene) return
|
||||
let intersects = raycaster.intersectObjects(scene.children, true);
|
||||
if (intersects.length > 0) {
|
||||
let currentObject = intersects[0].object;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ import React from 'react'
|
||||
import Dropped3dWidgets from './widgets/3d/Dropped3dWidget'
|
||||
import ZoneCentreTarget from './zone/zoneCameraTarget'
|
||||
import ZoneAssets from './zone/zoneAssets'
|
||||
// import MqttEvents from '../../services/factoryBuilder/mqtt/mqttEvents'
|
||||
import MqttEvents from '../../services/factoryBuilder/mqtt/mqttEvents'
|
||||
import DrieHtmlTemp from './mqttTemp/drieHtmlTemp'
|
||||
|
||||
const Visualization = () => {
|
||||
return (
|
||||
@@ -10,11 +11,14 @@ const Visualization = () => {
|
||||
|
||||
<Dropped3dWidgets />
|
||||
|
||||
{/* <ZoneCentreTarget />
|
||||
<ZoneCentreTarget />
|
||||
|
||||
<ZoneAssets />
|
||||
|
||||
<MqttEvents /> */}
|
||||
<MqttEvents />
|
||||
|
||||
{/* <DrieHtmlTemp /> */}
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
349
app/src/store/useEventsStore.ts
Normal file
349
app/src/store/useEventsStore.ts
Normal file
@@ -0,0 +1,349 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
import { useProductStore } from './useSimulationStore';
|
||||
|
||||
type EventsStore = {
|
||||
events: EventsSchema[];
|
||||
|
||||
// Sync with product store
|
||||
syncFromProducts: (products: productsSchema) => void;
|
||||
|
||||
// Event-level actions
|
||||
addEvent: (event: EventsSchema) => void;
|
||||
removeEvent: (modelUuid: string) => void;
|
||||
updateEvent: (modelUuid: string, updates: Partial<EventsSchema>) => void;
|
||||
|
||||
// Point-level actions
|
||||
addPoint: (modelUuid: string, point: TransferPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema) => void;
|
||||
removePoint: (modelUuid: string, pointUuid: string) => void;
|
||||
updatePoint: (
|
||||
modelUuid: string,
|
||||
pointUuid: string,
|
||||
updates: Partial<TransferPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema>
|
||||
) => void;
|
||||
|
||||
// Action-level actions
|
||||
addAction: (
|
||||
modelUuid: string,
|
||||
pointUuid: string,
|
||||
action: TransferPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']
|
||||
) => void;
|
||||
removeAction: (actionUuid: string) => void;
|
||||
updateAction: (
|
||||
actionUuid: string,
|
||||
updates: Partial<TransferPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']>
|
||||
) => void;
|
||||
|
||||
// Trigger-level actions
|
||||
addTrigger: (actionUuid: string, trigger: TriggerSchema) => void;
|
||||
removeTrigger: (triggerUuid: string) => void;
|
||||
updateTrigger: (triggerUuid: string, updates: Partial<TriggerSchema>) => void;
|
||||
|
||||
// Helper functions
|
||||
getEventByModelUuid: (modelUuid: string) => EventsSchema | undefined;
|
||||
getPointByUuid: (modelUuid: string, pointUuid: string) => TransferPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
||||
getActionByUuid: (actionUuid: string) => (TransferPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
||||
getTriggerByUuid: (triggerUuid: string) => TriggerSchema | undefined;
|
||||
};
|
||||
|
||||
export const useEventsStore = create<EventsStore>()(
|
||||
immer((set, get) => ({
|
||||
events: [],
|
||||
|
||||
// Sync events from products store
|
||||
syncFromProducts: (products) => {
|
||||
set((state) => {
|
||||
state.events = products.flatMap(product => product.eventsData);
|
||||
});
|
||||
},
|
||||
|
||||
// Event-level actions
|
||||
addEvent: (event) => {
|
||||
set((state) => {
|
||||
state.events.push(event);
|
||||
});
|
||||
},
|
||||
|
||||
removeEvent: (modelUuid) => {
|
||||
set((state) => {
|
||||
state.events = state.events.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
|
||||
});
|
||||
},
|
||||
|
||||
updateEvent: (modelUuid, updates) => {
|
||||
set((state) => {
|
||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event) {
|
||||
Object.assign(event, updates);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Point-level actions
|
||||
addPoint: (modelUuid, point) => {
|
||||
set((state) => {
|
||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event && 'points' in event) {
|
||||
(event as TransferEventSchema).points.push(point as TransferPointSchema);
|
||||
} else if (event && 'point' in event) {
|
||||
(event as VehicleSchemaEvent | RoboticArmSchemaEvent | MachineSchemaEvent | StorageSchemaEvent).point = point as any;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removePoint: (modelUuid, pointUuid) => {
|
||||
set((state) => {
|
||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event && 'points' in event) {
|
||||
(event as TransferEventSchema).points = (event as TransferEventSchema).points.filter(p => p.uuid !== pointUuid);
|
||||
}
|
||||
// For single-point events, you might want to handle differently
|
||||
});
|
||||
},
|
||||
|
||||
updatePoint: (modelUuid, pointUuid, updates) => {
|
||||
set((state) => {
|
||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event && 'points' in event) {
|
||||
const point = (event as TransferEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
if (point) {
|
||||
Object.assign(point, updates);
|
||||
}
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
Object.assign((event as any).point, updates);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Action-level actions
|
||||
addAction: (modelUuid, pointUuid, action) => {
|
||||
set((state) => {
|
||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event && 'points' in event) {
|
||||
const point = (event as TransferEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
if (point) {
|
||||
point.action = action as any;
|
||||
}
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
if ('action' in (event as any).point) {
|
||||
(event as any).point.action = action;
|
||||
} else if ('actions' in (event as any).point) {
|
||||
(event as any).point.actions.push(action);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeAction: (actionUuid) => {
|
||||
set((state) => {
|
||||
for (const event of state.events) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
// Handle removal for single action points
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if (event.type === "roboticArm") {
|
||||
if ('actions' in point) {
|
||||
point.actions = point.actions.filter((a: any) => a.actionUuid !== actionUuid);
|
||||
}
|
||||
} else if ('action' in point && point.action?.actionUuid === actionUuid) {
|
||||
// Handle single action
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateAction: (actionUuid, updates) => {
|
||||
set((state) => {
|
||||
for (const event of state.events) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
Object.assign(point.action, updates);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||
Object.assign(point.action, updates);
|
||||
return;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
Object.assign(action, updates);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Trigger-level actions
|
||||
addTrigger: (actionUuid, trigger) => {
|
||||
set((state) => {
|
||||
for (const event of state.events) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
point.action.triggers.push(trigger);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||
point.action.triggers.push(trigger);
|
||||
return;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
action.triggers.push(trigger);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeTrigger: (triggerUuid) => {
|
||||
set((state) => {
|
||||
for (const event of state.events) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && 'triggers' in point.action) {
|
||||
point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateTrigger: (triggerUuid, updates) => {
|
||||
set((state) => {
|
||||
for (const event of state.events) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
Object.assign(trigger, updates);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
Object.assign(trigger, updates);
|
||||
return;
|
||||
}
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
Object.assign(trigger, updates);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Helper functions
|
||||
getEventByModelUuid: (modelUuid) => {
|
||||
return get().events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
},
|
||||
|
||||
getPointByUuid: (modelUuid, pointUuid) => {
|
||||
const event = get().events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event && 'points' in event) {
|
||||
return (event as TransferEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
return (event as any).point;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getActionByUuid: (actionUuid) => {
|
||||
const state = get();
|
||||
for (const event of state.events) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
return point.action;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||
return point.action;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getTriggerByUuid: (triggerUuid) => {
|
||||
const state = get();
|
||||
for (const event of state.events) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||
if (trigger) return trigger;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) return trigger;
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}))
|
||||
);
|
||||
|
||||
// Set up automatic syncing between stores
|
||||
useProductStore.subscribe(
|
||||
(state) => {
|
||||
useEventsStore.getState().syncFromProducts(state.products);
|
||||
}
|
||||
);
|
||||
@@ -1,134 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
interface AssetEventSchema {
|
||||
modelUuid: string;
|
||||
modelName: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
state: "idle" | "running" | "stopped" | "disabled" | "error";
|
||||
}
|
||||
|
||||
interface TriggerSchema {
|
||||
triggerUuid: string;
|
||||
triggerName: string;
|
||||
triggerType: "onComplete" | "onStart" | "onStop" | "delay" | "onError";
|
||||
delay: number;
|
||||
triggeredAsset: {
|
||||
triggeredModel: { modelName: string, modelUuid: string };
|
||||
triggeredAction: { actionName: string, actionUuid: string };
|
||||
} | null;
|
||||
}
|
||||
|
||||
interface TransferPointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "default" | "spawn" | "swap" | "despawn";
|
||||
material: string | "inherit";
|
||||
delay: number | "inherit";
|
||||
spawnInterval: number | "inherit";
|
||||
spawnCount: number | "inherit";
|
||||
triggers: TriggerSchema[];
|
||||
}[];
|
||||
}
|
||||
|
||||
interface VehiclePointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "travel";
|
||||
material: string;
|
||||
unLoadDuration: number;
|
||||
loadCapacity: number;
|
||||
pickUpPoint: { x: number; y: number, z: number } | {};
|
||||
unLoadPoint: { x: number; y: number, z: number } | {};
|
||||
triggers: TriggerSchema[];
|
||||
}[];
|
||||
}
|
||||
|
||||
interface RoboticArmPointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "pickAndPlace";
|
||||
process: { startPoint: string; endPoint: string };
|
||||
triggers: TriggerSchema[];
|
||||
}[];
|
||||
}
|
||||
|
||||
interface MachinePointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "process";
|
||||
processTime: number;
|
||||
swapMaterial: string;
|
||||
triggers: TriggerSchema[];
|
||||
}[];
|
||||
}
|
||||
|
||||
interface StoragePointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "storage";
|
||||
materials: { materialName: string; materialId: string; quantity: number }[];
|
||||
storageCapacity: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
interface TransferEventSchema extends AssetEventSchema {
|
||||
type: "transfer";
|
||||
speed: number;
|
||||
points: TransferPointSchema[];
|
||||
}
|
||||
|
||||
interface VehicleSchemaEvent extends AssetEventSchema {
|
||||
type: "vehicle";
|
||||
speed: number;
|
||||
point: VehiclePointSchema;
|
||||
}
|
||||
|
||||
interface RoboticArmSchemaEvent extends AssetEventSchema {
|
||||
type: "roboticArm";
|
||||
speed: number;
|
||||
point: RoboticArmPointSchema;
|
||||
}
|
||||
|
||||
interface MachineSchemaEvent extends AssetEventSchema {
|
||||
type: "machine";
|
||||
point: MachinePointSchema;
|
||||
}
|
||||
|
||||
interface StorageSchemaEvent extends AssetEventSchema {
|
||||
type: "storageUnit";
|
||||
point: StoragePointSchema;
|
||||
}
|
||||
|
||||
type EventsSchema = TransferEventSchema | VehicleSchemaEvent | RoboticArmSchemaEvent | MachineSchemaEvent | StorageSchemaEvent | [];
|
||||
|
||||
type productsSchema = {
|
||||
productName: string;
|
||||
productId: string;
|
||||
eventsData: EventsSchema[];
|
||||
}[]
|
||||
|
||||
type Store = {
|
||||
products: productsSchema;
|
||||
|
||||
@@ -138,14 +10,14 @@ type Store = {
|
||||
updateProduct: (productId: string, updates: Partial<{ productName: string; eventsData: EventsSchema[] }>) => void;
|
||||
|
||||
// Event-level actions
|
||||
addEventToProduct: (productId: string, event: EventsSchema) => void;
|
||||
removeEventFromProduct: (productId: string, modelUuid: string) => void;
|
||||
updateEventInProduct: (productId: string, modelUuid: string, updates: Partial<EventsSchema>) => void;
|
||||
addEvent: (productId: string, event: EventsSchema) => void;
|
||||
removeEvent: (productId: string, modelUuid: string) => void;
|
||||
updateEvent: (productId: string, modelUuid: string, updates: Partial<EventsSchema>) => void;
|
||||
|
||||
// Point-level actions
|
||||
addPointToEvent: (productId: string, modelUuid: string, point: TransferPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema) => void;
|
||||
removePointFromEvent: (productId: string, modelUuid: string, pointUuid: string) => void;
|
||||
updatePointInEvent: (
|
||||
addPoint: (productId: string, modelUuid: string, point: TransferPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema) => void;
|
||||
removePoint: (productId: string, modelUuid: string, pointUuid: string) => void;
|
||||
updatePoint: (
|
||||
productId: string,
|
||||
modelUuid: string,
|
||||
pointUuid: string,
|
||||
@@ -157,12 +29,12 @@ type Store = {
|
||||
productId: string,
|
||||
modelUuid: string,
|
||||
pointUuid: string,
|
||||
action: TransferPointSchema['actions'][0] | VehiclePointSchema['actions'][0] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['actions'][0] | StoragePointSchema['actions'][0]
|
||||
action: TransferPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']
|
||||
) => void;
|
||||
removeAction: (actionUuid: string) => void;
|
||||
updateAction: (
|
||||
actionUuid: string,
|
||||
updates: Partial<TransferPointSchema['actions'][0] | VehiclePointSchema['actions'][0] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['actions'][0] | StoragePointSchema['actions'][0]>
|
||||
updates: Partial<TransferPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']>
|
||||
) => void;
|
||||
|
||||
// Trigger-level actions
|
||||
@@ -178,16 +50,11 @@ type Store = {
|
||||
|
||||
// Helper functions
|
||||
getProductById: (productId: string) => { productName: string; productId: string; eventsData: EventsSchema[] } | undefined;
|
||||
getEventByModelUuid: (productId: string, modelUuid: string) => EventsSchema | undefined;
|
||||
getPointByUuid: (productId: string, modelUuid: string, pointUuid: string) => TransferPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
||||
getActionByUuid: (actionUuid: string) => (TransferPointSchema['actions'][0] | VehiclePointSchema['actions'][0] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['actions'][0] | StoragePointSchema['actions'][0]) | undefined;
|
||||
getTriggerByUuid: (triggerUuid: string) => TriggerSchema | undefined;
|
||||
};
|
||||
|
||||
export const useProductStore = create<Store>()(
|
||||
immer((set, get) => ({
|
||||
products: [],
|
||||
activeProductId: null,
|
||||
|
||||
// Product-level actions
|
||||
addProduct: (productName, productId) => {
|
||||
@@ -217,7 +84,7 @@ export const useProductStore = create<Store>()(
|
||||
},
|
||||
|
||||
// Event-level actions
|
||||
addEventToProduct: (productId, event) => {
|
||||
addEvent: (productId, event) => {
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
@@ -226,7 +93,7 @@ export const useProductStore = create<Store>()(
|
||||
});
|
||||
},
|
||||
|
||||
removeEventFromProduct: (productId, modelUuid) => {
|
||||
removeEvent: (productId, modelUuid) => {
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
@@ -235,7 +102,7 @@ export const useProductStore = create<Store>()(
|
||||
});
|
||||
},
|
||||
|
||||
updateEventInProduct: (productId, modelUuid, updates) => {
|
||||
updateEvent: (productId, modelUuid, updates) => {
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
@@ -248,7 +115,7 @@ export const useProductStore = create<Store>()(
|
||||
},
|
||||
|
||||
// Point-level actions
|
||||
addPointToEvent: (productId, modelUuid, point) => {
|
||||
addPoint: (productId, modelUuid, point) => {
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
@@ -262,7 +129,7 @@ export const useProductStore = create<Store>()(
|
||||
});
|
||||
},
|
||||
|
||||
removePointFromEvent: (productId, modelUuid, pointUuid) => {
|
||||
removePoint: (productId, modelUuid, pointUuid) => {
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
@@ -271,13 +138,12 @@ export const useProductStore = create<Store>()(
|
||||
(event as TransferEventSchema).points = (event as TransferEventSchema).points.filter(p => p.uuid !== pointUuid);
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
// For events with single point, we can't remove it, only reset to empty
|
||||
// You might want to handle this differently
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updatePointInEvent: (productId, modelUuid, pointUuid, updates) => {
|
||||
updatePoint: (productId, modelUuid, pointUuid, updates) => {
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
@@ -303,25 +169,37 @@ export const useProductStore = create<Store>()(
|
||||
if (event && 'points' in event) {
|
||||
const point = (event as TransferEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
if (point) {
|
||||
point.actions.push(action as any);
|
||||
point.action = action as any;
|
||||
}
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
if ('action' in (event as any).point) {
|
||||
(event as any).point.action = action;
|
||||
} else if ('actions' in (event as any).point) {
|
||||
(event as any).point.actions.push(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeAction: (actionUuid) => {
|
||||
removeAction: (actionUuid: string) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
if ('points' in event) {
|
||||
// Handle TransferEventSchema
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
point.actions = point.actions.filter(a => a.actionUuid !== actionUuid);
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
(event as any).point.actions = (event as any).point.actions.filter((a: any) => a.actionUuid !== actionUuid);
|
||||
const point = (event as any).point;
|
||||
if (event.type === "roboticArm") {
|
||||
// Handle RoboticArmSchemaEvent
|
||||
if ('actions' in point) {
|
||||
point.actions = point.actions.filter((a: any) => a.actionUuid !== actionUuid);
|
||||
}
|
||||
} else if ('action' in point && point.action?.actionUuid === actionUuid) {
|
||||
// For other schemas with a single 'action'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,14 +212,18 @@ export const useProductStore = create<Store>()(
|
||||
for (const event of product.eventsData) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
const action = point.actions.find(a => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
Object.assign(action, updates);
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
Object.assign(point.action, updates);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const action = (event as any).point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||
Object.assign(point.action, updates);
|
||||
return;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
Object.assign(action, updates);
|
||||
return;
|
||||
@@ -349,6 +231,7 @@ export const useProductStore = create<Store>()(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -359,21 +242,26 @@ export const useProductStore = create<Store>()(
|
||||
for (const event of product.eventsData) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
const action = point.actions.find(a => a.actionUuid === actionUuid);
|
||||
if (action && 'triggers' in action) {
|
||||
action.triggers.push(trigger);
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
point.action.triggers.push(trigger);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const action = (event as any).point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action && 'triggers' in action) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||
point.action.triggers.push(trigger);
|
||||
return;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
action.triggers.push(trigger);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -383,14 +271,16 @@ export const useProductStore = create<Store>()(
|
||||
for (const event of product.eventsData) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
action.triggers = action.triggers.filter(t => t.triggerUuid !== triggerUuid);
|
||||
}
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
for (const action of (event as any).point.actions) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && 'triggers' in point.action) {
|
||||
point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||
}
|
||||
@@ -398,6 +288,7 @@ export const useProductStore = create<Store>()(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -407,18 +298,24 @@ export const useProductStore = create<Store>()(
|
||||
for (const event of product.eventsData) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
const trigger = action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
Object.assign(trigger, updates);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
for (const action of (event as any).point.actions) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
Object.assign(trigger, updates);
|
||||
return;
|
||||
}
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
@@ -430,77 +327,13 @@ export const useProductStore = create<Store>()(
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Helper functions
|
||||
getProductById: (productId) => {
|
||||
return get().products.find(p => p.productId === productId);
|
||||
},
|
||||
|
||||
getEventByModelUuid: (productId, modelUuid) => {
|
||||
const product = get().products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
return product.eventsData.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getPointByUuid: (productId, modelUuid, pointUuid) => {
|
||||
const product = get().products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
const event = product.eventsData.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event && 'points' in event) {
|
||||
return (event as TransferEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
return (event as any).point;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getActionByUuid: (actionUuid) => {
|
||||
const state = get();
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
const action = point.actions.find(a => a.actionUuid === actionUuid);
|
||||
if (action) return action;
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const action = (event as any).point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getTriggerByUuid: (triggerUuid) => {
|
||||
const state = get();
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as TransferEventSchema).points) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
const trigger = action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||
if (trigger) return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
for (const action of (event as any).point.actions) {
|
||||
if ('triggers' in action) {
|
||||
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}))
|
||||
);
|
||||
122
app/src/types/simulationTypes.d.ts
vendored
122
app/src/types/simulationTypes.d.ts
vendored
@@ -1,99 +1,3 @@
|
||||
|
||||
interface PathConnection {
|
||||
fromModelUUID: string;
|
||||
fromUUID: string;
|
||||
toConnections: {
|
||||
toModelUUID: string;
|
||||
toUUID: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
interface ConnectionStore {
|
||||
connections: PathConnection[];
|
||||
setConnections: (connections: PathConnection[]) => void;
|
||||
addConnection: (newConnection: PathConnection) => void;
|
||||
removeConnection: (fromUUID: string, toUUID: string) => void;
|
||||
}
|
||||
|
||||
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; bufferTime: number; }[] | [];
|
||||
connections: {
|
||||
source: { modelUUID: string; pointUUID: string };
|
||||
targets: { modelUUID: string; pointUUID: string }[];
|
||||
};
|
||||
}[];
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
speed: number | string;
|
||||
}
|
||||
|
||||
interface VehicleEventsSchema {
|
||||
modeluuid: string;
|
||||
modelName: string;
|
||||
type: "Vehicle";
|
||||
points: {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: { uuid: string; name: string; type: string; start: { x: number; y: number } | {}; hitCount: number; end: { x: number; y: number } | {}; buffer: number; };
|
||||
connections: {
|
||||
source: { modelUUID: string; pointUUID: string };
|
||||
targets: { modelUUID: string; pointUUID: string }[];
|
||||
};
|
||||
speed: number;
|
||||
isPlaying: boolean;
|
||||
};
|
||||
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
}
|
||||
|
||||
interface StaticMachineEventsSchema {
|
||||
modeluuid: string;
|
||||
modelName: string;
|
||||
type: "StaticMachine";
|
||||
points: {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: { uuid: string; name: string; buffer: number; material: string; };
|
||||
triggers: { uuid: string; name: string; type: string };
|
||||
connections: {
|
||||
source: { modelUUID: string; pointUUID: string };
|
||||
targets: { modelUUID: string; pointUUID: string }[];
|
||||
};
|
||||
};
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
}
|
||||
|
||||
interface ArmBotEventsSchema {
|
||||
modeluuid: string;
|
||||
modelName: string;
|
||||
type: "ArmBot";
|
||||
points: {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: { uuid: string; name: string; speed: number; processes: { triggerId: string; startPoint: string; endPoint: string }[]; };
|
||||
triggers: { uuid: string; name: string; type: string };
|
||||
connections: {
|
||||
source: { modelUUID: string; pointUUID: string };
|
||||
targets: { modelUUID: string; pointUUID: string }[];
|
||||
};
|
||||
};
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
}
|
||||
|
||||
interface AssetEventSchema {
|
||||
modelUuid: string;
|
||||
modelName: string;
|
||||
@@ -117,7 +21,7 @@ interface TransferPointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
action: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "default" | "spawn" | "swap" | "despawn";
|
||||
@@ -125,15 +29,15 @@ interface TransferPointSchema {
|
||||
delay: number | "inherit";
|
||||
spawnInterval: number | "inherit";
|
||||
spawnCount: number | "inherit";
|
||||
triggers: TriggerSchema[] | [];
|
||||
}[];
|
||||
triggers: TriggerSchema[];
|
||||
};
|
||||
}
|
||||
|
||||
interface VehiclePointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
action: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "travel";
|
||||
@@ -142,8 +46,8 @@ interface VehiclePointSchema {
|
||||
loadCapacity: number;
|
||||
pickUpPoint: { x: number; y: number, z: number } | {};
|
||||
unLoadPoint: { x: number; y: number, z: number } | {};
|
||||
triggers: TriggerSchema[] | [];
|
||||
}[];
|
||||
triggers: TriggerSchema[];
|
||||
};
|
||||
}
|
||||
|
||||
interface RoboticArmPointSchema {
|
||||
@@ -155,7 +59,7 @@ interface RoboticArmPointSchema {
|
||||
actionName: string;
|
||||
actionType: "pickAndPlace";
|
||||
process: { startPoint: string; endPoint: string };
|
||||
triggers: TriggerSchema[] | [];
|
||||
triggers: TriggerSchema[];
|
||||
}[];
|
||||
}
|
||||
|
||||
@@ -163,27 +67,27 @@ interface MachinePointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
action: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "process";
|
||||
processTime: number;
|
||||
swapMaterial: string;
|
||||
triggers: TriggerSchema[] | [];
|
||||
}[];
|
||||
triggers: TriggerSchema[];
|
||||
};
|
||||
}
|
||||
|
||||
interface StoragePointSchema {
|
||||
uuid: string;
|
||||
position: [number, number, number];
|
||||
rotation: [number, number, number];
|
||||
actions: {
|
||||
action: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "storage";
|
||||
materials: { materialName: string; materialId: string; quantity: number }[];
|
||||
storageCapacity: number;
|
||||
}[];
|
||||
};
|
||||
}
|
||||
|
||||
interface TransferEventSchema extends AssetEventSchema {
|
||||
@@ -220,4 +124,4 @@ type productsSchema = {
|
||||
productName: string;
|
||||
productId: string;
|
||||
eventsData: EventsSchema[];
|
||||
}[] | []
|
||||
}[]
|
||||
Reference in New Issue
Block a user