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 { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useProductStore } from "../../../../../../store/simulation/useProductStore";
import { useStorageUnitStore } from "../../../../../../store/simulation/useStorageUnitStore";
import { useSelectedAction, useSelectedEventData, useSelectedProduct } from "../../../../../../store/simulation/useSimulationStore";
import * as THREE from 'three';
import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function StorageMechanics() {
const { storageUnitStore } = useSceneContext();
const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default");
const [selectedPointData, setSelectedPointData] = useState<StoragePointSchema | undefined>();
const { selectedEventData } = useSelectedEventData();
const { getPointByUuid, updateAction } = useProductStore();
const { selectedProduct } = useSelectedProduct();
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
const { setCurrentMaterials, clearCurrentMaterials, updateCurrentLoad, getStorageUnitById } = useStorageUnitStore();
const { setCurrentMaterials, clearCurrentMaterials, updateCurrentLoad, getStorageUnitById } = storageUnitStore();
const email = localStorage.getItem('email')
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 ActionsList from "../components/ActionsList";
import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi";
import { useVehicleStore } from "../../../../../../store/simulation/useVehicleStore";
import { useSceneContext } from "../../../../../../modules/scene/sceneContext";
function VehicleMechanics() {
const [activeOption, setActiveOption] = useState<"default" | "travel">(
"default"
);
const [selectedPointData, setSelectedPointData] = useState<
VehiclePointSchema | undefined
>();
const { vehicleStore } = useSceneContext();
const [activeOption, setActiveOption] = useState<"default" | "travel">("default");
const [selectedPointData, setSelectedPointData] = useState<VehiclePointSchema | undefined>();
const { selectedEventData } = useSelectedEventData();
const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } =
useProductStore();
const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction } = useProductStore();
const { selectedProduct } = useSelectedProduct();
const { setSelectedAction, clearSelectedAction } = useSelectedAction();
const { getVehicleById } = useVehicleStore();
const { getVehicleById } = vehicleStore();
const email = localStorage.getItem("email");
const organization = email!.split("@")[1].split(".")[0];
@ -255,7 +251,7 @@ function VehicleMechanics() {
defaultValue={"0.5"}
max={10}
activeOption="m/s"
onClick={() => {}}
onClick={() => { }}
onChange={handleSpeedChange}
/>
</div>
@ -294,14 +290,14 @@ function VehicleMechanics() {
onChange: handleUnloadDurationChange,
}}
clearPoints={handleClearPoints}
// pickPoint={{
// value: currentPickPoint,
// onChange: handlePickPointChange,
// }}
// unloadPoint={{
// value: currentUnloadPoint,
// onChange: handleUnloadPointChange,
// }}
// pickPoint={{
// value: currentPickPoint,
// onChange: handlePickPointChange,
// }}
// unloadPoint={{
// value: currentUnloadPoint,
// onChange: handleUnloadPointChange,
// }}
/>
)}
</div>

View File

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

View File

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

View File

