diff --git a/app/src/components/layout/sidebarRight/SideBarRight.tsx b/app/src/components/layout/sidebarRight/SideBarRight.tsx index 6581d5f..b37630b 100644 --- a/app/src/components/layout/sidebarRight/SideBarRight.tsx +++ b/app/src/components/layout/sidebarRight/SideBarRight.tsx @@ -37,9 +37,8 @@ const SideBarRight: React.FC = () => {
{/* {activeModule === "builder" && ( */}
setSubModule("properties")} > @@ -84,6 +83,17 @@ const SideBarRight: React.FC = () => {
)} + {toggleUI && + subModule === "zoneProperties" && + activeModule === "builder" && ( +
+
+ {/* */} + + {/* */} +
+
+ )} {/* simulation */} {toggleUI && activeModule === "simulation" && ( diff --git a/app/src/components/layout/sidebarRight/customInput/Vector3Input.tsx b/app/src/components/layout/sidebarRight/customInput/Vector3Input.tsx index 05b7041..38fae4e 100644 --- a/app/src/components/layout/sidebarRight/customInput/Vector3Input.tsx +++ b/app/src/components/layout/sidebarRight/customInput/Vector3Input.tsx @@ -1,62 +1,57 @@ import React from "react"; import { EyeDroperIcon } from "../../../icons/ExportCommonIcons"; +// import { useThree } from "@react-three/fiber"; interface PositionInputProps { - onChange: (value: string) => void; // Callback for value change + onChange: (value: [number, number, number]) => void; // Callback for value change header: string; placeholder?: string; // Optional placeholder type?: string; // Input type (e.g., text, number, email) + value: [number, number, number] | null; + disabled?: boolean; // To enable/disable editing } const Vector3Input: React.FC = ({ onChange, header, placeholder = "Enter value", // Default placeholder - type = "number", // Default type + type = "string", // Default type + value, + disabled = false, // Default to disabled }) => { + + const handleChange = (index: number, newValue: string) => { + if (!value) return; + const updatedValue = [...value] as [number, number, number]; + updatedValue[index] = parseFloat(newValue) || 0; + console.log('updatedValue: ', updatedValue); + onChange(updatedValue); + }; + + + return (
- {header}{" "} -
- -
+ {header}
-
-
X :
- onChange(e.target.value)} - placeholder={placeholder} - disabled - /> -
-
-
Y :
- onChange(e.target.value)} - placeholder={placeholder} - disabled - min={0} - /> -
-
-
Z :
- onChange(e.target.value)} - placeholder={placeholder} - disabled - /> -
+ {["X", "Y", "Z"].map((axis, i) => ( +
+
{axis}:
+ handleChange(i, e.target.value)} + placeholder={placeholder} + disabled={disabled} + /> +
+ ))}
); }; -export default Vector3Input; +export default Vector3Input; \ No newline at end of file diff --git a/app/src/components/layout/sidebarRight/properties/ZoneProperties.tsx b/app/src/components/layout/sidebarRight/properties/ZoneProperties.tsx index 4baf91c..c707f14 100644 --- a/app/src/components/layout/sidebarRight/properties/ZoneProperties.tsx +++ b/app/src/components/layout/sidebarRight/properties/ZoneProperties.tsx @@ -2,37 +2,64 @@ import React, { useEffect, useState } from "react"; import RenameInput from "../../../ui/inputs/RenameInput"; import Vector3Input from "../customInput/Vector3Input"; import { useSelectedZoneStore } from "../../../../store/useZoneStore"; +import { useEditPosition, usezonePosition, usezoneTarget } from "../../../../store/store"; const ZoneProperties: React.FC = () => { - const [Edit, setEdit] = useState(false); + const { Edit, setEdit } = useEditPosition(); const { selectedZone, setSelectedZone } = useSelectedZoneStore(); + const { zonePosition, setZonePosition } = usezonePosition(); + const { zoneTarget, setZoneTarget } = usezoneTarget(); + + useEffect(() => { + setZonePosition(selectedZone.zoneViewPortPosition) + setZoneTarget(selectedZone.zoneViewPortTarget) + }, [selectedZone?.zoneViewPortPosition, selectedZone?.zoneViewPortTarget]) function handleSetView() { + console.log("setApi"); + + console.log('zoneTarget: ', zoneTarget); + console.log('zonePosition: ', zonePosition); setEdit(false); } function handleEditView() { - if (Edit) { - setEdit(false); - } else { - setEdit(true); - } + setEdit(!Edit); // This will toggle the `Edit` state correctly } - useEffect(() => { - console.log(' selectedZone.zoneName: ', selectedZone.zoneName); - }, [selectedZone]) + function handleZoneNameChange(newName: string) { + setSelectedZone((prev) => ({ ...prev, zoneName: newName })); + } + + function handleVectorChange(key: "zoneViewPortTarget" | "zoneViewPortPosition", newValue: [number, number, number]) { + setSelectedZone((prev) => ({ ...prev, [key]: newValue })); + } + + useEffect(() => { + console.log("Updated selectedZone: ", selectedZone); + }, [selectedZone]); return (
- +
{Edit ? "Cancel" : "Edit"}
- { }} header="Viewport Target" /> - { }} header="Viewport Position" /> + handleVectorChange("zoneViewPortTarget", value)} + header="Viewport Target" + value={zoneTarget as [number, number, number]} + disabled={!Edit} + /> + handleVectorChange("zoneViewPortPosition", value)} + header="Viewport Position" + value={zonePosition as [number, number, number]} + disabled={!Edit} + /> + {Edit && (
Set View @@ -43,3 +70,4 @@ const ZoneProperties: React.FC = () => { }; export default ZoneProperties; + diff --git a/app/src/components/ui/componets/AddButtons.tsx b/app/src/components/ui/componets/AddButtons.tsx index 6b182f9..42dc082 100644 --- a/app/src/components/ui/componets/AddButtons.tsx +++ b/app/src/components/ui/componets/AddButtons.tsx @@ -129,8 +129,8 @@ const AddButtons: React.FC = ({ }; const email = localStorage.getItem('email') const organization = (email!.split("@")[1]).split(".")[0]; - let response = panelData(organization, selectedZone.zoneId, newActiveSides) - console.log('response: ', response); + // let response = panelData(organization, selectedZone.zoneId, newActiveSides) + // console.log('response: ', response); // Update the selectedZone state console.log("updatedZone: ", updatedZone); @@ -140,7 +140,6 @@ const AddButtons: React.FC = ({ return ( <> -
{(["top", "right", "bottom", "left"] as Side[]).map((side) => (
diff --git a/app/src/components/ui/componets/DroppedFloatingWidgets.tsx b/app/src/components/ui/componets/DroppedFloatingWidgets.tsx index 19b1717..f7c1bd3 100644 --- a/app/src/components/ui/componets/DroppedFloatingWidgets.tsx +++ b/app/src/components/ui/componets/DroppedFloatingWidgets.tsx @@ -1,59 +1,89 @@ -import { useState } from "react"; -import { useThree } from "@react-three/fiber"; -import * as THREE from "three"; +// import { useState } from "react"; +// import { useThree } from "@react-three/fiber"; +// import * as THREE from "three"; -const DroppedObjects = () => { - const { camera } = useThree(); // Now inside Canvas ✅ - const [objects, setObjects] = useState<{ id: number; position: [number, number, number] }[]>([]); - // Function to convert drop event into 3D position - const handleDrop = (event: DragEvent) => { - event.preventDefault(); - const data = event.dataTransfer?.getData("text/plain"); - if (!data) return; +// const DroppedObjects = () => { +// const { camera } = useThree(); // Now inside Canvas ✅ +// const [objects, setObjects] = useState<{ id: number; position: [number, number, number] }[]>([]); - try { - const cardData = JSON.parse(data); - if (!cardData.className.includes("floating total-card")) { - console.log("Drop rejected: Incorrect element."); - return; - } +// // Function to convert drop event into 3D position +// const handleDrop = (event: DragEvent) => { +// event.preventDefault(); - // Convert 2D drop position to 3D world coordinates - const x = (event.clientX / window.innerWidth) * 2 - 1; - const y = -(event.clientY / window.innerHeight) * 2 + 1; +// const data = event.dataTransfer?.getData("text/plain"); +// if (!data) return; - // Raycasting to determine the drop position in 3D - const raycaster = new THREE.Raycaster(); - const mouseVector = new THREE.Vector2(x, y); - raycaster.setFromCamera(mouseVector, camera); +// try { +// const cardData = JSON.parse(data); +// if (!cardData.className.includes("floating total-card")) { +// console.log("Drop rejected: Incorrect element."); +// return; +// } - // Intersect with a ground plane (assume y = 0) - const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0); - const intersection = new THREE.Vector3(); - raycaster.ray.intersectPlane(groundPlane, intersection); +// // Convert 2D drop position to 3D world coordinates +// const x = (event.clientX / window.innerWidth) * 2 - 1; +// const y = -(event.clientY / window.innerHeight) * 2 + 1; - console.log("Spawn Object at:", intersection); +// // Raycasting to determine the drop position in 3D +// const raycaster = new THREE.Raycaster(); +// const mouseVector = new THREE.Vector2(x, y); +// raycaster.setFromCamera(mouseVector, camera); - // Add the dropped object to the scene state - setObjects((prev) => [...prev, { id: Date.now(), position: [intersection.x, intersection.y, intersection.z] }]); - } catch (error) { - console.error("Invalid data:", error); - } - }; +// // Intersect with a ground plane (assume y = 0) +// const groundPlane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0); +// const intersection = new THREE.Vector3(); +// raycaster.ray.intersectPlane(groundPlane, intersection); + +// console.log("Spawn Object at:", intersection); + +// // Add the dropped object to the scene state +// setObjects((prev) => [...prev, { id: Date.now(), position: [intersection.x, intersection.y, intersection.z] }]); +// } catch (error) { +// console.error("Invalid data:", error); +// } +// }; + +// return ( +// +// {/* Render dropped objects as green boxes */} +// {objects.map((obj) => ( +// +// +// +// +// ))} +// +// ); +// }; + +import { Html } from "@react-three/drei"; +import { useDroppedObjectsStore } from "../../../store/store"; + + +const DroppedObjects: React.FC = () => { + const objects = useDroppedObjectsStore((state) => state.objects); // Get objects from Zustand store + console.log('objects: ', objects); return ( - - {/* Render dropped objects as green boxes */} - {objects.map((obj) => ( - - - - + <> + {objects.map((obj, index) => ( + + +
+
{obj.header}
+
+
{obj.value}
+
{obj.per}
+
+
+ +
))} -
+ ); }; export default DroppedObjects; + diff --git a/app/src/components/ui/componets/RealTimeVisulization.tsx b/app/src/components/ui/componets/RealTimeVisulization.tsx index f5efce3..cecc2c0 100644 --- a/app/src/components/ui/componets/RealTimeVisulization.tsx +++ b/app/src/components/ui/componets/RealTimeVisulization.tsx @@ -6,7 +6,8 @@ import { useSelectedZoneStore } from "../../../store/useZoneStore"; import DisplayZone from "./DisplayZone"; import Scene from "../../../modules/scene/scene"; import useModuleStore from "../../../store/useModuleStore"; -import { useZones } from "../../../store/store"; +import { useDroppedObjectsStore, useZones } from "../../../store/store"; +import DroppedObjects from "./DroppedFloatingWidgets"; @@ -37,14 +38,14 @@ const RealTimeVisulization: React.FC = () => { const containerRef = useRef(null); const { isPlaying } = usePlayButtonStore(); const { activeModule } = useModuleStore(); - + const [droppedObjects, setDroppedObjects] = useState([]); const [zonesData, setZonesData] = useState({}); const { selectedZone, setSelectedZone } = useSelectedZoneStore(); const { zones } = useZones() useEffect(() => { const data = Array.isArray(zones) ? zones : []; - console.log('data: ', data); + const formattedData = data.reduce((acc, zone) => { acc[zone.zoneName] = { activeSides: [], @@ -80,23 +81,37 @@ const RealTimeVisulization: React.FC = () => { }); }, [selectedZone]); + // const handleDrop = (event: React.DragEvent) => { + // console.log("Drop event fired! ✅"); + // event.preventDefault(); + + // const data = event.dataTransfer.getData("text/plain"); + // if (!data) { + // console.log("❌ No data received on drop!"); + // return; + // } + + // try { + // const droppedData = JSON.parse(data); + // console.log("✅ Dropped Data:", droppedData); + + // console.log('droppedData: ', droppedData); + // setDroppedObjects((prev) => [...prev, droppedData]); // ✅ Add to state + // console.log(droppedObjects); + // } catch (error) { + // console.error("❌ Error parsing dropped data:", error); + // } + // }; const handleDrop = (event: React.DragEvent) => { event.preventDefault(); - const canvas = document.querySelector(".scene-container"); - if (canvas) { - // Extract relevant properties manually - const dragEvent = new DragEvent("drop", { - bubbles: true, - cancelable: true, - dataTransfer: event.dataTransfer, // Attach dataTransfer manually ✅ - }); + const data = event.dataTransfer.getData("text/plain"); // Use "text/plain" to match the drag event - console.log('dragEvent: ', dragEvent); - canvas.dispatchEvent(dragEvent); + if (data) { + const droppedData = JSON.parse(data); + useDroppedObjectsStore.getState().addObject(droppedData); // Add to Zustand store } }; - return (
{ width: "100%", borderRadius: isPlaying || activeModule !== "visualization" ? "" : "6px", }} - onDrop={handleDrop} + onDrop={(event) => handleDrop(event)} + onDragOver={(event) => event.preventDefault()} > - {/* {objects.map((obj) => ( - - - - - ))} */} +
{activeModule === "visualization" && ( @@ -146,7 +157,7 @@ const RealTimeVisulization: React.FC = () => { hiddenPanels={hiddenPanels} selectedZone={selectedZone} setSelectedZone={setSelectedZone} - + /> )} diff --git a/app/src/components/ui/componets/zoneCameraTarget.tsx b/app/src/components/ui/componets/zoneCameraTarget.tsx index 8605afa..2412926 100644 --- a/app/src/components/ui/componets/zoneCameraTarget.tsx +++ b/app/src/components/ui/componets/zoneCameraTarget.tsx @@ -1,13 +1,17 @@ import { useEffect, useMemo, useRef, useState } from "react"; -import { useThree } from "@react-three/fiber"; +import { useFrame, useThree } from "@react-three/fiber"; import * as THREE from "three"; import { useSelectedZoneStore } from "../../../store/useZoneStore"; +import { useEditPosition, usezonePosition, usezoneTarget } from "../../../store/store"; export default function ZoneCentreTarget() { const { selectedZone, setSelectedZone } = useSelectedZoneStore(); const [previousZoneCentre, setPreviousZoneCentre] = useState(null); const sphereRef = useRef(null); const { camera, controls }: any = useThree(); + const { zonePosition, setZonePosition } = usezonePosition(); + const { zoneTarget, setZoneTarget } = usezoneTarget(); + const { Edit, setEdit } = useEditPosition(); useEffect(() => { @@ -32,9 +36,9 @@ export default function ZoneCentreTarget() { sphereRef.current.position.set(selectedZone.zoneViewPortTarget[0], selectedZone.zoneViewPortTarget[1], selectedZone.zoneViewPortTarget[2]); } if (centrePoint) { - + if (centrePoint.length > 0) { - + let camPosition = new THREE.Vector3(...selectedZone.zoneViewPortPosition); let CamTarget = new THREE.Vector3(...selectedZone.zoneViewPortTarget); @@ -63,7 +67,7 @@ export default function ZoneCentreTarget() { }; setCam(); } else { - + let camPosition = new THREE.Vector3(...selectedZone.zoneViewPortPosition); let CamTarget = new THREE.Vector3(...selectedZone.zoneViewPortTarget); @@ -89,7 +93,14 @@ export default function ZoneCentreTarget() { } } } - }, [selectedZone.zoneViewPortTarget, camera, controls]); + }, [selectedZone.zoneViewPortTarget]); + + useFrame(() => { + if (Edit) { + setZonePosition([controls.getPosition().x, controls.getPosition().y, controls.getPosition().z]) + setZoneTarget([controls.getTarget().x, controls.getTarget().y, controls.getTarget().z]) + } + }) return ( <> ); diff --git a/app/src/components/ui/inputs/RenameInput.tsx b/app/src/components/ui/inputs/RenameInput.tsx index cae54f3..d197dd4 100644 --- a/app/src/components/ui/inputs/RenameInput.tsx +++ b/app/src/components/ui/inputs/RenameInput.tsx @@ -1,4 +1,4 @@ -import React, { useState, useRef } from "react"; +import React, { useState, useRef, useEffect } from "react"; interface RenameInputProps { value: string; @@ -9,6 +9,9 @@ const RenameInput: React.FC = ({ value, onRename }) => { const [isEditing, setIsEditing] = useState(false); const [text, setText] = useState(value); const inputRef = useRef(null); + useEffect(() => { + setText(value); // Ensure state updates when parent value changes + }, [value]); const handleDoubleClick = () => { setIsEditing(true); diff --git a/app/src/components/ui/list/List.tsx b/app/src/components/ui/list/List.tsx index eb8468b..7a7da8d 100644 --- a/app/src/components/ui/list/List.tsx +++ b/app/src/components/ui/list/List.tsx @@ -12,17 +12,14 @@ interface ListProps { } const List: React.FC = ({ items = [], remove }) => { - console.log("items: ", items); - - const { selectedZone, setSelectedZone } = useSelectedZoneStore(); - const { subModule, setSubModule } = useSubModuleStore(); + const { setSelectedZone } = useSelectedZoneStore(); + const { setSubModule } = useSubModuleStore(); async function handleSelectZone(id: string) { setSubModule("zoneProperties") const email = localStorage.getItem('email') const organization = (email!.split("@")[1]).split(".")[0]; let response = await getZoneData(id, organization) - console.log('response: ', response); setSelectedZone({ zoneName: response?.zoneName, activeSides: response?.activeSides || [], diff --git a/app/src/components/ui/realTimeVis/floating/SimpleCard.tsx b/app/src/components/ui/realTimeVis/floating/SimpleCard.tsx index fca0c3d..ef3d85c 100644 --- a/app/src/components/ui/realTimeVis/floating/SimpleCard.tsx +++ b/app/src/components/ui/realTimeVis/floating/SimpleCard.tsx @@ -19,8 +19,11 @@ const SimpleCard: React.FC = ({ header, value, per, - className: event.currentTarget.className, // Store the class name + className: event.currentTarget.className, }); + + console.log("Dragging Data:", cardData); // ✅ Debugging log + event.dataTransfer.setData("text/plain", cardData); }; diff --git a/app/src/modules/scene/scene.tsx b/app/src/modules/scene/scene.tsx index 9286a66..0b8987f 100644 --- a/app/src/modules/scene/scene.tsx +++ b/app/src/modules/scene/scene.tsx @@ -20,6 +20,7 @@ import ZoneCentreTarget from "../../components/ui/componets/zoneCameraTarget"; import { useThree } from "@react-three/fiber"; import * as THREE from "three"; import DroppedObjects from "../../components/ui/componets/DroppedFloatingWidgets"; + // import Simulation from "./simulationtemp/simulation"; export default function Scene() { @@ -44,7 +45,7 @@ export default function Scene() { onContextMenu={(e) => { e.preventDefault(); }} - + > diff --git a/app/src/services/realTimeVisulization/zoneData/panel.tsx b/app/src/services/realTimeVisulization/zoneData/panel.ts similarity index 97% rename from app/src/services/realTimeVisulization/zoneData/panel.tsx rename to app/src/services/realTimeVisulization/zoneData/panel.ts index 793bedb..5e0b5ac 100644 --- a/app/src/services/realTimeVisulization/zoneData/panel.tsx +++ b/app/src/services/realTimeVisulization/zoneData/panel.ts @@ -1,4 +1,4 @@ -let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`; +let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_BACKEND_URL}`; type Side = "top" | "bottom" | "left" | "right"; diff --git a/app/src/store/store.ts b/app/src/store/store.ts index 0cca1fe..86c6dee 100644 --- a/app/src/store/store.ts +++ b/app/src/store/store.ts @@ -1,324 +1,344 @@ import * as THREE from "three"; -import * as Types from '../types/world/worldTypes'; +import * as Types from "../types/world/worldTypes"; import { create } from "zustand"; import { io } from "socket.io-client"; export const useSocketStore = create((set: any, get: any) => ({ - socket: null, - initializeSocket: (email: any) => { - const existingSocket = get().socket; - if (existingSocket) { - return; - } - - const socket = io(`http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/`, { - reconnection: false, - auth: { email } - }); - - set({ socket }); - }, - disconnectSocket: () => { - set((state: any) => { - state.socket?.disconnect(); - return { socket: null }; - }); + socket: null, + initializeSocket: (email: any) => { + const existingSocket = get().socket; + if (existingSocket) { + return; } + + const socket = io( + `http://${process.env.REACT_APP_SERVER_SOCKET_API_BASE_URL}/`, + { + reconnection: false, + auth: { email }, + } + ); + + set({ socket }); + }, + disconnectSocket: () => { + set((state: any) => { + state.socket?.disconnect(); + return { socket: null }; + }); + }, })); export const useOrganization = create((set: any) => ({ - organization: "", - setOrganization: (x: any) => set(() => ({ organization: x })), + organization: "", + setOrganization: (x: any) => set(() => ({ organization: x })), })); export const useToggleView = create((set: any) => ({ - toggleView: false, - setToggleView: (x: any) => set(() => ({ toggleView: x })), + toggleView: false, + setToggleView: (x: any) => set(() => ({ toggleView: x })), })); export const useUpdateScene = create((set: any) => ({ - updateScene: false, - setUpdateScene: (x: any) => set(() => ({ updateScene: x })), + updateScene: false, + setUpdateScene: (x: any) => set(() => ({ updateScene: x })), })); export const useWalls = create((set: any) => ({ - walls: [], - setWalls: (x: any) => set(() => ({ walls: x })), + walls: [], + setWalls: (x: any) => set(() => ({ walls: x })), })); export const useZones = create((set: any) => ({ - zones: [], - setZones: (x: any) => set(() => ({ zones: x })), + zones: [], + setZones: (x: any) => set(() => ({ zones: x })), })); interface ZonePointsState { - zonePoints: THREE.Vector3[]; - setZonePoints: (points: THREE.Vector3[]) => void; + zonePoints: THREE.Vector3[]; + setZonePoints: (points: THREE.Vector3[]) => void; } export const useZonePoints = create((set) => ({ - zonePoints: [], - setZonePoints: (points) => set({ zonePoints: points }), + zonePoints: [], + setZonePoints: (points) => set({ zonePoints: points }), })); export const useSelectedItem = create((set: any) => ({ - selectedItem: { name: "", id: "" }, - setSelectedItem: (x: any) => set(() => ({ selectedItem: x })), + selectedItem: { name: "", id: "" }, + setSelectedItem: (x: any) => set(() => ({ selectedItem: x })), })); export const useSelectedAssets = create((set: any) => ({ - selectedAssets: [], - setSelectedAssets: (x: any) => set(() => ({ selectedAssets: x })), + selectedAssets: [], + setSelectedAssets: (x: any) => set(() => ({ selectedAssets: x })), })); export const useLayers = create((set: any) => ({ - Layers: 1, - setLayers: (x: any) => set(() => ({ Layers: x })), + Layers: 1, + setLayers: (x: any) => set(() => ({ Layers: x })), })); export const useCamPosition = create((set: any) => ({ - camPosition: { x: undefined, y: undefined, z: undefined }, - setCamPosition: (newCamPosition: any) => set({ camPosition: newCamPosition }), + camPosition: { x: undefined, y: undefined, z: undefined }, + setCamPosition: (newCamPosition: any) => set({ camPosition: newCamPosition }), })); export const useMenuVisible = create((set: any) => ({ - menuVisible: false, - setMenuVisible: (x: any) => set(() => ({ menuVisible: x })), + menuVisible: false, + setMenuVisible: (x: any) => set(() => ({ menuVisible: x })), })); export const useDeleteModels = create((set: any) => ({ - deleteModels: false, - setDeleteModels: (x: any) => set(() => ({ deleteModels: x })), + deleteModels: false, + setDeleteModels: (x: any) => set(() => ({ deleteModels: x })), })); export const useToolMode = create((set: any) => ({ - toolMode: null, - setToolMode: (x: any) => set(() => ({ toolMode: x })), + toolMode: null, + setToolMode: (x: any) => set(() => ({ toolMode: x })), })); export const useNewLines = create((set: any) => ({ - newLines: [], - setNewLines: (x: any) => set(() => ({ newLines: x })), + newLines: [], + setNewLines: (x: any) => set(() => ({ newLines: x })), })); export const useDeletedLines = create((set: any) => ({ - deletedLines: [], - setDeletedLines: (x: any) => set(() => ({ deletedLines: x })), + deletedLines: [], + setDeletedLines: (x: any) => set(() => ({ deletedLines: x })), })); export const useMovePoint = create((set: any) => ({ - movePoint: false, - setMovePoint: (x: any) => set(() => ({ movePoint: x })), + movePoint: false, + setMovePoint: (x: any) => set(() => ({ movePoint: x })), })); export const useTransformMode = create((set: any) => ({ - transformMode: null, - setTransformMode: (x: any) => set(() => ({ transformMode: x })), + transformMode: null, + setTransformMode: (x: any) => set(() => ({ transformMode: x })), })); export const useDeletePointOrLine = create((set: any) => ({ - deletePointOrLine: false, - setDeletePointOrLine: (x: any) => set(() => ({ deletePointOrLine: x })), + deletePointOrLine: false, + setDeletePointOrLine: (x: any) => set(() => ({ deletePointOrLine: x })), })); export const useFloorItems = create((set: any) => ({ - floorItems: null, - setFloorItems: (callback: any) => - set((state: any) => ({ - floorItems: - typeof callback === "function" - ? callback(state.floorItems) - : callback, - })), + floorItems: null, + setFloorItems: (callback: any) => + set((state: any) => ({ + floorItems: + typeof callback === "function" ? callback(state.floorItems) : callback, + })), })); export const useWallItems = create((set: any) => ({ - wallItems: [], - setWallItems: (callback: any) => - set((state: any) => ({ - wallItems: - typeof callback === "function" - ? callback(state.wallItems) - : callback, - })), + wallItems: [], + setWallItems: (callback: any) => + set((state: any) => ({ + wallItems: + typeof callback === "function" ? callback(state.wallItems) : callback, + })), })); export const useSelectedWallItem = create((set: any) => ({ - selectedWallItem: null, - setSelectedWallItem: (x: any) => set(() => ({ selectedWallItem: x })), + selectedWallItem: null, + setSelectedWallItem: (x: any) => set(() => ({ selectedWallItem: x })), })); export const useselectedFloorItem = create((set: any) => ({ - selectedFloorItem: null, - setselectedFloorItem: (x: any) => set(() => ({ selectedFloorItem: x })), + selectedFloorItem: null, + setselectedFloorItem: (x: any) => set(() => ({ selectedFloorItem: x })), })); export const useDeletableFloorItem = create((set: any) => ({ - deletableFloorItem: null, - setDeletableFloorItem: (x: any) => set(() => ({ deletableFloorItem: x })), + deletableFloorItem: null, + setDeletableFloorItem: (x: any) => set(() => ({ deletableFloorItem: x })), })); export const useSetScale = create((set: any) => ({ - scale: null, - setScale: (x: any) => set(() => ({ scale: x })), + scale: null, + setScale: (x: any) => set(() => ({ scale: x })), })); export const useRoofVisibility = create((set: any) => ({ - roofVisibility: false, - setRoofVisibility: (x: any) => set(() => ({ roofVisibility: x })), + roofVisibility: false, + setRoofVisibility: (x: any) => set(() => ({ roofVisibility: x })), })); export const useWallVisibility = create((set: any) => ({ - wallVisibility: false, - setWallVisibility: (x: any) => set(() => ({ wallVisibility: x })), + wallVisibility: false, + setWallVisibility: (x: any) => set(() => ({ wallVisibility: x })), })); export const useShadows = create((set: any) => ({ - shadows: false, - setShadows: (x: any) => set(() => ({ shadows: x })), + shadows: false, + setShadows: (x: any) => set(() => ({ shadows: x })), })); export const useSunPosition = create((set: any) => ({ - sunPosition: { x: undefined, y: undefined, z: undefined }, - setSunPosition: (newSuntPosition: any) => set({ sunPosition: newSuntPosition }), + sunPosition: { x: undefined, y: undefined, z: undefined }, + setSunPosition: (newSuntPosition: any) => + set({ sunPosition: newSuntPosition }), })); export const useRemoveLayer = create((set: any) => ({ - removeLayer: false, - setRemoveLayer: (x: any) => set(() => ({ removeLayer: x })), + removeLayer: false, + setRemoveLayer: (x: any) => set(() => ({ removeLayer: x })), })); export const useRemovedLayer = create((set: any) => ({ - removedLayer: null, - setRemovedLayer: (x: any) => set(() => ({ removedLayer: x })), + removedLayer: null, + setRemovedLayer: (x: any) => set(() => ({ removedLayer: x })), })); export const useActiveLayer = create((set: any) => ({ - activeLayer: 1, - setActiveLayer: (x: any) => set({ activeLayer: x }), + activeLayer: 1, + setActiveLayer: (x: any) => set({ activeLayer: x }), })); export const useResetCamera = create((set: any) => ({ - resetCamera: false, - setResetCamera: (x: any) => set({ resetCamera: x }), + resetCamera: false, + setResetCamera: (x: any) => set({ resetCamera: x }), })); export const useAddAction = create((set: any) => ({ - addAction: null, - setAddAction: (x: any) => set({ addAction: x }), + addAction: null, + setAddAction: (x: any) => set({ addAction: x }), })); export const useActiveTool = create((set: any) => ({ - activeTool: "Cursor", - setActiveTool: (x: any) => set({ activeTool: x }), + activeTool: "Cursor", + setActiveTool: (x: any) => set({ activeTool: x }), })); export const use2DUndoRedo = create((set: any) => ({ - is2DUndoRedo: null, - set2DUndoRedo: (x: any) => set({ is2DUndoRedo: x }), -})) + is2DUndoRedo: null, + set2DUndoRedo: (x: any) => set({ is2DUndoRedo: x }), +})); export const useElevation = create((set: any) => ({ - elevation: 45, - setElevation: (x: any) => set({ elevation: x }), + elevation: 45, + setElevation: (x: any) => set({ elevation: x }), })); export const useAzimuth = create((set: any) => ({ - azimuth: -160, - setAzimuth: (x: any) => set({ azimuth: x }), + azimuth: -160, + setAzimuth: (x: any) => set({ azimuth: x }), })); export const useRenderDistance = create((set: any) => ({ - renderDistance: 50, - setRenderDistance: (x: any) => set({ renderDistance: x }), + renderDistance: 50, + setRenderDistance: (x: any) => set({ renderDistance: x }), })); export const useCamMode = create((set: any) => ({ - camMode: "ThirdPerson", - setCamMode: (x: any) => set({ camMode: x }), + camMode: "ThirdPerson", + setCamMode: (x: any) => set({ camMode: x }), })); export const useUserName = create((set: any) => ({ - userName: "", - setUserName: (x: any) => set({ userName: x }), + userName: "", + setUserName: (x: any) => set({ userName: x }), })); export const useObjectPosition = create((set: any) => ({ - objectPosition: { x: undefined, y: undefined, z: undefined }, - setObjectPosition: (newObjectPosition: any) => set({ objectPosition: newObjectPosition }), + objectPosition: { x: undefined, y: undefined, z: undefined }, + setObjectPosition: (newObjectPosition: any) => + set({ objectPosition: newObjectPosition }), })); export const useObjectScale = create((set: any) => ({ - objectScale: { x: undefined, y: undefined, z: undefined }, - setObjectScale: (newObjectScale: any) => set({ objectScale: newObjectScale }), + objectScale: { x: undefined, y: undefined, z: undefined }, + setObjectScale: (newObjectScale: any) => set({ objectScale: newObjectScale }), })); export const useObjectRotation = create((set: any) => ({ - objectRotation: { x: undefined, y: undefined, z: undefined }, - setObjectRotation: (newObjectRotation: any) => set({ objectRotation: newObjectRotation }), + objectRotation: { x: undefined, y: undefined, z: undefined }, + setObjectRotation: (newObjectRotation: any) => + set({ objectRotation: newObjectRotation }), })); export const useDrieTemp = create((set: any) => ({ - drieTemp: undefined, - setDrieTemp: (x: any) => set({ drieTemp: x }), + drieTemp: undefined, + setDrieTemp: (x: any) => set({ drieTemp: x }), })); export const useActiveUsers = create((set: any) => ({ - activeUsers: [], - setActiveUsers: (x: any) => set({ activeUsers: x }), + activeUsers: [], + setActiveUsers: (x: any) => set({ activeUsers: x }), })); export const useDrieUIValue = create((set: any) => ({ - drieUIValue: { touch: null, temperature: null, humidity: null }, + drieUIValue: { touch: null, temperature: null, humidity: null }, - setDrieUIValue: (x: any) => set((state: any) => ({ drieUIValue: { ...state.drieUIValue, ...x } })), + setDrieUIValue: (x: any) => + set((state: any) => ({ drieUIValue: { ...state.drieUIValue, ...x } })), - setTouch: (value: any) => set((state: any) => ({ drieUIValue: { ...state.drieUIValue, touch: value } })), - setTemperature: (value: any) => set((state: any) => ({ drieUIValue: { ...state.drieUIValue, temperature: value } })), - setHumidity: (value: any) => set((state: any) => ({ drieUIValue: { ...state.drieUIValue, humidity: value } })), + setTouch: (value: any) => + set((state: any) => ({ + drieUIValue: { ...state.drieUIValue, touch: value }, + })), + setTemperature: (value: any) => + set((state: any) => ({ + drieUIValue: { ...state.drieUIValue, temperature: value }, + })), + setHumidity: (value: any) => + set((state: any) => ({ + drieUIValue: { ...state.drieUIValue, humidity: value }, + })), })); export const useDrawMaterialPath = create((set: any) => ({ - drawMaterialPath: false, - setDrawMaterialPath: (x: any) => set({ drawMaterialPath: x }), + drawMaterialPath: false, + setDrawMaterialPath: (x: any) => set({ drawMaterialPath: x }), })); export const useSelectedActionSphere = create((set: any) => ({ - selectedActionSphere: undefined, - setSelectedActionSphere: (x: any) => set({ selectedActionSphere: x }), + selectedActionSphere: undefined, + setSelectedActionSphere: (x: any) => set({ selectedActionSphere: x }), })); export const useSelectedPath = create((set: any) => ({ - selectedPath: undefined, - setSelectedPath: (x: any) => set({ selectedPath: x }), + selectedPath: undefined, + setSelectedPath: (x: any) => set({ selectedPath: x }), })); interface Path { - modeluuid: string; - modelName: string; - points: { - uuid: string; - position: [number, number, number]; - rotation: [number, number, number]; - actions: { uuid: string; type: string; material: string; delay: number | string; spawnInterval: number | string; isUsed: boolean }[] | []; - triggers: { uuid: string; type: string; isUsed: boolean }[] | []; - }[]; - pathPosition: [number, number, number]; - pathRotation: [number, number, number]; - speed: number; + modeluuid: string; + modelName: string; + points: { + uuid: string; + position: [number, number, number]; + rotation: [number, number, number]; + actions: + | { + uuid: string; + type: string; + material: string; + delay: number | string; + spawnInterval: number | string; + isUsed: boolean; + }[] + | []; + triggers: { uuid: string; type: string; isUsed: boolean }[] | []; + }[]; + pathPosition: [number, number, number]; + pathRotation: [number, number, number]; + speed: number; } interface SimulationPathsStore { - simulationPaths: Path[]; - setSimulationPaths: (paths: Path[]) => void; + simulationPaths: Path[]; + setSimulationPaths: (paths: Path[]) => void; } export const useSimulationPaths = create((set) => ({ - simulationPaths: [], - setSimulationPaths: (paths) => set({ simulationPaths: paths }), + simulationPaths: [], + setSimulationPaths: (paths) => set({ simulationPaths: paths }), })); - // interface Point { // uuid: string; // position: [number, number, number]; @@ -363,40 +383,75 @@ export const useSimulationPaths = create((set) => ({ // setSimulationPaths: (paths) => set({ simulationPaths: paths }), // })); - export const useConnections = create((set) => ({ - connections: [], + connections: [], - setConnections: (connections) => set({ connections }), + setConnections: (connections) => set({ connections }), - addConnection: (newConnection) => - set((state) => ({ - connections: [...state.connections, newConnection], - })), + addConnection: (newConnection) => + set((state) => ({ + connections: [...state.connections, newConnection], + })), - removeConnection: (fromUUID, toUUID) => - set((state) => ({ - connections: state.connections - .map((connection) => - connection.fromUUID === fromUUID - ? { - ...connection, - toConnections: connection.toConnections.filter( - (to) => to.toUUID !== toUUID - ), - } - : connection - ) - .filter((connection) => connection.toConnections.length > 0), - })), + removeConnection: (fromUUID, toUUID) => + set((state) => ({ + connections: state.connections + .map((connection) => + connection.fromUUID === fromUUID + ? { + ...connection, + toConnections: connection.toConnections.filter( + (to) => to.toUUID !== toUUID + ), + } + : connection + ) + .filter((connection) => connection.toConnections.length > 0), + })), })); export const useIsConnecting = create((set: any) => ({ - isConnecting: false, - setIsConnecting: (x: any) => set({ isConnecting: x }), + isConnecting: false, + setIsConnecting: (x: any) => set({ isConnecting: x }), })); export const useStartSimulation = create((set: any) => ({ - startSimulation: false, - setStartSimulation: (x: any) => set({ startSimulation: x }), -})); \ No newline at end of file + startSimulation: false, + setStartSimulation: (x: any) => set({ startSimulation: x }), +})); +export const usezoneTarget = create((set: any) => ({ + zoneTarget: [], + setZoneTarget: (x: any) => set({ zoneTarget: x }), +})); +export const usezonePosition = create((set: any) => ({ + zonePosition: [], + setZonePosition: (x: any) => set({ zonePosition: x }), +})); + + +interface EditPositionState { + Edit: boolean; + setEdit: (value: boolean) => void; + } + + export const useEditPosition = create((set) => ({ + Edit: false, + setEdit: (value) => set({ Edit: value }), // Properly updating the state + })); + + interface DroppedObject { + header: string; + value: string; + per: string; + className: string; + } + + interface DroppedObjectsState { + objects: DroppedObject[]; + addObject: (obj: DroppedObject) => void; + } + + export const useDroppedObjectsStore = create((set) => ({ + objects: [], + addObject: (obj) => set((state) => ({ objects: [...state.objects, obj] })), + })); \ No newline at end of file