Refactor store creation for Conveyor, Machine, Storage Unit, and Vehicle

- Changed the store creation functions to `createConveyorStore`, `createMachineStore`, `createStorageUnitStore`, and `createVehicleStore` for better clarity and consistency.
- Updated the internal state management methods to maintain functionality while improving readability.
- Ensured that all stores now return their respective types for better type safety.
This commit is contained in:
Jerald-Golden-B 2025-05-28 16:24:08 +05:30
parent d198f520ea
commit 5e58606f8f
41 changed files with 884 additions and 856 deletions

View File

@ -6,18 +6,19 @@ import StorageAction from "../actions/StorageAction";
import ActionsList from "../components/ActionsList"; import ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductStore } from "../../../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import { useStorageUnitStore } from "../../../../../../store/simulation/useStorageUnitStore";
import { useSelectedAction, useSelectedEventData, useSelectedProduct } from "../../../../../../store/simulation/useSimulationStore"; import { useSelectedAction, useSelectedEventData, useSelectedProduct } from "../../../../../../store/simulation/useSimulationStore";
import * as THREE from 'three'; import * as THREE from 'three';
import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function StorageMechanics() { function StorageMechanics() {
const { storageUnitStore } = useSceneContext();
const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default"); const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default");
const [selectedPointData, setSelectedPointData] = useState<StoragePointSchema | undefined>(); const [selectedPointData, setSelectedPointData] = useState<StoragePointSchema | undefined>();
const { selectedEventData } = useSelectedEventData(); const { selectedEventData } = useSelectedEventData();
const { getPointByUuid, updateAction } = useProductStore(); const { getPointByUuid, updateAction } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { setSelectedAction, clearSelectedAction } = useSelectedAction(); const { setSelectedAction, clearSelectedAction } = useSelectedAction();
const { setCurrentMaterials, clearCurrentMaterials, updateCurrentLoad, getStorageUnitById } = useStorageUnitStore(); const { setCurrentMaterials, clearCurrentMaterials, updateCurrentLoad, getStorageUnitById } = storageUnitStore();
const email = localStorage.getItem('email') const email = localStorage.getItem('email')
const organization = (email!.split("@")[1]).split(".")[0]; const organization = (email!.split("@")[1]).split(".")[0];

View File

@ -13,21 +13,17 @@ import { useProductStore } from "../../../../../../store/simulation/useProductSt
import TravelAction from "../actions/TravelAction"; import TravelAction from "../actions/TravelAction";
import ActionsList from "../components/ActionsList"; import ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useVehicleStore } from "../../../../../../store/simulation/useVehicleStore"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function VehicleMechanics() { function VehicleMechanics() {
const [activeOption, setActiveOption] = useState<"default" | "travel">( const { vehicleStore } = useSceneContext();
"default" const [activeOption, setActiveOption] = useState<"default" | "travel">("default");
); const [selectedPointData, setSelectedPointData] = useState<VehiclePointSchema | undefined>();
const [selectedPointData, setSelectedPointData] = useState<
VehiclePointSchema | undefined
>();
const { selectedEventData } = useSelectedEventData(); const { selectedEventData } = useSelectedEventData();
const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = useProductStore();
useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { setSelectedAction, clearSelectedAction } = useSelectedAction(); const { setSelectedAction, clearSelectedAction } = useSelectedAction();
const { getVehicleById } = useVehicleStore(); const { getVehicleById } = vehicleStore();
const email = localStorage.getItem("email"); const email = localStorage.getItem("email");
const organization = email!.split("@")[1].split(".")[0]; const organization = email!.split("@")[1].split(".")[0];
@ -255,7 +251,7 @@ function VehicleMechanics() {
defaultValue={"0.5"} defaultValue={"0.5"}
max={10} max={10}
activeOption="m/s" activeOption="m/s"
onClick={() => {}} onClick={() => { }}
onChange={handleSpeedChange} onChange={handleSpeedChange}
/> />
</div> </div>
@ -294,14 +290,14 @@ function VehicleMechanics() {
onChange: handleUnloadDurationChange, onChange: handleUnloadDurationChange,
}} }}
clearPoints={handleClearPoints} clearPoints={handleClearPoints}
// pickPoint={{ // pickPoint={{
// value: currentPickPoint, // value: currentPickPoint,
// onChange: handlePickPointChange, // onChange: handlePickPointChange,
// }} // }}
// unloadPoint={{ // unloadPoint={{
// value: currentUnloadPoint, // value: currentUnloadPoint,
// onChange: handleUnloadPointChange, // onChange: handleUnloadPointChange,
// }} // }}
/> />
)} )}
</div> </div>

View File

