Dwinzo_dev/app/src/store/store.ts

369 lines
11 KiB
TypeScript
Raw Normal View History

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