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";
export function useDespawnHandler() {
const { getMaterialById, removeMaterial } = useMaterialStore();
const { getMaterialById, removeMaterial, setEndTime } = useMaterialStore();
const deSpawnLogStatus = (materialUuid: string, status: string) => {
echo.info(`${materialUuid}, ${status}`);
@ -14,6 +14,7 @@ export function useDespawnHandler() {
const material = getMaterialById(materialId);
if (!material) return;
setEndTime(material.materialId, performance.now());
removeMaterial(material.materialId);
deSpawnLogStatus(material.materialName, `Despawned`);

View File

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

View File

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