Refactor material handling to include setEndTime in despawn and store actions for improved state management

This commit is contained in:
Jerald-Golden-B 2025-05-13 18:03:57 +05:30
parent db7b4c6f7d
commit b7f74c975c
3 changed files with 6 additions and 3 deletions

View File

@ -2,7 +2,7 @@ import { useCallback } from "react";
import { useMaterialStore } from "../../../../../store/simulation/useMaterialStore"; import { useMaterialStore } from "../../../../../store/simulation/useMaterialStore";
export function useDespawnHandler() { export function useDespawnHandler() {
const { getMaterialById, removeMaterial } = useMaterialStore(); const { getMaterialById, removeMaterial, setEndTime } = useMaterialStore();
const deSpawnLogStatus = (materialUuid: string, status: string) => { const deSpawnLogStatus = (materialUuid: string, status: string) => {
echo.info(`${materialUuid}, ${status}`); echo.info(`${materialUuid}, ${status}`);
@ -14,6 +14,7 @@ export function useDespawnHandler() {
const material = getMaterialById(materialId); const material = getMaterialById(materialId);
if (!material) return; if (!material) return;
setEndTime(material.materialId, performance.now());
removeMaterial(material.materialId); removeMaterial(material.materialId);
deSpawnLogStatus(material.materialName, `Despawned`); deSpawnLogStatus(material.materialName, `Despawned`);

View File

@ -5,7 +5,7 @@ import { useProductStore } from "../../../../../store/simulation/useProductStore
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore"; import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
export function useStoreHandler() { export function useStoreHandler() {
const { getMaterialById, removeMaterial } = useMaterialStore(); const { getMaterialById, removeMaterial, setEndTime } = useMaterialStore();
const { addCurrentMaterial, updateCurrentLoad } = useStorageUnitStore(); const { addCurrentMaterial, updateCurrentLoad } = useStorageUnitStore();
const { getModelUuidByActionUuid } = useProductStore(); const { getModelUuidByActionUuid } = useProductStore();
const { selectedProduct } = useSelectedProduct(); const { selectedProduct } = useSelectedProduct();
@ -23,6 +23,7 @@ export function useStoreHandler() {
const modelUuid = getModelUuidByActionUuid(selectedProduct.productId, action.actionUuid); const modelUuid = getModelUuidByActionUuid(selectedProduct.productId, action.actionUuid);
if (!modelUuid) return; if (!modelUuid) return;
setEndTime(material.materialId, performance.now());
removeMaterial(material.materialId); removeMaterial(material.materialId);
addCurrentMaterial(modelUuid, material.materialType, material.materialId); addCurrentMaterial(modelUuid, material.materialType, material.materialId);
updateCurrentLoad(modelUuid, 1); updateCurrentLoad(modelUuid, 1);

View File

@ -15,7 +15,7 @@ import MaterialAnimator from '../animator/materialAnimator';
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 { removeMaterial } = useMaterialStore(); const { removeMaterial, setEndTime } = useMaterialStore();
const { getStorageUnitById } = useStorageUnitStore(); const { getStorageUnitById } = useStorageUnitStore();
const { triggerPointActions } = useTriggerHandler(); const { triggerPointActions } = useTriggerHandler();
const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore(); const { getActionByUuid, getEventByModelUuid, getTriggerByUuid } = useProductStore();
@ -296,6 +296,7 @@ function VehicleInstance({ agvDetail }: Readonly<{ agvDetail: VehicleStatus }>)
decrementVehicleLoad(agvDetail.modelUuid, 1); decrementVehicleLoad(agvDetail.modelUuid, 1);
const material = removeLastMaterial(agvDetail.modelUuid); const material = removeLastMaterial(agvDetail.modelUuid);
if (material) { if (material) {
setEndTime(material.materialId, performance.now());
removeMaterial(material.materialId); removeMaterial(material.materialId);
} }
if (droppedMat > 0) { if (droppedMat > 0) {