@ -6,7 +6,7 @@ function AisleInstances() {
const { aisles } = useAisleStore(); const { aisles } = useAisleStore();
useEffect(() => { useEffect(() => {
console.log('aisles: ', aisles); // console.log('aisles: ', aisles);
}, [aisles]); }, [aisles]);
return ( return (

View File

@ -1,4 +1,3 @@
import React from 'react'
import AisleCreator from './aisleCreator/aisleCreator' import AisleCreator from './aisleCreator/aisleCreator'
import AisleInstances from './Instances/aisleInstances' import AisleInstances from './Instances/aisleInstances'

View File

@ -1,16 +1,40 @@
import { createContext, useContext, useMemo } from 'react'; import { createContext, useContext, useMemo } from 'react';
import { createMaterialStore, MaterialStoreType } from '../../store/simulation/useMaterialStore'; import { createMaterialStore, MaterialStoreType } from '../../store/simulation/useMaterialStore';
import { createArmBotStore, ArmBotStoreType } from '../../store/simulation/useArmBotStore';
import { createMachineStore, MachineStoreType } from '../../store/simulation/useMachineStore';
import { createConveyorStore, ConveyorStoreType } from '../../store/simulation/useConveyorStore';
import { createVehicleStore, VehicleStoreType } from '../../store/simulation/useVehicleStore';
import { createStorageUnitStore, StorageUnitStoreType } from '../../store/simulation/useStorageUnitStore';
type SceneContextValue = { type SceneContextValue = {
materialStore: MaterialStoreType; materialStore: MaterialStoreType;
// Add other stores here if needed armBotStore: ArmBotStoreType;
machineStore: MachineStoreType;
conveyorStore: ConveyorStoreType;
vehicleStore: VehicleStoreType;
storageUnitStore: StorageUnitStoreType;
}; };
const SceneContext = createContext<SceneContextValue | null>(null); const SceneContext = createContext<SceneContextValue | null>(null);
export function SceneProvider({ children }: { readonly children: React.ReactNode }) { export function SceneProvider({ children }: { readonly children: React.ReactNode }) {
const materialStore = useMemo(() => createMaterialStore(), []); const materialStore = useMemo(() => createMaterialStore(), []);
const contextValue = useMemo(() => ({ materialStore }), [materialStore]); const armBotStore = useMemo(() => createArmBotStore(), []);
const machineStore = useMemo(() => createMachineStore(), []);
const conveyorStore = useMemo(() => createConveyorStore(), []);
const vehicleStore = useMemo(() => createVehicleStore(), []);
const storageUnitStore = useMemo(() => createStorageUnitStore(), []);
const contextValue = useMemo(() => (
{
materialStore,
armBotStore,
machineStore,
conveyorStore,
vehicleStore,
storageUnitStore
}
), [materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore]);
return ( return (
<SceneContext.Provider value={contextValue}> <SceneContext.Provider value={contextValue}>

View File

@ -4,7 +4,6 @@ import { useFrame } from "@react-three/fiber";
import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
import { usePlayButtonStore, useAnimationPlaySpeed, usePauseButtonStore, useResetButtonStore } from "../../../../../store/usePlayButtonStore"; import { usePlayButtonStore, useAnimationPlaySpeed, usePauseButtonStore, useResetButtonStore } from "../../../../../store/usePlayButtonStore";
import { useConveyorStore } from "../../../../../store/simulation/useConveyorStore";
import { useSceneContext } from "../../../../scene/sceneContext"; import { useSceneContext } from "../../../../scene/sceneContext";
interface SpawnInstance { interface SpawnInstance {
@ -23,9 +22,9 @@ interface SpawnInstance {
} }
export function useSpawnHandler() { export function useSpawnHandler() {
const { materialStore } = useSceneContext(); const { materialStore, conveyorStore } = useSceneContext();
const { addMaterial } = materialStore(); const { addMaterial } = materialStore();
const { getConveyorById } = useConveyorStore(); const { getConveyorById } = conveyorStore();
const { getModelUuidByActionUuid, getPointUuidByActionUuid } = useProductStore(); const { getModelUuidByActionUuid, getPointUuidByActionUuid } = useProductStore();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { isPaused } = usePauseButtonStore(); const { isPaused } = usePauseButtonStore();

View File

@ -1,13 +1,12 @@
import { useCallback } from "react"; import { useCallback } from "react";
import { useMachineStore } from "../../../../../store/simulation/useMachineStore";
import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
import { useSceneContext } from "../../../../scene/sceneContext"; import { useSceneContext } from "../../../../scene/sceneContext";
export function useProcessHandler() { export function useProcessHandler() {
const { materialStore } = useSceneContext(); const { materialStore, machineStore } = useSceneContext();
const { getMaterialById, setMaterial } = materialStore(); const { getMaterialById, setMaterial } = materialStore();
const { addCurrentAction } = useMachineStore(); const { addCurrentAction } = machineStore();
const { getModelUuidByActionUuid } = useProductStore(); const { getModelUuidByActionUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();

View File

@ -1,13 +1,12 @@
import { useCallback } from "react"; import { useCallback } from "react";
import { useArmBotStore } from "../../../../../store/simulation/useArmBotStore";
import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
import { useSceneContext } from "../../../../scene/sceneContext"; import { useSceneContext } from "../../../../scene/sceneContext";
export function usePickAndPlaceHandler() { export function usePickAndPlaceHandler() {
const { materialStore } = useSceneContext(); const { materialStore, armBotStore } = useSceneContext();
const { getMaterialById } = materialStore(); const { getMaterialById } = materialStore();
const { addCurrentAction } = useArmBotStore(); const { addCurrentAction } = armBotStore();
const { getModelUuidByActionUuid } = useProductStore(); const { getModelUuidByActionUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();

View File

@ -2,20 +2,17 @@ import { useCallback, useState, useEffect, useRef } from "react";
import { useFrame } from "@react-three/fiber"; import { useFrame } from "@react-three/fiber";
import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
import { useStorageUnitStore } from "../../../../../store/simulation/useStorageUnitStore";
import { useArmBotStore } from "../../../../../store/simulation/useArmBotStore";
import { useVehicleStore } from "../../../../../store/simulation/useVehicleStore";
import { usePlayButtonStore, usePauseButtonStore, useResetButtonStore, useAnimationPlaySpeed } from "../../../../../store/usePlayButtonStore"; import { usePlayButtonStore, usePauseButtonStore, useResetButtonStore, useAnimationPlaySpeed } from "../../../../../store/usePlayButtonStore";
import { useSceneContext } from "../../../../scene/sceneContext"; import { useSceneContext } from "../../../../scene/sceneContext";
export function useRetrieveHandler() { export function useRetrieveHandler() {
const { materialStore } = useSceneContext(); const { materialStore, armBotStore, vehicleStore, storageUnitStore } = useSceneContext();
const { addMaterial } = materialStore(); const { addMaterial } = materialStore();
const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = useProductStore(); const { getModelUuidByActionUuid, getPointUuidByActionUuid, getEventByModelUuid, getActionByUuid } = useProductStore();
const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = useStorageUnitStore(); const { getStorageUnitById, getLastMaterial, updateCurrentLoad, removeLastMaterial } = storageUnitStore();
const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = useVehicleStore(); const { getVehicleById, incrementVehicleLoad, addCurrentMaterial } = vehicleStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { getArmBotById, addCurrentAction } = useArmBotStore(); const { getArmBotById, addCurrentAction } = armBotStore();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { speed } = useAnimationPlaySpeed(); const { speed } = useAnimationPlaySpeed();
const { isPaused } = usePauseButtonStore(); const { isPaused } = usePauseButtonStore();

View File

@ -1,13 +1,12 @@
import { useCallback } from "react"; import { useCallback } from "react";
import { useStorageUnitStore } from "../../../../../store/simulation/useStorageUnitStore";
import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
import { useSceneContext } from "../../../../scene/sceneContext"; import { useSceneContext } from "../../../../scene/sceneContext";
export function useStoreHandler() { export function useStoreHandler() {
const { materialStore } = useSceneContext(); const { materialStore, storageUnitStore } = useSceneContext();
const { getMaterialById, removeMaterial, setEndTime } = materialStore(); const { getMaterialById, removeMaterial, setEndTime } = materialStore();
const { addCurrentMaterial, updateCurrentLoad } = useStorageUnitStore(); const { addCurrentMaterial, updateCurrentLoad } = storageUnitStore();
const { getModelUuidByActionUuid } = useProductStore(); const { getModelUuidByActionUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();

View File

@ -1,15 +1,14 @@
import { useCallback } from "react"; import { useCallback } from "react";
import { useProductStore } from "../../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../../store/simulation/useProductStore";
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
import { useVehicleStore } from "../../../../../store/simulation/useVehicleStore";
import { useSceneContext } from "../../../../scene/sceneContext"; import { useSceneContext } from "../../../../scene/sceneContext";
export function useTravelHandler() { export function useTravelHandler() {
const { materialStore } = useSceneContext(); const { materialStore, vehicleStore } = useSceneContext();
const { getMaterialById } = materialStore(); const { getMaterialById } = materialStore();
const { getModelUuidByActionUuid } = useProductStore(); const { getModelUuidByActionUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { incrementVehicleLoad, addCurrentMaterial } = useVehicleStore(); const { incrementVehicleLoad, addCurrentMaterial } = vehicleStore();
const travelLogStatus = (materialUuid: string, status: string) => { const travelLogStatus = (materialUuid: string, status: string) => {
echo.info(`${materialUuid}, ${status}`); echo.info(`${materialUuid}, ${status}`);

View File

@ -2,24 +2,19 @@ import { useEffect } from 'react';
import { useSelectedProduct } from '../../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
import { useProductStore } from '../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../store/simulation/useProductStore';
import { determineExecutionMachineSequences } from '../../simulator/functions/determineExecutionMachineSequences'; import { determineExecutionMachineSequences } from '../../simulator/functions/determineExecutionMachineSequences';
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
import { useMachineCount, useMachineUptime, useMaterialCycle, useProcessBar, useThroughPutData } from '../../../../store/builder/store'; import { useMachineCount, useMachineUptime, useMaterialCycle, useProcessBar, useThroughPutData } from '../../../../store/builder/store';
import { useVehicleStore } from '../../../../store/simulation/useVehicleStore';
import { useMachineStore } from '../../../../store/simulation/useMachineStore';
import { useConveyorStore } from '../../../../store/simulation/useConveyorStore';
import { useStorageUnitStore } from '../../../../store/simulation/useStorageUnitStore';
import { usePlayButtonStore } from '../../../../store/usePlayButtonStore'; import { usePlayButtonStore } from '../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../scene/sceneContext'; import { useSceneContext } from '../../../scene/sceneContext';
export default function ThroughPutData() { export default function ThroughPutData() {
const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { products, getProductById } = useProductStore(); const { products, getProductById } = useProductStore();
const { armBots } = useArmBotStore(); const { armBots } = armBotStore();
const { vehicles } = useVehicleStore(); const { vehicles } = vehicleStore();
const { machines } = useMachineStore(); const { machines } = machineStore();
const { conveyors } = useConveyorStore(); const { conveyors } = conveyorStore();
const { storageUnits } = useStorageUnitStore(); const { storageUnits } = storageUnitStore();
const { materialStore } = useSceneContext();
const { materialHistory } = materialStore(); const { materialHistory } = materialStore();
const { machineCount, setMachineCount } = useMachineCount(); const { machineCount, setMachineCount } = useMachineCount();
const { machineActiveTime, setMachineActiveTime } = useMachineUptime(); const { machineActiveTime, setMachineActiveTime } = useMachineUptime();

View File

@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useFrame } from '@react-three/fiber'; import { useFrame } from '@react-three/fiber';
import { useConveyorStore } from '../../../../store/simulation/useConveyorStore';
import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../scene/sceneContext';
type ConveyorCallback = { type ConveyorCallback = {
conveyorId: string; conveyorId: string;
@ -9,7 +9,8 @@ type ConveyorCallback = {
}; };
export function useConveyorEventManager() { export function useConveyorEventManager() {
const { getConveyorById } = useConveyorStore(); const { conveyorStore } = useSceneContext();
const { getConveyorById } = conveyorStore();
const callbacksRef = useRef<ConveyorCallback[]>([]); const callbacksRef = useRef<ConveyorCallback[]>([]);
const isMonitoringRef = useRef(false); const isMonitoringRef = useRef(false);
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();

View File

@ -1,5 +1,4 @@
import { useEffect } from 'react' import { useEffect } from 'react'
import { useConveyorStore } from '../../../../../store/simulation/useConveyorStore';
import { useResetButtonStore } from '../../../../../store/usePlayButtonStore'; import { useResetButtonStore } from '../../../../../store/usePlayButtonStore';
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
import { useProductStore } from '../../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../../store/simulation/useProductStore';
@ -9,10 +8,10 @@ import { useSceneContext } from '../../../../scene/sceneContext';
function ConveyorInstance({ conveyor }: { conveyor: ConveyorStatus }) { function ConveyorInstance({ conveyor }: { conveyor: ConveyorStatus }) {
const { getProductById } = useProductStore(); const { getProductById } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { materialStore } = useSceneContext(); const { materialStore, conveyorStore } = useSceneContext();
const { getMaterialsByCurrentModelUuid, materials } = materialStore(); const { getMaterialsByCurrentModelUuid, materials } = materialStore();
const { isReset } = useResetButtonStore(); const { isReset } = useResetButtonStore();
const { setConveyorPaused } = useConveyorStore(); const { setConveyorPaused } = conveyorStore();
useEffect(() => { useEffect(() => {
const product = getProductById(selectedProduct.productId); const product = getProductById(selectedProduct.productId);

View File

@ -1,10 +1,11 @@
import React from 'react' import React from 'react'
import ConveyorInstance from './conveyorInstance/conveyorInstance' import ConveyorInstance from './conveyorInstance/conveyorInstance'
import { useConveyorStore } from '../../../../store/simulation/useConveyorStore' import { useSceneContext } from '../../../scene/sceneContext';
function ConveyorInstances() { function ConveyorInstances() {
const { conveyors } = useConveyorStore(); const { conveyorStore } = useSceneContext();
const { conveyors } = conveyorStore();
return ( return (
<> <>

View File

@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useFrame } from '@react-three/fiber'; import { useFrame } from '@react-three/fiber';
import { useMachineStore } from '../../../../store/simulation/useMachineStore';
import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../scene/sceneContext';
type MachineCallback = { type MachineCallback = {
machineId: string; machineId: string;
@ -9,7 +9,8 @@ type MachineCallback = {
}; };
export function useMachineEventManager() { export function useMachineEventManager() {
const { getMachineById } = useMachineStore(); const { machineStore } = useSceneContext();
const { getMachineById } = machineStore();
const callbacksRef = useRef<MachineCallback[]>([]); const callbacksRef = useRef<MachineCallback[]>([]);
const isMonitoringRef = useRef(false); const isMonitoringRef = useRef(false);
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();

View File

@ -1,7 +1,6 @@
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useMachineStore } from '../../../../../store/simulation/useMachineStore';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../../scene/sceneContext';
interface MachineAnimatorProps { interface MachineAnimatorProps {
currentPhase: string; currentPhase: string;
@ -19,7 +18,8 @@ const MachineAnimator = ({ currentPhase, handleCallBack, processingTime, machine
const animationFrameId = useRef<number | null>(null); const animationFrameId = useRef<number | null>(null);
const pauseTimeRef = useRef<number | null>(null); const pauseTimeRef = useRef<number | null>(null);
const { isPaused } = usePauseButtonStore(); const { isPaused } = usePauseButtonStore();
const { removeCurrentAction } = useMachineStore(); const { machineStore } = useSceneContext();
const { removeCurrentAction } = machineStore();
const { isReset } = useResetButtonStore(); const { isReset } = useResetButtonStore();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { speed } = useAnimationPlaySpeed(); const { speed } = useAnimationPlaySpeed();

View File

@ -1,12 +1,12 @@
import { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import { useMachineStore } from '../../../../../store/simulation/useMachineStore';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
import MachineAnimator from '../animator/machineAnimator'; import MachineAnimator from '../animator/machineAnimator';
import { useProductStore } from '../../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler'; import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
import { useSceneContext } from '../../../../scene/sceneContext';
function MachineInstance({ machineDetail }: { machineDetail: MachineStatus }) { function MachineInstance({ machineDetail }: { readonly machineDetail: MachineStatus }) {
const [currentPhase, setCurrentPhase] = useState<string>('idle'); const [currentPhase, setCurrentPhase] = useState<string>('idle');
let isIncrememtable = useRef<boolean>(true); let isIncrememtable = useRef<boolean>(true);
const idleTimeRef = useRef<number>(0); const idleTimeRef = useRef<number>(0);
@ -16,7 +16,8 @@ function MachineInstance({ machineDetail }: { machineDetail: MachineStatus }) {
const isSpeedRef = useRef<number>(0); const isSpeedRef = useRef<number>(0);
const isPausedRef = useRef<boolean>(false); const isPausedRef = useRef<boolean>(false);
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { machines, setMachineState, setMachineActive, incrementIdleTime, incrementActiveTime, resetTime } = useMachineStore(); const { machineStore } = useSceneContext();
const { machines, setMachineState, setMachineActive, incrementIdleTime, incrementActiveTime, resetTime } = machineStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { getActionByUuid } = useProductStore(); const { getActionByUuid } = useProductStore();
const { triggerPointActions } = useTriggerHandler(); const { triggerPointActions } = useTriggerHandler();

View File

@ -1,10 +1,11 @@
import React from "react"; import React from "react";
import MachineInstance from "./machineInstance/machineInstance"; import MachineInstance from "./machineInstance/machineInstance";
import { useMachineStore } from "../../../../store/simulation/useMachineStore";
import MachineContentUi from "../../ui3d/MachineContentUi"; import MachineContentUi from "../../ui3d/MachineContentUi";
import { useSceneContext } from "../../../scene/sceneContext";
function MachineInstances() { function MachineInstances() {
const { machines } = useMachineStore(); const { machineStore } = useSceneContext();
const { machines } = machineStore();
return ( return (
<> <>
{machines.map((machine: MachineStatus) => ( {machines.map((machine: MachineStatus) => (

View File

@ -2,7 +2,7 @@ import React, { useEffect, useState, useRef } from 'react';
import * as THREE from 'three'; import * as THREE from 'three';
import { useFrame, useThree } from '@react-three/fiber'; import { useFrame, useThree } from '@react-three/fiber';
import { usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; import { usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
import { useConveyorStore } from '../../../../../store/simulation/useConveyorStore'; import { useSceneContext } from '../../../../scene/sceneContext';
interface MaterialAnimatorProps { interface MaterialAnimatorProps {
matRef: React.RefObject<THREE.Mesh>; matRef: React.RefObject<THREE.Mesh>;
@ -20,7 +20,8 @@ function MaterialAnimator({
const { scene } = useThree(); const { scene } = useThree();
const [targetPosition, setTargetPosition] = useState<THREE.Vector3 | null>(null); const [targetPosition, setTargetPosition] = useState<THREE.Vector3 | null>(null);
const [isAnimating, setIsAnimating] = useState(false); const [isAnimating, setIsAnimating] = useState(false);
const { getConveyorById } = useConveyorStore(); const { conveyorStore } = useSceneContext();
const { getConveyorById } = conveyorStore();
const animationState = useRef({ const animationState = useRef({
startTime: 0, startTime: 0,
startPosition: new THREE.Vector3(), startPosition: new THREE.Vector3(),

View File

@ -4,21 +4,18 @@ import { useProductStore } from '../../../store/simulation/useProductStore';
import { useSelectedProduct } from '../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../store/simulation/useSimulationStore';
import { upsertProductOrEventApi } from '../../../services/simulation/products/UpsertProductOrEventApi'; import { upsertProductOrEventApi } from '../../../services/simulation/products/UpsertProductOrEventApi';
import { getAllProductsApi } from '../../../services/simulation/products/getallProductsApi'; import { getAllProductsApi } from '../../../services/simulation/products/getallProductsApi';
import { useVehicleStore } from '../../../store/simulation/useVehicleStore';
import { useArmBotStore } from '../../../store/simulation/useArmBotStore';
import { useConveyorStore } from '../../../store/simulation/useConveyorStore';
import { useMachineStore } from '../../../store/simulation/useMachineStore';
import { useStorageUnitStore } from '../../../store/simulation/useStorageUnitStore';
import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore'; import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore';
import { useSceneContext } from '../../scene/sceneContext';
function Products() { function Products() {
const { armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
const { products, getProductById, addProduct, setProducts } = useProductStore(); const { products, getProductById, addProduct, setProducts } = useProductStore();
const { selectedProduct, setSelectedProduct } = useSelectedProduct(); const { selectedProduct, setSelectedProduct } = useSelectedProduct();
const { addVehicle, clearvehicles } = useVehicleStore(); const { addVehicle, clearvehicles } = vehicleStore();
const { addArmBot, clearArmBots } = useArmBotStore(); const { addArmBot, clearArmBots } = armBotStore();
const { addMachine, clearMachines } = useMachineStore(); const { addMachine, clearMachines } = machineStore();
const { addConveyor, clearConveyors } = useConveyorStore(); const { addConveyor, clearConveyors } = conveyorStore();
const { setCurrentMaterials, clearStorageUnits, updateCurrentLoad, addStorageUnit } = useStorageUnitStore(); const { setCurrentMaterials, clearStorageUnits, updateCurrentLoad, addStorageUnit } = storageUnitStore();
const { isReset } = useResetButtonStore(); const { isReset } = useResetButtonStore();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
@ -105,7 +102,7 @@ function Products() {
addStorageUnit(selectedProduct.productId, event); addStorageUnit(selectedProduct.productId, event);
if (event.point.action.actionType === 'retrieve') { if (event.point.action.actionType === 'retrieve') {
const storageAction = event.point.action as StorageAction; const storageAction = event.point.action;
const materials = Array.from({ length: storageAction.storageCapacity }, () => ({ const materials = Array.from({ length: storageAction.storageCapacity }, () => ({
materialType: storageAction.materialType || 'Default material', materialType: storageAction.materialType || 'Default material',
materialId: THREE.MathUtils.generateUUID() materialId: THREE.MathUtils.generateUUID()

View File

@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useFrame } from '@react-three/fiber'; import { useFrame } from '@react-three/fiber';
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../scene/sceneContext';
type ArmBotCallback = { type ArmBotCallback = {
armBotId: string; armBotId: string;
@ -9,7 +9,8 @@ type ArmBotCallback = {
}; };
export function useArmBotEventManager() { export function useArmBotEventManager() {
const { getArmBotById } = useArmBotStore(); const {armBotStore} = useSceneContext();
const { getArmBotById } = armBotStore();
const callbacksRef = useRef<ArmBotCallback[]>([]); const callbacksRef = useRef<ArmBotCallback[]>([]);
const isMonitoringRef = useRef(false); const isMonitoringRef = useRef(false);
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();

View File

@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { useFrame, useThree } from '@react-three/fiber'; import { useFrame, useThree } from '@react-three/fiber';
import * as THREE from 'three'; import * as THREE from 'three';
import { Line, Text } from '@react-three/drei'; import { Line, Text } from '@react-three/drei';

View File

@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react' import { useEffect, useRef, useState } from 'react'
import * as THREE from "three"; import * as THREE from "three";
import { useThree } from "@react-three/fiber"; import { useThree } from "@react-three/fiber";
import IKInstance from '../ikInstance/ikInstance'; import IKInstance from '../ikInstance/ikInstance';
@ -6,15 +6,12 @@ import RoboticArmAnimator from '../animator/roboticArmAnimator';
import MaterialAnimator from '../animator/materialAnimator'; import MaterialAnimator from '../animator/materialAnimator';
import armModel from "../../../../../assets/gltf-glb/rigged/ik_arm_1.glb"; import armModel from "../../../../../assets/gltf-glb/rigged/ik_arm_1.glb";
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore';
import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore';
import { useProductStore } from '../../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
import { useStorageUnitStore } from '../../../../../store/simulation/useStorageUnitStore';
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler'; import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
import { useSceneContext } from '../../../../scene/sceneContext'; import { useSceneContext } from '../../../../scene/sceneContext';
function RoboticArmInstance({ armBot }: {readonly armBot: ArmBotStatus }) { function RoboticArmInstance({ armBot }: { readonly armBot: ArmBotStatus }) {
const [currentPhase, setCurrentPhase] = useState<(string)>("init"); const [currentPhase, setCurrentPhase] = useState<(string)>("init");
const [path, setPath] = useState<[number, number, number][]>([]); const [path, setPath] = useState<[number, number, number][]>([]);
@ -28,10 +25,10 @@ function RoboticArmInstance({ armBot }: {readonly armBot: ArmBotStatus }) {
const isSpeedRef = useRef<any>(null); const isSpeedRef = useRef<any>(null);
let startTime: number; let startTime: number;
const { setArmBotActive, setArmBotState, removeCurrentAction, incrementActiveTime, incrementIdleTime } = useArmBotStore(); const { materialStore, armBotStore, vehicleStore, storageUnitStore } = useSceneContext();
const { decrementVehicleLoad, removeLastMaterial } = useVehicleStore(); const { setArmBotActive, setArmBotState, removeCurrentAction, incrementActiveTime, incrementIdleTime } = armBotStore();
const { removeLastMaterial: removeLastStorageMaterial, updateCurrentLoad } = useStorageUnitStore(); const { decrementVehicleLoad, removeLastMaterial } = vehicleStore();
const { materialStore } = useSceneContext(); const { removeLastMaterial: removeLastStorageMaterial, updateCurrentLoad } = storageUnitStore();
const { getMaterialById, setIsVisible, setIsPaused } = materialStore(); const { getMaterialById, setIsVisible, setIsPaused } = materialStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { getActionByUuid, getEventByActionUuid, getEventByModelUuid } = useProductStore(); const { getActionByUuid, getEventByActionUuid, getEventByModelUuid } = useProductStore();

View File

@ -1,10 +1,11 @@
import { useSceneContext } from "../../../scene/sceneContext";
import RoboticArmInstance from "./armInstance/roboticArmInstance"; import RoboticArmInstance from "./armInstance/roboticArmInstance";
import { useArmBotStore } from "../../../../store/simulation/useArmBotStore";
// import RoboticArmContentUi from "../../ui3d/RoboticArmContentUi"; // import RoboticArmContentUi from "../../ui3d/RoboticArmContentUi";
import React from "react"; import React from "react";
function RoboticArmInstances() { function RoboticArmInstances() {
const { armBots } = useArmBotStore(); const {armBotStore} = useSceneContext();
const { armBots } = armBotStore();
return ( return (
<> <>

View File

@ -1,12 +1,13 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useArmBotStore } from "../../../store/simulation/useArmBotStore";
import { useSelectedEventSphere } from "../../../store/simulation/useSimulationStore"; import { useSelectedEventSphere } from "../../../store/simulation/useSimulationStore";
import { usePlayButtonStore } from "../../../store/usePlayButtonStore"; import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
import RoboticArmInstances from "./instances/roboticArmInstances"; import RoboticArmInstances from "./instances/roboticArmInstances";
import ArmBotUI from "../spatialUI/arm/armBotUI"; import ArmBotUI from "../spatialUI/arm/armBotUI";
import { useSceneContext } from "../../scene/sceneContext";
function RoboticArm() { function RoboticArm() {
const { getArmBotById } = useArmBotStore(); const {armBotStore} = useSceneContext();
const { getArmBotById } = armBotStore();
const { selectedEventSphere } = useSelectedEventSphere(); const { selectedEventSphere } = useSelectedEventSphere();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const [isArmBotSelected, setIsArmBotSelected] = useState(false); const [isArmBotSelected, setIsArmBotSelected] = useState(false);

View File

@ -1,5 +1,5 @@
import { useSceneContext } from "../../../scene/sceneContext";
import { extractTriggersFromPoint } from "./extractTriggersFromPoint"; import { extractTriggersFromPoint } from "./extractTriggersFromPoint";
import { useArmBotStore } from "../../../../store/simulation/useArmBotStore";
export function getRoboticArmSequencesInProduct( export function getRoboticArmSequencesInProduct(
product: { product: {
@ -80,7 +80,8 @@ export function findRoboticArmSubsequence(
// React component/hook that uses the pure functions // React component/hook that uses the pure functions
export function useCheckActiveRoboticArmsInSubsequence() { export function useCheckActiveRoboticArmsInSubsequence() {
const { getArmBotById } = useArmBotStore(); const {armBotStore} = useSceneContext();
const { getArmBotById } = armBotStore();
return function (product: { return function (product: {
productName: string; productName: string;

View File

@ -3,7 +3,6 @@ import { useSelectedAction, useSelectedEventSphere, useSelectedProduct } from '.
import { useGLTF } from '@react-three/drei'; import { useGLTF } from '@react-three/drei';
import { useThree } from '@react-three/fiber'; import { useThree } from '@react-three/fiber';
import { useProductStore } from '../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../store/simulation/useProductStore';
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
import PickDropPoints from './PickDropPoints'; import PickDropPoints from './PickDropPoints';
import useDraggableGLTF from './useDraggableGLTF'; import useDraggableGLTF from './useDraggableGLTF';
import * as THREE from 'three'; import * as THREE from 'three';
@ -11,6 +10,7 @@ import * as THREE from 'three';
import armPick from "../../../../assets/gltf-glb/ui/arm_ui_pick.glb"; import armPick from "../../../../assets/gltf-glb/ui/arm_ui_pick.glb";
import armDrop from "../../../../assets/gltf-glb/ui/arm_ui_drop.glb"; import armDrop from "../../../../assets/gltf-glb/ui/arm_ui_drop.glb";
import { upsertProductOrEventApi } from '../../../../services/simulation/products/UpsertProductOrEventApi'; import { upsertProductOrEventApi } from '../../../../services/simulation/products/UpsertProductOrEventApi';
import { useSceneContext } from '../../../scene/sceneContext';
type Positions = { type Positions = {
pick: [number, number, number]; pick: [number, number, number];
@ -24,7 +24,8 @@ const ArmBotUI = () => {
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { scene } = useThree(); const { scene } = useThree();
const { selectedAction } = useSelectedAction(); const { selectedAction } = useSelectedAction();
const { armBots } = useArmBotStore(); const { armBotStore } = useSceneContext();
const { armBots } = armBotStore();
const armUiPick = useGLTF(armPick) as any; const armUiPick = useGLTF(armPick) as any;
const armUiDrop = useGLTF(armDrop) as any; const armUiDrop = useGLTF(armDrop) as any;

View File

@ -8,13 +8,13 @@ import {
useSelectedProduct, useSelectedProduct,
useIsRotating, useIsRotating,
} from "../../../../store/simulation/useSimulationStore"; } from "../../../../store/simulation/useSimulationStore";
import { useVehicleStore } from "../../../../store/simulation/useVehicleStore";
import { useProductStore } from "../../../../store/simulation/useProductStore"; import { useProductStore } from "../../../../store/simulation/useProductStore";
import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi"; import { upsertProductOrEventApi } from "../../../../services/simulation/products/UpsertProductOrEventApi";
import { DoubleSide, Group, Plane, Vector3 } from "three"; import { DoubleSide, Group, Plane, Vector3 } from "three";
import startPoint from "../../../../assets/gltf-glb/ui/arrow_green.glb"; import startPoint from "../../../../assets/gltf-glb/ui/arrow_green.glb";
import startEnd from "../../../../assets/gltf-glb/ui/arrow_red.glb"; import startEnd from "../../../../assets/gltf-glb/ui/arrow_red.glb";
import { useSceneContext } from "../../../scene/sceneContext";
const VehicleUI = () => { const VehicleUI = () => {
const { scene: startScene } = useGLTF(startPoint) as any; const { scene: startScene } = useGLTF(startPoint) as any;
@ -24,7 +24,8 @@ const VehicleUI = () => {
const prevMousePos = useRef({ x: 0, y: 0 }); const prevMousePos = useRef({ x: 0, y: 0 });
const { selectedEventSphere } = useSelectedEventSphere(); const { selectedEventSphere } = useSelectedEventSphere();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { vehicles, getVehicleById } = useVehicleStore(); const { vehicleStore } = useSceneContext();
const { vehicles, getVehicleById } = vehicleStore();
const { updateEvent } = useProductStore(); const { updateEvent } = useProductStore();
const [startPosition, setStartPosition] = useState<[number, number, number]>([ const [startPosition, setStartPosition] = useState<[number, number, number]>([
0, 1, 0, 0, 1, 0,

View File

@ -1,17 +1,18 @@
import React from 'react' import React from 'react'
import StorageUnitInstance from './storageUnitInstance/storageUnitInstance' import StorageUnitInstance from './storageUnitInstance/storageUnitInstance'
import { useStorageUnitStore } from '../../../../store/simulation/useStorageUnitStore'
import StorageContentUi from '../../ui3d/StorageContentUi'; import StorageContentUi from '../../ui3d/StorageContentUi';
import { useSceneContext } from '../../../scene/sceneContext';
function StorageUnitInstances() { function StorageUnitInstances() {
const { storageUnits } = useStorageUnitStore(); const { storageUnitStore } = useSceneContext();
const { storageUnits } = storageUnitStore();
return ( return (
<> <>
{storageUnits.map((storageUnit: StorageUnitStatus) => ( {storageUnits.map((storageUnit: StorageUnitStatus) => (
<React.Fragment key={storageUnit.modelUuid}> <React.Fragment key={storageUnit.modelUuid}>
<StorageUnitInstance storageUnit={storageUnit} /> <StorageUnitInstance storageUnit={storageUnit} />
<StorageContentUi storageUnit={storageUnit}/> <StorageContentUi storageUnit={storageUnit} />
</React.Fragment> </React.Fragment>
))} ))}
</> </>

View File

@ -2,31 +2,26 @@ import { useCallback } from 'react';
import { useActionHandler } from '../../actions/useActionHandler'; import { useActionHandler } from '../../actions/useActionHandler';
import { useProductStore } from '../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../store/simulation/useProductStore';
import { useSelectedProduct } from '../../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../../store/simulation/useSimulationStore';
import { useArmBotStore } from '../../../../store/simulation/useArmBotStore';
import { useVehicleStore } from '../../../../store/simulation/useVehicleStore';
import { useMachineStore } from '../../../../store/simulation/useMachineStore';
import { useStorageUnitStore } from '../../../../store/simulation/useStorageUnitStore';
import { useArmBotEventManager } from '../../roboticArm/eventManager/useArmBotEventManager'; import { useArmBotEventManager } from '../../roboticArm/eventManager/useArmBotEventManager';
import { useConveyorStore } from '../../../../store/simulation/useConveyorStore';
import { useConveyorEventManager } from '../../conveyor/eventManager/useConveyorEventManager'; import { useConveyorEventManager } from '../../conveyor/eventManager/useConveyorEventManager';
import { useVehicleEventManager } from '../../vehicle/eventManager/useVehicleEventManager'; import { useVehicleEventManager } from '../../vehicle/eventManager/useVehicleEventManager';
import { useMachineEventManager } from '../../machine/eventManager/useMachineEventManager'; import { useMachineEventManager } from '../../machine/eventManager/useMachineEventManager';
import { useSceneContext } from '../../../scene/sceneContext'; import { useSceneContext } from '../../../scene/sceneContext';
export function useTriggerHandler() { export function useTriggerHandler() {
const { materialStore, armBotStore, machineStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
const { handleAction } = useActionHandler(); const { handleAction } = useActionHandler();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { getEventByTriggerUuid, getEventByModelUuid, getActionByUuid, getModelUuidByActionUuid } = useProductStore(); const { getEventByTriggerUuid, getEventByModelUuid, getActionByUuid, getModelUuidByActionUuid } = useProductStore();
const { getArmBotById } = useArmBotStore(); const { getArmBotById } = armBotStore();
const { getConveyorById } = useConveyorStore(); const { getConveyorById } = conveyorStore();
const { addArmBotToMonitor } = useArmBotEventManager(); const { addArmBotToMonitor } = useArmBotEventManager();
const { addConveyorToMonitor } = useConveyorEventManager(); const { addConveyorToMonitor } = useConveyorEventManager();
const { addVehicleToMonitor } = useVehicleEventManager(); const { addVehicleToMonitor } = useVehicleEventManager();
const { addMachineToMonitor } = useMachineEventManager(); const { addMachineToMonitor } = useMachineEventManager();
const { getVehicleById } = useVehicleStore(); const { getVehicleById } = vehicleStore();
const { getMachineById } = useMachineStore(); const { getMachineById } = machineStore();
const { getStorageUnitById } = useStorageUnitStore(); const { getStorageUnitById } = storageUnitStore();
const { materialStore } = useSceneContext();
const { getMaterialById, setCurrentLocation, setNextLocation, setPreviousLocation, setIsPaused, setIsVisible, setEndTime } = materialStore(); const { getMaterialById, setCurrentLocation, setNextLocation, setPreviousLocation, setIsPaused, setIsVisible, setEndTime } = materialStore();
const handleTrigger = (trigger: TriggerSchema, action: Action, materialId?: string) => { const handleTrigger = (trigger: TriggerSchema, action: Action, materialId?: string) => {

View File

@ -1,7 +1,7 @@
import { useEffect, useRef } from 'react'; import { useEffect, useRef } from 'react';
import { useFrame } from '@react-three/fiber'; import { useFrame } from '@react-three/fiber';
import { useVehicleStore } from '../../../../store/simulation/useVehicleStore';
import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore'; import { usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../store/usePlayButtonStore';
import { useSceneContext } from '../../../scene/sceneContext';
type VehicleCallback = { type VehicleCallback = {
vehicleId: string; vehicleId: string;
@ -9,7 +9,8 @@ type VehicleCallback = {
}; };
export function useVehicleEventManager() { export function useVehicleEventManager() {
const { getVehicleById } = useVehicleStore(); const { vehicleStore } = useSceneContext();
const { getVehicleById } = vehicleStore();
const callbacksRef = useRef<VehicleCallback[]>([]); const callbacksRef = useRef<VehicleCallback[]>([]);
const isMonitoringRef = useRef(false); const isMonitoringRef = useRef(false);
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();

View File

@ -3,7 +3,7 @@ import { useFrame, useThree } from '@react-three/fiber';
import * as THREE from 'three'; import * as THREE from 'three';
import { Line } from '@react-three/drei'; import { Line } from '@react-three/drei';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore';
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore'; import { useSceneContext } from '../../../../scene/sceneContext';
interface VehicleAnimatorProps { interface VehicleAnimatorProps {
path: [number, number, number][]; path: [number, number, number][];
@ -15,8 +15,9 @@ interface VehicleAnimatorProps {
agvDetail: VehicleStatus; agvDetail: VehicleStatus;
} }
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: VehicleAnimatorProps) { function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: Readonly<VehicleAnimatorProps>) {
const { getVehicleById } = useVehicleStore(); const { vehicleStore } = useSceneContext();
const { getVehicleById } = vehicleStore();
const { isPaused } = usePauseButtonStore(); const { isPaused } = usePauseButtonStore();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { speed } = useAnimationPlaySpeed(); const { speed } = useAnimationPlaySpeed();

View File

@ -1,13 +1,9 @@
import React, { useCallback, useEffect, useRef, useState } from 'react'; import { useCallback, useEffect, useRef, useState } from 'react';
import VehicleAnimator from '../animator/vehicleAnimator'; import VehicleAnimator from '../animator/vehicleAnimator';
import * as THREE from 'three'; import * as THREE from 'three';
import { NavMeshQuery } from '@recast-navigation/core'; import { NavMeshQuery } from '@recast-navigation/core';
import { useNavMesh } from '../../../../../store/builder/store'; import { useNavMesh } from '../../../../../store/builder/store';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore'; import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
import { useArmBotStore } from '../../../../../store/simulation/useArmBotStore';
import { useConveyorStore } from '../../../../../store/simulation/useConveyorStore';
import { useStorageUnitStore } from '../../../../../store/simulation/useStorageUnitStore';
import { useProductStore } from '../../../../../store/simulation/useProductStore'; import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore'; import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler'; import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
@ -17,15 +13,15 @@ import { useSceneContext } from '../../../../scene/sceneContext';
function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) { function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) {
const { navMesh } = useNavMesh(); const { navMesh } = useNavMesh();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const { materialStore } = useSceneContext(); const { materialStore, armBotStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
const { removeMaterial, setEndTime } = materialStore(); const { removeMaterial, setEndTime } = materialStore();
const { getStorageUnitById } = useStorageUnitStore(); const { getStorageUnitById } = storageUnitStore();
const { getArmBotById } = useArmBotStore(); const { getArmBotById } = armBotStore();
const { getConveyorById } = useConveyorStore(); const { getConveyorById } = conveyorStore();
const { triggerPointActions } = useTriggerHandler(); const { triggerPointActions } = useTriggerHandler();
const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore(); const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
const { vehicles, setVehicleActive, setVehicleState, setVehiclePicking, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial, getLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = useVehicleStore(); const { vehicles, setVehicleActive, setVehicleState, setVehiclePicking, clearCurrentMaterials, setVehicleLoad, decrementVehicleLoad, removeLastMaterial, getLastMaterial, incrementIdleTime, incrementActiveTime, resetTime } = vehicleStore();
const [currentPhase, setCurrentPhase] = useState<string>('stationed'); const [currentPhase, setCurrentPhase] = useState<string>('stationed');
const [path, setPath] = useState<[number, number, number][]>([]); const [path, setPath] = useState<[number, number, number][]>([]);

View File

@ -1,10 +1,11 @@
import React from "react"; import React from "react";
import VehicleInstance from "./instance/vehicleInstance"; import VehicleInstance from "./instance/vehicleInstance";
import { useVehicleStore } from "../../../../store/simulation/useVehicleStore";
import VehicleContentUi from "../../ui3d/VehicleContentUi"; import VehicleContentUi from "../../ui3d/VehicleContentUi";
import { useSceneContext } from "../../../scene/sceneContext";
function VehicleInstances() { function VehicleInstances() {
const { vehicles } = useVehicleStore(); const { vehicleStore } = useSceneContext();
const { vehicles } = vehicleStore();
return ( return (
<> <>

View File

@ -1,12 +1,13 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useVehicleStore } from "../../../store/simulation/useVehicleStore";
import { useSelectedEventSphere } from "../../../store/simulation/useSimulationStore"; import { useSelectedEventSphere } from "../../../store/simulation/useSimulationStore";
import { usePlayButtonStore } from "../../../store/usePlayButtonStore"; import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
import VehicleInstances from "./instances/vehicleInstances"; import VehicleInstances from "./instances/vehicleInstances";
import VehicleUI from "../spatialUI/vehicle/vehicleUI"; import VehicleUI from "../spatialUI/vehicle/vehicleUI";
import { useSceneContext } from "../../scene/sceneContext";
function Vehicles() { function Vehicles() {
const { getVehicleById } = useVehicleStore(); const { vehicleStore } = useSceneContext();
const { getVehicleById } = vehicleStore();
const { selectedEventSphere } = useSelectedEventSphere(); const { selectedEventSphere } = useSelectedEventSphere();
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
const [isVehicleSelected, setIsVehicleSelected] = useState(false); const [isVehicleSelected, setIsVehicleSelected] = useState(false);

View File

@ -34,173 +34,177 @@ interface ArmBotStore {
getArmBotsByCurrentAction: (actionUuid: string) => ArmBotStatus[]; getArmBotsByCurrentAction: (actionUuid: string) => ArmBotStatus[];
} }
export const useArmBotStore = create<ArmBotStore>()( export const createArmBotStore = () => {
immer((set, get) => ({ return create<ArmBotStore>()(
armBots: [], immer((set, get) => ({
armBots: [],
addArmBot: (productId, event) => { addArmBot: (productId, event) => {
set((state) => { set((state) => {
const exists = state.armBots.some(a => a.modelUuid === event.modelUuid); const exists = state.armBots.some(a => a.modelUuid === event.modelUuid);
if (!exists) { if (!exists) {
state.armBots.push({ state.armBots.push({
...event, ...event,
productId, productId,
isActive: false, isActive: false,
idleTime: 0, idleTime: 0,
activeTime: 0, activeTime: 0,
state: 'idle', state: 'idle',
}); });
}
});
},
removeArmBot: (modelUuid) => {
set((state) => {
state.armBots = state.armBots.filter(a => a.modelUuid !== modelUuid);
});
},
updateArmBot: (modelUuid, updates) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
Object.assign(armBot, updates);
}
});
},
clearArmBots: () => {
set((state) => {
state.armBots = [];
});
},
addCurrentAction: (modelUuid, actionUuid, materialType, materialId) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
const action = armBot.point.actions.find(a => a.actionUuid === actionUuid);
if (action) {
armBot.currentAction = {
actionUuid: action.actionUuid,
actionName: action.actionName,
materialType: materialType,
materialId: materialId
};
} }
} });
}); },
},
removeCurrentAction: (modelUuid) => { removeArmBot: (modelUuid) => {
set((state) => { set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid); state.armBots = state.armBots.filter(a => a.modelUuid !== modelUuid);
if (armBot) { });
armBot.currentAction = undefined; },
}
});
},
addAction: (modelUuid, action) => { updateArmBot: (modelUuid, updates) => {
set((state) => { set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid); const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) { if (armBot) {
armBot.point.actions.push(action); Object.assign(armBot, updates);
}
});
},
removeAction: (modelUuid, actionUuid) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.point.actions = armBot.point.actions.filter(a => a.actionUuid !== actionUuid);
}
});
},
updateStartPoint: (modelUuid, actionUuid, startPoint) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
const action = armBot.point.actions.find(a => a.actionUuid === actionUuid);
if (action) {
action.process.startPoint = startPoint;
} }
} });
}); },
},
updateEndPoint: (modelUuid, actionUuid, endPoint) => { clearArmBots: () => {
set((state) => { set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid); state.armBots = [];
if (armBot) { });
const action = armBot.point.actions.find(a => a.actionUuid === actionUuid); },
if (action) {
action.process.endPoint = endPoint; addCurrentAction: (modelUuid, actionUuid, materialType, materialId) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
const action = armBot.point.actions.find(a => a.actionUuid === actionUuid);
if (action) {
armBot.currentAction = {
actionUuid: action.actionUuid,
actionName: action.actionName,
materialType: materialType,
materialId: materialId
};
}
} }
} });
}); },
},
setArmBotActive: (modelUuid, isActive) => { removeCurrentAction: (modelUuid) => {
set((state) => { set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid); const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) { if (armBot) {
armBot.isActive = isActive; armBot.currentAction = undefined;
} }
}); });
}, },
setArmBotState: (modelUuid, newState) => { addAction: (modelUuid, action) => {
set((state) => { set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid); const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) { if (armBot) {
armBot.state = newState; armBot.point.actions.push(action);
} }
}); });
}, },
incrementActiveTime: (modelUuid, incrementBy) => { removeAction: (modelUuid, actionUuid) => {
set((state) => { set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid); const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) { if (armBot) {
armBot.activeTime += incrementBy; armBot.point.actions = armBot.point.actions.filter(a => a.actionUuid !== actionUuid);
} }
}); });
}, },
incrementIdleTime: (modelUuid, incrementBy) => { updateStartPoint: (modelUuid, actionUuid, startPoint) => {
set((state) => { set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid); const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) { if (armBot) {
armBot.idleTime += incrementBy; const action = armBot.point.actions.find(a => a.actionUuid === actionUuid);
} if (action) {
}); action.process.startPoint = startPoint;
}, }
}
});
},
getArmBotById: (modelUuid) => { updateEndPoint: (modelUuid, actionUuid, endPoint) => {
return get().armBots.find(a => a.modelUuid === modelUuid); set((state) => {
}, const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
const action = armBot.point.actions.find(a => a.actionUuid === actionUuid);
if (action) {
action.process.endPoint = endPoint;
}
}
});
},
getArmBotsByProduct: (productId) => { setArmBotActive: (modelUuid, isActive) => {
return get().armBots.filter(a => a.productId === productId); set((state) => {
}, const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.isActive = isActive;
}
});
},
getArmBotsByState: (state) => { setArmBotState: (modelUuid, newState) => {
return get().armBots.filter(a => a.state === state); set((state) => {
}, const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.state = newState;
}
});
},
getActiveArmBots: () => { incrementActiveTime: (modelUuid, incrementBy) => {
return get().armBots.filter(a => a.isActive); set((state) => {
}, const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.activeTime += incrementBy;
}
});
},
getIdleArmBots: () => { incrementIdleTime: (modelUuid, incrementBy) => {
return get().armBots.filter(a => !a.isActive && a.state === 'idle'); set((state) => {
}, const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.idleTime += incrementBy;
}
});
},
getArmBotsByCurrentAction: (actionUuid) => { getArmBotById: (modelUuid) => {
return get().armBots.filter(a => a.currentAction?.actionUuid === actionUuid); return get().armBots.find(a => a.modelUuid === modelUuid);
} },
}))
); getArmBotsByProduct: (productId) => {
return get().armBots.filter(a => a.productId === productId);
},
getArmBotsByState: (state) => {
return get().armBots.filter(a => a.state === state);
},
getActiveArmBots: () => {
return get().armBots.filter(a => a.isActive);
},
getIdleArmBots: () => {
return get().armBots.filter(a => !a.isActive && a.state === 'idle');
},
getArmBotsByCurrentAction: (actionUuid) => {
return get().armBots.filter(a => a.currentAction?.actionUuid === actionUuid);
}
}))
)
}
export type ArmBotStoreType = ReturnType<typeof createArmBotStore>;

View File

@ -26,111 +26,115 @@ interface ConveyorStore {
getIdleConveyors: () => ConveyorStatus[]; getIdleConveyors: () => ConveyorStatus[];
} }
export const useConveyorStore = create<ConveyorStore>()( export const createConveyorStore = () => {
immer((set, get) => ({ return create<ConveyorStore>()(
conveyors: [], immer((set, get) => ({
conveyors: [],
addConveyor: (productId, event) => { addConveyor: (productId, event) => {
set((state) => { set((state) => {
const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid); const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid);
if (!exists) { if (!exists) {
state.conveyors.push({ state.conveyors.push({
...event, ...event,
productId, productId,
isActive: false, isActive: false,
isPaused: false, isPaused: false,
idleTime: 0, idleTime: 0,
activeTime: 0, activeTime: 0,
state: 'idle', state: 'idle',
}); });
} }
}); });
}, },
removeConveyor: (modelUuid) => { removeConveyor: (modelUuid) => {
set((state) => { set((state) => {
state.conveyors = state.conveyors.filter(c => c.modelUuid !== modelUuid); state.conveyors = state.conveyors.filter(c => c.modelUuid !== modelUuid);
}); });
}, },
updateConveyor: (modelUuid, updates) => { updateConveyor: (modelUuid, updates) => {
set((state) => { set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) { if (conveyor) {
Object.assign(conveyor, updates); Object.assign(conveyor, updates);
} }
}); });
}, },
clearConveyors: () => { clearConveyors: () => {
set((state) => { set((state) => {
state.conveyors = []; state.conveyors = [];
}); });
}, },
setConveyorActive: (modelUuid, isActive) => { setConveyorActive: (modelUuid, isActive) => {
set((state) => { set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) { if (conveyor) {
conveyor.isActive = isActive; conveyor.isActive = isActive;
} }
}); });
}, },
setConveyorState: (modelUuid, newState) => { setConveyorState: (modelUuid, newState) => {
set((state) => { set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) { if (conveyor) {
conveyor.state = newState; conveyor.state = newState;
} }
}); });
}, },
setConveyorPaused: (modelUuid, isPaused) => { setConveyorPaused: (modelUuid, isPaused) => {
set((state) => { set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) { if (conveyor) {
conveyor.isPaused = isPaused; conveyor.isPaused = isPaused;
} }
}); });
}, },
incrementActiveTime: (modelUuid, incrementBy) => { incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) { if (conveyor) {
conveyor.activeTime += incrementBy; conveyor.activeTime += incrementBy;
} }
}); });
}, },
incrementIdleTime: (modelUuid, incrementBy) => { incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid); const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) { if (conveyor) {
conveyor.idleTime += incrementBy; conveyor.idleTime += incrementBy;
} }
}); });
}, },
getConveyorById: (modelUuid) => { getConveyorById: (modelUuid) => {
return get().conveyors.find(c => c.modelUuid === modelUuid); return get().conveyors.find(c => c.modelUuid === modelUuid);
}, },
getConveyorsByProduct: (productId) => { getConveyorsByProduct: (productId) => {
return get().conveyors.filter(c => c.productId === productId); return get().conveyors.filter(c => c.productId === productId);
}, },
getConveyorsByState: (state) => { getConveyorsByState: (state) => {
return get().conveyors.filter(c => c.state === state); return get().conveyors.filter(c => c.state === state);
}, },
getActiveConveyors: () => { getActiveConveyors: () => {
return get().conveyors.filter(c => c.isActive); return get().conveyors.filter(c => c.isActive);
}, },
getIdleConveyors: () => { getIdleConveyors: () => {
return get().conveyors.filter(c => !c.isActive && c.state === 'idle'); return get().conveyors.filter(c => !c.isActive && c.state === 'idle');
}, },
})) }))
); )
}
export type ConveyorStoreType = ReturnType<typeof createConveyorStore>;

View File

@ -37,140 +37,144 @@ interface MachineStore {
getIdleMachines: () => MachineStatus[]; getIdleMachines: () => MachineStatus[];
} }
export const useMachineStore = create<MachineStore>()( export const createMachineStore = () => {
immer((set, get) => ({ return create<MachineStore>()(
machines: [], immer((set, get) => ({
machines: [],
addMachine: (productId, machine) => { addMachine: (productId, machine) => {
set((state) => { set((state) => {
const exists = state.machines.some( const exists = state.machines.some(
(m) => m.modelUuid === machine.modelUuid (m) => m.modelUuid === machine.modelUuid
); );
if (!exists) { if (!exists) {
state.machines.push({ state.machines.push({
...machine, ...machine,
productId, productId,
isActive: false, isActive: false,
idleTime: 0, idleTime: 0,
activeTime: 0, activeTime: 0,
state: "idle", state: "idle",
}); });
}
});
},
removeMachine: (modelUuid) => {
set((state) => {
state.machines = state.machines.filter(
(m) => m.modelUuid !== modelUuid
);
});
},
updateMachine: (modelUuid, updates) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
Object.assign(machine, updates);
}
});
},
clearMachines: () => {
set((state) => {
state.machines = [];
});
},
addCurrentAction: (modelUuid, actionUuid, materialType, materialId) => {
set((state) => {
const armBot = state.machines.find((a) => a.modelUuid === modelUuid);
if (armBot) {
const action = armBot.point.action;
if (action) {
armBot.currentAction = {
actionUuid: actionUuid,
actionName: action.actionName,
materialType: materialType,
materialId: materialId,
};
} }
} });
}); },
},
removeCurrentAction: (modelUuid) => { removeMachine: (modelUuid) => {
set((state) => { set((state) => {
const armBot = state.machines.find((a) => a.modelUuid === modelUuid); state.machines = state.machines.filter(
if (armBot) { (m) => m.modelUuid !== modelUuid
armBot.currentAction = undefined; );
} });
}); },
},
setMachineActive: (modelUuid, isActive) => { updateMachine: (modelUuid, updates) => {
set((state) => { set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid); const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) { if (machine) {
machine.isActive = isActive; Object.assign(machine, updates);
} }
}); });
}, },
setMachineState: (modelUuid, newState) => { clearMachines: () => {
set((state) => { set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid); state.machines = [];
if (machine) { });
machine.state = newState; },
}
});
},
incrementActiveTime: (modelUuid, incrementBy) => { addCurrentAction: (modelUuid, actionUuid, materialType, materialId) => {
set((state) => { set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid); const armBot = state.machines.find((a) => a.modelUuid === modelUuid);
if (machine) { if (armBot) {
machine.activeTime += incrementBy; const action = armBot.point.action;
} if (action) {
}); armBot.currentAction = {
}, actionUuid: actionUuid,
actionName: action.actionName,
materialType: materialType,
materialId: materialId,
};
}
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => { removeCurrentAction: (modelUuid) => {
set((state) => { set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid); const armBot = state.machines.find((a) => a.modelUuid === modelUuid);
if (machine) { if (armBot) {
machine.idleTime += incrementBy; armBot.currentAction = undefined;
} }
}); });
}, },
resetTime: (modelUuid) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.activeTime = 0;
machine.idleTime = 0;
}
});
},
getMachineById: (modelUuid) => { setMachineActive: (modelUuid, isActive) => {
return get().machines.find((m) => m.modelUuid === modelUuid); set((state) => {
}, const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.isActive = isActive;
}
});
},
getMachinesByProduct: (productId) => { setMachineState: (modelUuid, newState) => {
return get().machines.filter((m) => m.productId === productId); set((state) => {
}, const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.state = newState;
}
});
},
getMachinesBystate: (state) => { incrementActiveTime: (modelUuid, incrementBy) => {
return get().machines.filter((m) => m.state === state); set((state) => {
}, const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.activeTime += incrementBy;
}
});
},
getActiveMachines: () => { incrementIdleTime: (modelUuid, incrementBy) => {
return get().machines.filter((m) => m.isActive); set((state) => {
}, const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.idleTime += incrementBy;
}
});
},
resetTime: (modelUuid) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.activeTime = 0;
machine.idleTime = 0;
}
});
},
getIdleMachines: () => { getMachineById: (modelUuid) => {
return get().machines.filter((m) => !m.isActive && m.state === "idle"); return get().machines.find((m) => m.modelUuid === modelUuid);
}, },
}))
); getMachinesByProduct: (productId) => {
return get().machines.filter((m) => m.productId === productId);
},
getMachinesBystate: (state) => {
return get().machines.filter((m) => m.state === state);
},
getActiveMachines: () => {
return get().machines.filter((m) => m.isActive);
},
getIdleMachines: () => {
return get().machines.filter((m) => !m.isActive && m.state === "idle");
},
}))
)
}
export type MachineStoreType = ReturnType<typeof createMachineStore>;

View File

@ -35,181 +35,185 @@ interface StorageUnitStore {
getEmptyStorageUnits: () => StorageUnitStatus[]; getEmptyStorageUnits: () => StorageUnitStatus[];
} }
export const useStorageUnitStore = create<StorageUnitStore>()( export const createStorageUnitStore = () => {
immer((set, get) => ({ return create<StorageUnitStore>()(
storageUnits: [], immer((set, get) => ({
storageUnits: [],
addStorageUnit: (productId, storageUnit) => { addStorageUnit: (productId, storageUnit) => {
set((state) => { set((state) => {
const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid); const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid);
if (!exists) { if (!exists) {
state.storageUnits.push({ state.storageUnits.push({
...storageUnit, ...storageUnit,
productId, productId,
isActive: false, isActive: false,
idleTime: 0, idleTime: 0,
activeTime: 0, activeTime: 0,
currentLoad: 0, currentLoad: 0,
currentMaterials: [], currentMaterials: [],
state: 'idle' state: 'idle'
}); });
} }
}); });
}, },
removeStorageUnit: (modelUuid) => { removeStorageUnit: (modelUuid) => {
set((state) => { set((state) => {
state.storageUnits = state.storageUnits.filter(s => s.modelUuid !== modelUuid); state.storageUnits = state.storageUnits.filter(s => s.modelUuid !== modelUuid);
}); });
}, },
updateStorageUnit: (modelUuid, updates) => { updateStorageUnit: (modelUuid, updates) => {
set((state) => { set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) { if (unit) {
Object.assign(unit, updates); Object.assign(unit, updates);
} }
}); });
}, },
clearStorageUnits: () => { clearStorageUnits: () => {
set(() => ({ set(() => ({
storageUnits: [], storageUnits: [],
})); }));
}, },
setStorageUnitActive: (modelUuid, isActive) => { setStorageUnitActive: (modelUuid, isActive) => {
set((state) => { set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) { if (unit) {
unit.isActive = isActive; unit.isActive = isActive;
} }
}); });
}, },
setStorageUnitState: (modelUuid, newState) => { setStorageUnitState: (modelUuid, newState) => {
set((state) => { set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) { if (unit) {
unit.state = newState; unit.state = newState;
} }
}); });
}, },
updateCurrentLoad: (modelUuid, incrementBy) => { updateCurrentLoad: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) { if (unit) {
unit.currentLoad += incrementBy; unit.currentLoad += incrementBy;
} }
}); });
}, },
incrementActiveTime: (modelUuid, incrementBy) => { incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) { if (unit) {
unit.activeTime += incrementBy; unit.activeTime += incrementBy;
} }
}); });
}, },
incrementIdleTime: (modelUuid, incrementBy) => { incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid); const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) { if (unit) {
unit.idleTime += incrementBy; unit.idleTime += incrementBy;
} }
}); });
}, },
addCurrentMaterial: (modelUuid, materialType, materialId) => { addCurrentMaterial: (modelUuid, materialType, materialId) => {
set((state) => { set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) { if (storage) {
storage.currentMaterials.push({ materialType, materialId }); storage.currentMaterials.push({ materialType, materialId });
} }
}); });
}, },
setCurrentMaterials: (modelUuid, materials) => { setCurrentMaterials: (modelUuid, materials) => {
set((state) => { set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) { if (storage) {
storage.currentMaterials = materials; storage.currentMaterials = materials;
} }
}); });
}, },
getLastMaterial: (modelUuid) => { getLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined; let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => { set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) { if (storage) {
if (storage.currentMaterials.length > 0) { if (storage.currentMaterials.length > 0) {
const material = storage.currentMaterials[storage.currentMaterials.length - 1]; const material = storage.currentMaterials[storage.currentMaterials.length - 1];
if (material) { if (material) {
removedMaterial = { materialId: material.materialId, materialType: material.materialType }; removedMaterial = { materialId: material.materialId, materialType: material.materialType };
}
} }
} }
} });
}); return removedMaterial;
return removedMaterial; },
},
removeLastMaterial: (modelUuid) => { removeLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined; let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => { set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) { if (storage) {
if (storage.currentMaterials.length > 0) { if (storage.currentMaterials.length > 0) {
const material = storage.currentMaterials.pop(); const material = storage.currentMaterials.pop();
if (material) { if (material) {
removedMaterial = { materialId: material.materialId, materialType: material.materialType }; removedMaterial = { materialId: material.materialId, materialType: material.materialType };
}
} }
} }
} });
}); return removedMaterial;
return removedMaterial; },
},
clearCurrentMaterials: (modelUuid) => { clearCurrentMaterials: (modelUuid) => {
set((state) => { set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid); const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) { if (storage) {
storage.currentMaterials = []; storage.currentMaterials = [];
} }
}); });
}, },
getStorageUnitById: (modelUuid) => { getStorageUnitById: (modelUuid) => {
return get().storageUnits.find(s => s.modelUuid === modelUuid); return get().storageUnits.find(s => s.modelUuid === modelUuid);
}, },
getStorageUnitsByProduct: (productId) => { getStorageUnitsByProduct: (productId) => {
return get().storageUnits.filter(s => s.productId === productId); return get().storageUnits.filter(s => s.productId === productId);
}, },
getStorageUnitsBystate: (state) => { getStorageUnitsBystate: (state) => {
return get().storageUnits.filter(s => s.state === state); return get().storageUnits.filter(s => s.state === state);
}, },
getActiveStorageUnits: () => { getActiveStorageUnits: () => {
return get().storageUnits.filter(s => s.isActive); return get().storageUnits.filter(s => s.isActive);
}, },
getIdleStorageUnits: () => { getIdleStorageUnits: () => {
return get().storageUnits.filter(s => !s.isActive && s.state === 'idle'); return get().storageUnits.filter(s => !s.isActive && s.state === 'idle');
}, },
getFullStorageUnits: () => { getFullStorageUnits: () => {
return get().storageUnits.filter( return get().storageUnits.filter(
s => s.currentLoad >= s.point.action.storageCapacity s => s.currentLoad >= s.point.action.storageCapacity
); );
}, },
getEmptyStorageUnits: () => { getEmptyStorageUnits: () => {
return get().storageUnits.filter(s => s.currentLoad === 0); return get().storageUnits.filter(s => s.currentLoad === 0);
}, },
})) }))
); )
}
export type StorageUnitStoreType = ReturnType<typeof createStorageUnitStore>;

