Files
Dwinzo_dev/app/src/store/store.ts

457 lines
13 KiB
TypeScript
Raw Normal View History

2025-03-25 17:34:20 +05:30
import * as THREE from "three";
2025-03-27 12:28:17 +05:30
import * as Types from "../types/world/worldTypes";
2025-03-25 17:34:20 +05:30
import { create } from "zustand";
import { io } from "socket.io-client";
export const useSocketStore = create<any>((set: any, get: any) => ({
2025-03-27 12:28:17 +05:30
socket: null,
initializeSocket: (email: any) => {
const existingSocket = get().socket;
if (existingSocket) {
return;
2025-03-25 17:34:20 +05:30
}
2025-03-27 12:28:17 +05:30
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 };
});
},
2025-03-25 17:34:20 +05:30
}));
export const useOrganization = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
organization: "",
setOrganization: (x: any) => set(() => ({ organization: x })),
2025-03-25 17:34:20 +05:30
}));
export const useToggleView = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
toggleView: false,
setToggleView: (x: any) => set(() => ({ toggleView: x })),
2025-03-25 17:34:20 +05:30
}));
export const useUpdateScene = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
updateScene: false,
setUpdateScene: (x: any) => set(() => ({ updateScene: x })),
2025-03-25 17:34:20 +05:30
}));
export const useWalls = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
walls: [],
setWalls: (x: any) => set(() => ({ walls: x })),
2025-03-25 17:34:20 +05:30
}));
export const useZones = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
zones: [],
setZones: (x: any) => set(() => ({ zones: x })),
2025-03-25 17:34:20 +05:30
}));
interface ZonePointsState {
2025-03-27 12:28:17 +05:30
zonePoints: THREE.Vector3[];
setZonePoints: (points: THREE.Vector3[]) => void;
2025-03-25 17:34:20 +05:30
}
export const useZonePoints = create<ZonePointsState>((set) => ({
2025-03-27 12:28:17 +05:30
zonePoints: [],
setZonePoints: (points) => set({ zonePoints: points }),
2025-03-25 17:34:20 +05:30
}));
export const useSelectedItem = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
selectedItem: { name: "", id: "" },
setSelectedItem: (x: any) => set(() => ({ selectedItem: x })),
2025-03-25 17:34:20 +05:30
}));
export const useSelectedAssets = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
selectedAssets: [],
setSelectedAssets: (x: any) => set(() => ({ selectedAssets: x })),
2025-03-25 17:34:20 +05:30
}));
export const useLayers = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
Layers: 1,
setLayers: (x: any) => set(() => ({ Layers: x })),
2025-03-25 17:34:20 +05:30
}));
export const useCamPosition = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
camPosition: { x: undefined, y: undefined, z: undefined },
setCamPosition: (newCamPosition: any) => set({ camPosition: newCamPosition }),
2025-03-25 17:34:20 +05:30
}));
export const useMenuVisible = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
menuVisible: false,
setMenuVisible: (x: any) => set(() => ({ menuVisible: x })),
2025-03-25 17:34:20 +05:30
}));
export const useDeleteModels = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
deleteModels: false,
setDeleteModels: (x: any) => set(() => ({ deleteModels: x })),
2025-03-25 17:34:20 +05:30
}));
export const useToolMode = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
toolMode: null,
setToolMode: (x: any) => set(() => ({ toolMode: x })),
2025-03-25 17:34:20 +05:30
}));
export const useNewLines = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
newLines: [],
setNewLines: (x: any) => set(() => ({ newLines: x })),
2025-03-25 17:34:20 +05:30
}));
export const useDeletedLines = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
deletedLines: [],
setDeletedLines: (x: any) => set(() => ({ deletedLines: x })),
2025-03-25 17:34:20 +05:30
}));
export const useMovePoint = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
movePoint: false,
setMovePoint: (x: any) => set(() => ({ movePoint: x })),
2025-03-25 17:34:20 +05:30
}));
export const useTransformMode = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
transformMode: null,
setTransformMode: (x: any) => set(() => ({ transformMode: x })),
2025-03-25 17:34:20 +05:30
}));
export const useDeletePointOrLine = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
deletePointOrLine: false,
setDeletePointOrLine: (x: any) => set(() => ({ deletePointOrLine: x })),
2025-03-25 17:34:20 +05:30
}));
export const useFloorItems = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
floorItems: null,
setFloorItems: (callback: any) =>
set((state: any) => ({
floorItems:
typeof callback === "function" ? callback(state.floorItems) : callback,
})),
2025-03-25 17:34:20 +05:30
}));
export const useWallItems = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
wallItems: [],
setWallItems: (callback: any) =>
set((state: any) => ({
wallItems:
typeof callback === "function" ? callback(state.wallItems) : callback,
})),
2025-03-25 17:34:20 +05:30
}));
export const useSelectedWallItem = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
selectedWallItem: null,
setSelectedWallItem: (x: any) => set(() => ({ selectedWallItem: x })),
2025-03-25 17:34:20 +05:30
}));
export const useselectedFloorItem = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
selectedFloorItem: null,
setselectedFloorItem: (x: any) => set(() => ({ selectedFloorItem: x })),
2025-03-25 17:34:20 +05:30
}));
export const useDeletableFloorItem = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
deletableFloorItem: null,
setDeletableFloorItem: (x: any) => set(() => ({ deletableFloorItem: x })),
2025-03-25 17:34:20 +05:30
}));
export const useSetScale = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
scale: null,
setScale: (x: any) => set(() => ({ scale: x })),
2025-03-25 17:34:20 +05:30
}));
export const useRoofVisibility = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
roofVisibility: false,
setRoofVisibility: (x: any) => set(() => ({ roofVisibility: x })),
2025-03-25 17:34:20 +05:30
}));
export const useWallVisibility = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
wallVisibility: false,
setWallVisibility: (x: any) => set(() => ({ wallVisibility: x })),
2025-03-25 17:34:20 +05:30
}));
export const useShadows = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
shadows: false,
setShadows: (x: any) => set(() => ({ shadows: x })),
2025-03-25 17:34:20 +05:30
}));
export const useSunPosition = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
sunPosition: { x: undefined, y: undefined, z: undefined },
setSunPosition: (newSuntPosition: any) =>
set({ sunPosition: newSuntPosition }),
2025-03-25 17:34:20 +05:30
}));
export const useRemoveLayer = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
removeLayer: false,
setRemoveLayer: (x: any) => set(() => ({ removeLayer: x })),
2025-03-25 17:34:20 +05:30
}));
export const useRemovedLayer = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
removedLayer: null,
setRemovedLayer: (x: any) => set(() => ({ removedLayer: x })),
2025-03-25 17:34:20 +05:30
}));
export const useActiveLayer = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
activeLayer: 1,
setActiveLayer: (x: any) => set({ activeLayer: x }),
2025-03-25 17:34:20 +05:30
}));
export const useResetCamera = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
resetCamera: false,
setResetCamera: (x: any) => set({ resetCamera: x }),
2025-03-25 17:34:20 +05:30
}));
export const useAddAction = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
addAction: null,
setAddAction: (x: any) => set({ addAction: x }),
2025-03-25 17:34:20 +05:30
}));
export const useActiveTool = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
activeTool: "Cursor",
setActiveTool: (x: any) => set({ activeTool: x }),
2025-03-25 17:34:20 +05:30
}));
export const use2DUndoRedo = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
is2DUndoRedo: null,
set2DUndoRedo: (x: any) => set({ is2DUndoRedo: x }),
}));
2025-03-25 17:34:20 +05:30
export const useElevation = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
elevation: 45,
setElevation: (x: any) => set({ elevation: x }),
2025-03-25 17:34:20 +05:30
}));
export const useAzimuth = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
azimuth: -160,
setAzimuth: (x: any) => set({ azimuth: x }),
2025-03-25 17:34:20 +05:30
}));
export const useRenderDistance = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
renderDistance: 50,
setRenderDistance: (x: any) => set({ renderDistance: x }),
2025-03-25 17:34:20 +05:30
}));
export const useCamMode = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
camMode: "ThirdPerson",
setCamMode: (x: any) => set({ camMode: x }),
2025-03-25 17:34:20 +05:30
}));
export const useUserName = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
userName: "",
setUserName: (x: any) => set({ userName: x }),
2025-03-25 17:34:20 +05:30
}));
export const useObjectPosition = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
objectPosition: { x: undefined, y: undefined, z: undefined },
setObjectPosition: (newObjectPosition: any) =>
set({ objectPosition: newObjectPosition }),
2025-03-25 17:34:20 +05:30
}));
export const useObjectScale = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
objectScale: { x: undefined, y: undefined, z: undefined },
setObjectScale: (newObjectScale: any) => set({ objectScale: newObjectScale }),
2025-03-25 17:34:20 +05:30
}));
export const useObjectRotation = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
objectRotation: { x: undefined, y: undefined, z: undefined },
setObjectRotation: (newObjectRotation: any) =>
set({ objectRotation: newObjectRotation }),
2025-03-25 17:34:20 +05:30
}));
export const useDrieTemp = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
drieTemp: undefined,
setDrieTemp: (x: any) => set({ drieTemp: x }),
2025-03-25 17:34:20 +05:30
}));
export const useActiveUsers = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
activeUsers: [],
setActiveUsers: (x: any) => set({ activeUsers: x }),
2025-03-25 17:34:20 +05:30
}));
export const useDrieUIValue = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
drieUIValue: { touch: null, temperature: null, humidity: null },
2025-03-25 17:34:20 +05:30
2025-03-27 12:28:17 +05:30
setDrieUIValue: (x: any) =>
set((state: any) => ({ drieUIValue: { ...state.drieUIValue, ...x } })),
2025-03-25 17:34:20 +05:30
2025-03-27 12:28:17 +05:30
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 },
})),
2025-03-25 17:34:20 +05:30
}));
export const useDrawMaterialPath = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
drawMaterialPath: false,
setDrawMaterialPath: (x: any) => set({ drawMaterialPath: x }),
2025-03-25 17:34:20 +05:30
}));
export const useSelectedActionSphere = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
selectedActionSphere: undefined,
setSelectedActionSphere: (x: any) => set({ selectedActionSphere: x }),
2025-03-25 17:34:20 +05:30
}));
export const useSelectedPath = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
selectedPath: undefined,
setSelectedPath: (x: any) => set({ selectedPath: x }),
2025-03-25 17:34:20 +05:30
}));
interface Path {
2025-03-27 12:28:17 +05:30
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;
2025-03-25 17:34:20 +05:30
}
interface SimulationPathsStore {
2025-03-27 12:28:17 +05:30
simulationPaths: Path[];
setSimulationPaths: (paths: Path[]) => void;
2025-03-25 17:34:20 +05:30
}
export const useSimulationPaths = create<SimulationPathsStore>((set) => ({
2025-03-27 12:28:17 +05:30
simulationPaths: [],
setSimulationPaths: (paths) => set({ simulationPaths: paths }),
2025-03-25 17:34:20 +05:30
}));
// interface Point {
// uuid: string;
// position: [number, number, number];
// rotation: [number, number, number];
// event: {
// uuid: string;
// type: string;
// material: string;
// delay: number | string;
// spawnInterval: number | string;
// isUsed: boolean;
// };
// trigger: {
// uuid: string;
// type: string;
// isUsed: boolean;
// };
// }
// interface Process {
// processId: string;
// processName: string;
// points: Point[];
// pathPosition: [number, number, number];
// pathRotation: [number, number, number];
// speed: number;
// isUsed: boolean;
// }
// interface Path {
// modeluuid: string;
// processes: Process[];
// }
// interface SimulationPathsStore {
// simulationPaths: Path[];
// setSimulationPaths: (paths: Path[]) => void;
// }
// export const useSimulationPaths = create<SimulationPathsStore>((set) => ({
// simulationPaths: [],
// setSimulationPaths: (paths) => set({ simulationPaths: paths }),
// }));
export const useConnections = create<Types.ConnectionStore>((set) => ({
2025-03-27 12:28:17 +05:30
connections: [],
setConnections: (connections) => set({ connections }),
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),
})),
2025-03-25 17:34:20 +05:30
}));
export const useIsConnecting = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
isConnecting: false,
setIsConnecting: (x: any) => set({ isConnecting: x }),
2025-03-25 17:34:20 +05:30
}));
export const useStartSimulation = create<any>((set: any) => ({
2025-03-27 12:28:17 +05:30
startSimulation: false,
setStartSimulation: (x: any) => set({ startSimulation: x }),
}));
export const usezoneTarget = create<any>((set: any) => ({
zoneTarget: [],
setZoneTarget: (x: any) => set({ zoneTarget: x }),
}));
export const usezonePosition = create<any>((set: any) => ({
zonePosition: [],
setZonePosition: (x: any) => set({ zonePosition: x }),
}));
interface EditPositionState {
Edit: boolean;
setEdit: (value: boolean) => void;
}
export const useEditPosition = create<EditPositionState>((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<DroppedObjectsState>((set) => ({
objects: [],
addObject: (obj) => set((state) => ({ objects: [...state.objects, obj] })),
}));