@ -1,16 +1,40 @@
import { createContext, useContext, useMemo } from 'react';
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 = {
materialStore: MaterialStoreType;
// Add other stores here if needed
armBotStore: ArmBotStoreType;
machineStore: MachineStoreType;
conveyorStore: ConveyorStoreType;
vehicleStore: VehicleStoreType;
storageUnitStore: StorageUnitStoreType;
};
const SceneContext = createContext<SceneContextValue | null>(null);
export function SceneProvider({ children }: { readonly children: React.ReactNode }) {
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 (
<SceneContext.Provider value={contextValue}>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
import { useEffect, useRef, useState } from 'react'
import { useMachineStore } from '../../../../../store/simulation/useMachineStore';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore } from '../../../../../store/usePlayButtonStore';
import MachineAnimator from '../animator/machineAnimator';
import { useProductStore } from '../../../../../store/simulation/useProductStore';
import { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
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');
let isIncrememtable = useRef<boolean>(true);
const idleTimeRef = useRef<number>(0);
@ -16,7 +16,8 @@ function MachineInstance({ machineDetail }: { machineDetail: MachineStatus }) {
const isSpeedRef = useRef<number>(0);
const isPausedRef = useRef<boolean>(false);
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 { getActionByUuid } = useProductStore();
const { triggerPointActions } = useTriggerHandler();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ import { useFrame, useThree } from '@react-three/fiber';
import * as THREE from 'three';
import { Line } from '@react-three/drei';
import { useAnimationPlaySpeed, usePauseButtonStore, usePlayButtonStore, useResetButtonStore } from '../../../../../store/usePlayButtonStore';
import { useVehicleStore } from '../../../../../store/simulation/useVehicleStore';
import { useSceneContext } from '../../../../scene/sceneContext';
interface VehicleAnimatorProps {
path: [number, number, number][];
@ -15,8 +15,9 @@ interface VehicleAnimatorProps {
agvDetail: VehicleStatus;
}
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: VehicleAnimatorProps) {
const { getVehicleById } = useVehicleStore();
function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetail, reset, startUnloadingProcess }: Readonly<VehicleAnimatorProps>) {
const { vehicleStore } = useSceneContext();
const { getVehicleById } = vehicleStore();
const { isPaused } = usePauseButtonStore();
const { isPlaying } = usePlayButtonStore();
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 * as THREE from 'three';
import { NavMeshQuery } from '@recast-navigation/core';
import { useNavMesh } from '../../../../../store/builder/store';
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 { useSelectedProduct } from '../../../../../store/simulation/useSimulationStore';
import { useTriggerHandler } from '../../../triggers/triggerHandler/useTriggerHandler';
@ -17,15 +13,15 @@ import { useSceneContext } from '../../../../scene/sceneContext';
function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>) {
const { navMesh } = useNavMesh();
const { isPlaying } = usePlayButtonStore();
const { materialStore } = useSceneContext();
const { materialStore, armBotStore, conveyorStore, vehicleStore, storageUnitStore } = useSceneContext();
const { removeMaterial, setEndTime } = materialStore();
const { getStorageUnitById } = useStorageUnitStore();
const { getArmBotById } = useArmBotStore();
const { getConveyorById } = useConveyorStore();
const { getStorageUnitById } = storageUnitStore();
const { getArmBotById } = armBotStore();
const { getConveyorById } = conveyorStore();
const { triggerPointActions } = useTriggerHandler();
const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore();
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 [path, setPath] = useState<[number, number, number][]>([]);

View File

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

View File

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

View File

@ -34,173 +34,177 @@ interface ArmBotStore {
getArmBotsByCurrentAction: (actionUuid: string) => ArmBotStatus[];
}
export const useArmBotStore = create<ArmBotStore>()(
immer((set, get) => ({
armBots: [],
export const createArmBotStore = () => {
return create<ArmBotStore>()(
immer((set, get) => ({
armBots: [],
addArmBot: (productId, event) => {
set((state) => {
const exists = state.armBots.some(a => a.modelUuid === event.modelUuid);
if (!exists) {
state.armBots.push({
...event,
productId,
isActive: false,
idleTime: 0,
activeTime: 0,
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
};
addArmBot: (productId, event) => {
set((state) => {
const exists = state.armBots.some(a => a.modelUuid === event.modelUuid);
if (!exists) {
state.armBots.push({
...event,
productId,
isActive: false,
idleTime: 0,
activeTime: 0,
state: 'idle',
});
}
}
});
},
});
},
removeCurrentAction: (modelUuid) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.currentAction = undefined;
}
});
},
removeArmBot: (modelUuid) => {
set((state) => {
state.armBots = state.armBots.filter(a => a.modelUuid !== modelUuid);
});
},
addAction: (modelUuid, action) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.point.actions.push(action);
}
});
},
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;
updateArmBot: (modelUuid, updates) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
Object.assign(armBot, updates);
}
}
});
},
});
},
updateEndPoint: (modelUuid, actionUuid, endPoint) => {
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;
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
};
}
}
}
});
},
});
},
setArmBotActive: (modelUuid, isActive) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.isActive = isActive;
}
});
},
removeCurrentAction: (modelUuid) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.currentAction = undefined;
}
});
},
setArmBotState: (modelUuid, newState) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.state = newState;
}
});
},
addAction: (modelUuid, action) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.point.actions.push(action);
}
});
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.activeTime += incrementBy;
}
});
},
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);
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.idleTime += incrementBy;
}
});
},
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;
}
}
});
},
getArmBotById: (modelUuid) => {
return get().armBots.find(a => a.modelUuid === modelUuid);
},
updateEndPoint: (modelUuid, actionUuid, endPoint) => {
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) => {
return get().armBots.filter(a => a.productId === productId);
},
setArmBotActive: (modelUuid, isActive) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.isActive = isActive;
}
});
},
getArmBotsByState: (state) => {
return get().armBots.filter(a => a.state === state);
},
setArmBotState: (modelUuid, newState) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.state = newState;
}
});
},
getActiveArmBots: () => {
return get().armBots.filter(a => a.isActive);
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.activeTime += incrementBy;
}
});
},
getIdleArmBots: () => {
return get().armBots.filter(a => !a.isActive && a.state === 'idle');
},
incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => {
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
if (armBot) {
armBot.idleTime += incrementBy;
}
});
},
getArmBotsByCurrentAction: (actionUuid) => {
return get().armBots.filter(a => a.currentAction?.actionUuid === actionUuid);
}
}))
);
getArmBotById: (modelUuid) => {
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[];
}
export const useConveyorStore = create<ConveyorStore>()(
immer((set, get) => ({
conveyors: [],
export const createConveyorStore = () => {
return create<ConveyorStore>()(
immer((set, get) => ({
conveyors: [],
addConveyor: (productId, event) => {
set((state) => {
const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid);
if (!exists) {
state.conveyors.push({
...event,
productId,
isActive: false,
isPaused: false,
idleTime: 0,
activeTime: 0,
state: 'idle',
});
}
});
},
addConveyor: (productId, event) => {
set((state) => {
const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid);
if (!exists) {
state.conveyors.push({
...event,
productId,
isActive: false,
isPaused: false,
idleTime: 0,
activeTime: 0,
state: 'idle',
});
}
});
},
removeConveyor: (modelUuid) => {
set((state) => {
state.conveyors = state.conveyors.filter(c => c.modelUuid !== modelUuid);
});
},
removeConveyor: (modelUuid) => {
set((state) => {
state.conveyors = state.conveyors.filter(c => c.modelUuid !== modelUuid);
});
},
updateConveyor: (modelUuid, updates) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
Object.assign(conveyor, updates);
}
});
},
updateConveyor: (modelUuid, updates) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
Object.assign(conveyor, updates);
}
});
},
clearConveyors: () => {
set((state) => {
state.conveyors = [];
});
},
clearConveyors: () => {
set((state) => {
state.conveyors = [];
});
},
setConveyorActive: (modelUuid, isActive) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.isActive = isActive;
}
});
},
setConveyorActive: (modelUuid, isActive) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.isActive = isActive;
}
});
},
setConveyorState: (modelUuid, newState) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.state = newState;
}
});
},
setConveyorState: (modelUuid, newState) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.state = newState;
}
});
},
setConveyorPaused: (modelUuid, isPaused) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.isPaused = isPaused;
}
});
},
setConveyorPaused: (modelUuid, isPaused) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.isPaused = isPaused;
}
});
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.activeTime += incrementBy;
}
});
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.activeTime += incrementBy;
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.idleTime += incrementBy;
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => {
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
if (conveyor) {
conveyor.idleTime += incrementBy;
}
});
},
getConveyorById: (modelUuid) => {
return get().conveyors.find(c => c.modelUuid === modelUuid);
},
getConveyorById: (modelUuid) => {
return get().conveyors.find(c => c.modelUuid === modelUuid);
},
getConveyorsByProduct: (productId) => {
return get().conveyors.filter(c => c.productId === productId);
},
getConveyorsByProduct: (productId) => {
return get().conveyors.filter(c => c.productId === productId);
},
getConveyorsByState: (state) => {
return get().conveyors.filter(c => c.state === state);
},
getConveyorsByState: (state) => {
return get().conveyors.filter(c => c.state === state);
},
getActiveConveyors: () => {
return get().conveyors.filter(c => c.isActive);
},
getActiveConveyors: () => {
return get().conveyors.filter(c => c.isActive);
},
getIdleConveyors: () => {
return get().conveyors.filter(c => !c.isActive && c.state === 'idle');
},
}))
);
getIdleConveyors: () => {
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[];
}
export const useMachineStore = create<MachineStore>()(
immer((set, get) => ({
machines: [],
export const createMachineStore = () => {
return create<MachineStore>()(
immer((set, get) => ({
machines: [],
addMachine: (productId, machine) => {
set((state) => {
const exists = state.machines.some(
(m) => m.modelUuid === machine.modelUuid
);
if (!exists) {
state.machines.push({
...machine,
productId,
isActive: false,
idleTime: 0,
activeTime: 0,
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,
};
addMachine: (productId, machine) => {
set((state) => {
const exists = state.machines.some(
(m) => m.modelUuid === machine.modelUuid
);
if (!exists) {
state.machines.push({
...machine,
productId,
isActive: false,
idleTime: 0,
activeTime: 0,
state: "idle",
});
}
}
});
},
});
},
removeCurrentAction: (modelUuid) => {
set((state) => {
const armBot = state.machines.find((a) => a.modelUuid === modelUuid);
if (armBot) {
armBot.currentAction = undefined;
}
});
},
removeMachine: (modelUuid) => {
set((state) => {
state.machines = state.machines.filter(
(m) => m.modelUuid !== modelUuid
);
});
},
setMachineActive: (modelUuid, isActive) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.isActive = isActive;
}
});
},
updateMachine: (modelUuid, updates) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
Object.assign(machine, updates);
}
});
},
setMachineState: (modelUuid, newState) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.state = newState;
}
});
},
clearMachines: () => {
set((state) => {
state.machines = [];
});
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.activeTime += incrementBy;
}
});
},
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,
};
}
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => {
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;
}
});
},
removeCurrentAction: (modelUuid) => {
set((state) => {
const armBot = state.machines.find((a) => a.modelUuid === modelUuid);
if (armBot) {
armBot.currentAction = undefined;
}
});
},
getMachineById: (modelUuid) => {
return get().machines.find((m) => m.modelUuid === modelUuid);
},
setMachineActive: (modelUuid, isActive) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.isActive = isActive;
}
});
},
getMachinesByProduct: (productId) => {
return get().machines.filter((m) => m.productId === productId);
},
setMachineState: (modelUuid, newState) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.state = newState;
}
});
},
getMachinesBystate: (state) => {
return get().machines.filter((m) => m.state === state);
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const machine = state.machines.find((m) => m.modelUuid === modelUuid);
if (machine) {
machine.activeTime += incrementBy;
}
});
},
getActiveMachines: () => {
return get().machines.filter((m) => m.isActive);
},
incrementIdleTime: (modelUuid, incrementBy) => {
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: () => {
return get().machines.filter((m) => !m.isActive && m.state === "idle");
},
}))
);
getMachineById: (modelUuid) => {
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[];
}
export const useStorageUnitStore = create<StorageUnitStore>()(
immer((set, get) => ({
storageUnits: [],
export const createStorageUnitStore = () => {
return create<StorageUnitStore>()(
immer((set, get) => ({
storageUnits: [],
addStorageUnit: (productId, storageUnit) => {
set((state) => {
const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid);
if (!exists) {
state.storageUnits.push({
...storageUnit,
productId,
isActive: false,
idleTime: 0,
activeTime: 0,
currentLoad: 0,
currentMaterials: [],
state: 'idle'
});
}
});
},
addStorageUnit: (productId, storageUnit) => {
set((state) => {
const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid);
if (!exists) {
state.storageUnits.push({
...storageUnit,
productId,
isActive: false,
idleTime: 0,
activeTime: 0,
currentLoad: 0,
currentMaterials: [],
state: 'idle'
});
}
});
},
removeStorageUnit: (modelUuid) => {
set((state) => {
state.storageUnits = state.storageUnits.filter(s => s.modelUuid !== modelUuid);
});
},
removeStorageUnit: (modelUuid) => {
set((state) => {
state.storageUnits = state.storageUnits.filter(s => s.modelUuid !== modelUuid);
});
},
updateStorageUnit: (modelUuid, updates) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
Object.assign(unit, updates);
}
});
},
updateStorageUnit: (modelUuid, updates) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
Object.assign(unit, updates);
}
});
},
clearStorageUnits: () => {
set(() => ({
storageUnits: [],
}));
},
clearStorageUnits: () => {
set(() => ({
storageUnits: [],
}));
},
setStorageUnitActive: (modelUuid, isActive) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.isActive = isActive;
}
});
},
setStorageUnitActive: (modelUuid, isActive) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.isActive = isActive;
}
});
},
setStorageUnitState: (modelUuid, newState) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.state = newState;
}
});
},
setStorageUnitState: (modelUuid, newState) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.state = newState;
}
});
},
updateCurrentLoad: (modelUuid, incrementBy) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.currentLoad += incrementBy;
}
});
},
updateCurrentLoad: (modelUuid, incrementBy) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.currentLoad += incrementBy;
}
});
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.activeTime += incrementBy;
}
});
},
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.activeTime += incrementBy;
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.idleTime += incrementBy;
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => {
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
if (unit) {
unit.idleTime += incrementBy;
}
});
},
addCurrentMaterial: (modelUuid, materialType, materialId) => {
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
storage.currentMaterials.push({ materialType, materialId });
}
});
},
addCurrentMaterial: (modelUuid, materialType, materialId) => {
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
storage.currentMaterials.push({ materialType, materialId });
}
});
},
setCurrentMaterials: (modelUuid, materials) => {
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
storage.currentMaterials = materials;
}
});
},
setCurrentMaterials: (modelUuid, materials) => {
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
storage.currentMaterials = materials;
}
});
},
getLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
if (storage.currentMaterials.length > 0) {
const material = storage.currentMaterials[storage.currentMaterials.length - 1];
if (material) {
removedMaterial = { materialId: material.materialId, materialType: material.materialType };
getLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
if (storage.currentMaterials.length > 0) {
const material = storage.currentMaterials[storage.currentMaterials.length - 1];
if (material) {
removedMaterial = { materialId: material.materialId, materialType: material.materialType };
}
}
}
}
});
return removedMaterial;
},
});
return removedMaterial;
},
removeLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
if (storage.currentMaterials.length > 0) {
const material = storage.currentMaterials.pop();
if (material) {
removedMaterial = { materialId: material.materialId, materialType: material.materialType };
removeLastMaterial: (modelUuid) => {
let removedMaterial: { materialId: string; materialType: string; } | undefined;
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
if (storage.currentMaterials.length > 0) {
const material = storage.currentMaterials.pop();
if (material) {
removedMaterial = { materialId: material.materialId, materialType: material.materialType };
}
}
}
}
});
return removedMaterial;
},
});
return removedMaterial;
},
clearCurrentMaterials: (modelUuid) => {
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
storage.currentMaterials = [];
}
});
},
clearCurrentMaterials: (modelUuid) => {
set((state) => {
const storage = state.storageUnits.find((s) => s.modelUuid === modelUuid);
if (storage) {
storage.currentMaterials = [];
}
});
},
getStorageUnitById: (modelUuid) => {
return get().storageUnits.find(s => s.modelUuid === modelUuid);
},
getStorageUnitById: (modelUuid) => {
return get().storageUnits.find(s => s.modelUuid === modelUuid);
},
getStorageUnitsByProduct: (productId) => {
return get().storageUnits.filter(s => s.productId === productId);
},
getStorageUnitsByProduct: (productId) => {
return get().storageUnits.filter(s => s.productId === productId);
},
getStorageUnitsBystate: (state) => {
return get().storageUnits.filter(s => s.state === state);
},
getStorageUnitsBystate: (state) => {
return get().storageUnits.filter(s => s.state === state);
},
getActiveStorageUnits: () => {
return get().storageUnits.filter(s => s.isActive);
},
getActiveStorageUnits: () => {
return get().storageUnits.filter(s => s.isActive);
},
getIdleStorageUnits: () => {
return get().storageUnits.filter(s => !s.isActive && s.state === 'idle');
},
getIdleStorageUnits: () => {
return get().storageUnits.filter(s => !s.isActive && s.state === 'idle');
},
getFullStorageUnits: () => {
return get().storageUnits.filter(
s => s.currentLoad >= s.point.action.storageCapacity
);
},
getFullStorageUnits: () => {
return get().storageUnits.filter(
s => s.currentLoad >= s.point.action.storageCapacity
);
},
getEmptyStorageUnits: () => {
return get().storageUnits.filter(s => s.currentLoad === 0);
},
}))
);
getEmptyStorageUnits: () => {
return get().storageUnits.filter(s => s.currentLoad === 0);
},
}))
)
}
export type StorageUnitStoreType = ReturnType<typeof createStorageUnitStore>;

View File

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