View File

@ -37,217 +37,221 @@ interface VehiclesStore {
getActiveVehicles: () => VehicleStatus[]; getActiveVehicles: () => VehicleStatus[];
} }
export const useVehicleStore = create<VehiclesStore>()( export const createVehicleStore = () => {
immer((set, get) => ({ return create<VehiclesStore>()(
vehicles: [], immer((set, get) => ({
vehicles: [],
addVehicle: (productId, event) => { addVehicle: (productId, event) => {
set((state) => { set((state) => {
const exists = state.vehicles.some((v) => v.modelUuid === event.modelUuid); const exists = state.vehicles.some((v) => v.modelUuid === event.modelUuid);
if (!exists) { if (!exists) {
state.vehicles.push({ state.vehicles.push({
...event, ...event,
productId, productId,
isActive: false, isActive: false,
isPicking: false, isPicking: false,
idleTime: 0, idleTime: 0,
activeTime: 0, activeTime: 0,
currentLoad: 0, currentLoad: 0,
currentMaterials: [], currentMaterials: [],
distanceTraveled: 0, distanceTraveled: 0,
state: 'idle' state: 'idle'
}); });
} }
}); });
}, },
removeVehicle: (modelUuid) => { removeVehicle: (modelUuid) => {
set((state) => { set((state) => {
state.vehicles = state.vehicles.filter( state.vehicles = state.vehicles.filter(
(v) => v.modelUuid !== modelUuid (v) => v.modelUuid !== modelUuid
); );
}); });
}, },
updateVehicle: (modelUuid, updates) => { updateVehicle: (modelUuid, updates) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
Object.assign(vehicle, updates); Object.assign(vehicle, updates);
} }
}); });
}, },
clearvehicles: () => { clearvehicles: () => {
set((state) => { set((state) => {
state.vehicles = []; state.vehicles = [];
}); });
}, },
setVehicleActive: (modelUuid, isActive) => { setVehicleActive: (modelUuid, isActive) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.isActive = isActive; vehicle.isActive = isActive;
} }
}); });
}, },
setVehiclePicking: (modelUuid, isPicking) => { setVehiclePicking: (modelUuid, isPicking) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.isPicking = isPicking; vehicle.isPicking = isPicking;
} }
}); });
}, },
updateSteeringAngle: (modelUuid, steeringAngle) => { updateSteeringAngle: (modelUuid, steeringAngle) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.point.action.steeringAngle = steeringAngle; vehicle.point.action.steeringAngle = steeringAngle;
} }
}); });
}, },
incrementVehicleLoad: (modelUuid, incrementBy) => { incrementVehicleLoad: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.currentLoad += incrementBy; vehicle.currentLoad += incrementBy;
} }
}); });
}, },
decrementVehicleLoad: (modelUuid, decrementBy) => { decrementVehicleLoad: (modelUuid, decrementBy) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.currentLoad -= decrementBy; vehicle.currentLoad -= decrementBy;
} }
}); });
}, },
setVehicleLoad: (modelUuid, load) => { setVehicleLoad: (modelUuid, load) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.currentLoad = load; vehicle.currentLoad = load;
} }
}); });
}, },
setVehicleState: (modelUuid, newState) => { setVehicleState: (modelUuid, newState) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.state = newState; vehicle.state = newState;
} }
}); });
}, },
addCurrentMaterial: (modelUuid, materialType, materialId) => { addCurrentMaterial: (modelUuid, materialType, materialId) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.currentMaterials.push({ materialType, materialId }); vehicle.currentMaterials.push({ materialType, materialId });
} }
}); });
}, },
setCurrentMaterials: (modelUuid, materials) => { setCurrentMaterials: (modelUuid, materials) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.currentMaterials = materials; vehicle.currentMaterials = materials;
} }
}); });
}, },
removeLastMaterial: (modelUuid) => { removeLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined; let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
if (vehicle.currentMaterials.length > 0) { if (vehicle.currentMaterials.length > 0) {
const material = vehicle.currentMaterials.pop(); const material = vehicle.currentMaterials.pop();
if (material) { if (material) {
removedMaterial = { materialId: material.materialId, materialType: material.materialType }; removedMaterial = { materialId: material.materialId, materialType: material.materialType };
}
} }
} }
} });
}); return removedMaterial;
return removedMaterial; },
},
getLastMaterial: (modelUuid) => { getLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined; let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
if (vehicle.currentMaterials.length > 0) { if (vehicle.currentMaterials.length > 0) {
removedMaterial = { removedMaterial = {
materialId: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialId, materialId: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialId,
materialType: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialType materialType: vehicle.currentMaterials[vehicle.currentMaterials.length - 1].materialType
}; };
}
} }
} });
}); return removedMaterial;
return removedMaterial; },
},
clearCurrentMaterials: (modelUuid) => { clearCurrentMaterials: (modelUuid) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.currentMaterials = []; vehicle.currentMaterials = [];
} }
}); });
}, },
incrementActiveTime: (modelUuid, incrementBy) => { incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.activeTime += incrementBy; vehicle.activeTime += incrementBy;
} }
}); });
}, },
incrementIdleTime: (modelUuid, incrementBy) => { incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.idleTime += incrementBy; vehicle.idleTime += incrementBy;
} }
}); });
}, },
resetTime: (modelUuid) => { resetTime: (modelUuid) => {
set((state) => { set((state) => {
const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid); const vehicle = state.vehicles.find((v) => v.modelUuid === modelUuid);
if (vehicle) { if (vehicle) {
vehicle.activeTime = 0; vehicle.activeTime = 0;
vehicle.idleTime = 0; vehicle.idleTime = 0;
} }
}); });
}, },
getVehicleById: (modelUuid) => { getVehicleById: (modelUuid) => {
return get().vehicles.find((v) => v.modelUuid === modelUuid); return get().vehicles.find((v) => v.modelUuid === modelUuid);
}, },
getVehiclesByProduct: (productId) => { getVehiclesByProduct: (productId) => {
return get().vehicles.filter((v) => v.productId === productId); return get().vehicles.filter((v) => v.productId === productId);
}, },
getVehiclesByState: (state) => { getVehiclesByState: (state) => {
return get().vehicles.filter((v) => v.state === state); return get().vehicles.filter((v) => v.state === state);
}, },
getActiveVehicles: () => { getActiveVehicles: () => {
return get().vehicles.filter((v) => v.isActive); return get().vehicles.filter((v) => v.isActive);
}, },
})) }))
); )
}
export type VehicleStoreType = ReturnType<typeof createVehicleStore>;