diff --git a/app/src/modules/simulation/actions/human/actionHandler/useAnimatedTravelHandler.ts b/app/src/modules/simulation/actions/human/actionHandler/useAnimatedTravelHandler.ts new file mode 100644 index 0000000..d347f03 --- /dev/null +++ b/app/src/modules/simulation/actions/human/actionHandler/useAnimatedTravelHandler.ts @@ -0,0 +1,34 @@ +import { useCallback } from "react"; +import { useSceneContext } from "../../../../scene/sceneContext"; +import { useProductContext } from "../../../products/productContext"; + +export function useAnimatedTravelHandler() { + const { materialStore, humanStore, productStore } = useSceneContext(); + const { getMaterialById } = materialStore(); + const { } = humanStore(); + const { getModelUuidByActionUuid } = productStore(); + const { selectedProductStore } = useProductContext(); + const { selectedProduct } = selectedProductStore(); + + const animatedTravelLogStatus = (materialUuid: string, status: string) => { + echo.info(`${materialUuid}, ${status}`); + } + + const handleAnimatedTravel = useCallback((action: HumanAction, materialId?: string) => { + if (!action || action.actionType !== 'animatedTravel' || !materialId) return; + + const material = getMaterialById(materialId); + if (!material) return; + + const modelUuid = getModelUuidByActionUuid(selectedProduct.productUuid, action.actionUuid); + if (!modelUuid) return; + + + animatedTravelLogStatus(material.materialName, `performing animatedTravel`); + + }, [getMaterialById]); + + return { + handleAnimatedTravel, + }; +} \ No newline at end of file diff --git a/app/src/modules/simulation/actions/human/actionHandler/useAnimationHandler.ts b/app/src/modules/simulation/actions/human/actionHandler/useAnimationHandler.ts new file mode 100644 index 0000000..eb0ed6a --- /dev/null +++ b/app/src/modules/simulation/actions/human/actionHandler/useAnimationHandler.ts @@ -0,0 +1,34 @@ +import { useCallback } from "react"; +import { useSceneContext } from "../../../../scene/sceneContext"; +import { useProductContext } from "../../../products/productContext"; + +export function useAnimationHandler() { + const { materialStore, humanStore, productStore } = useSceneContext(); + const { getMaterialById } = materialStore(); + const { } = humanStore(); + const { getModelUuidByActionUuid } = productStore(); + const { selectedProductStore } = useProductContext(); + const { selectedProduct } = selectedProductStore(); + + const animationLogStatus = (materialUuid: string, status: string) => { + echo.info(`${materialUuid}, ${status}`); + } + + const handleAnimation = useCallback((action: HumanAction, materialId?: string) => { + if (!action || action.actionType !== 'animation' || !materialId) return; + + const material = getMaterialById(materialId); + if (!material) return; + + const modelUuid = getModelUuidByActionUuid(selectedProduct.productUuid, action.actionUuid); + if (!modelUuid) return; + + + animationLogStatus(material.materialName, `performing animation`); + + }, [getMaterialById]); + + return { + handleAnimation, + }; +} \ No newline at end of file diff --git a/app/src/modules/simulation/actions/human/useHumanActions.ts b/app/src/modules/simulation/actions/human/useHumanActions.ts new file mode 100644 index 0000000..b355ff6 --- /dev/null +++ b/app/src/modules/simulation/actions/human/useHumanActions.ts @@ -0,0 +1,45 @@ +import { useEffect, useCallback } from 'react'; +import { useAnimationHandler } from './actionHandler/useAnimationHandler'; +import { useAnimatedTravelHandler } from './actionHandler/useAnimatedTravelHandler'; + +export function useHumanActions() { + const { handleAnimation } = useAnimationHandler(); + const { handleAnimatedTravel } = useAnimatedTravelHandler(); + + const handleAnimationAction = useCallback((action: HumanAction, materialId: string) => { + handleAnimation(action, materialId); + }, [handleAnimation]); + + const handleAnimatedTravelAction = useCallback((action: HumanAction) => { + handleAnimatedTravel(action); + }, [handleAnimatedTravel]); + + const handleHumanAction = useCallback((action: HumanAction, materialId: string) => { + if (!action) return; + + switch (action.actionType) { + case 'animation': + handleAnimationAction(action, materialId); + break; + case 'animatedTravel': + handleAnimatedTravelAction(action); + break; + default: + console.warn(`Unknown Human action type: ${action.actionType}`); + } + }, [handleAnimationAction, handleAnimatedTravelAction]); + + const cleanup = useCallback(() => { + }, []); + + useEffect(() => { + return () => { + cleanup(); + }; + }, [cleanup]); + + return { + handleHumanAction, + cleanup + }; +} \ No newline at end of file diff --git a/app/src/modules/simulation/actions/storageUnit/useStorageUnitActions.ts b/app/src/modules/simulation/actions/storageUnit/useStorageUnitActions.ts index 6f5fb19..151ca20 100644 --- a/app/src/modules/simulation/actions/storageUnit/useStorageUnitActions.ts +++ b/app/src/modules/simulation/actions/storageUnit/useStorageUnitActions.ts @@ -27,7 +27,7 @@ export function useStorageActions() { default: console.warn(`Unknown storage action type: ${action.actionType}`); } - }, [handleStoreAction]); + }, [handleStoreAction, handleRetrieveAction]); const cleanup = useCallback(() => { }, []); diff --git a/app/src/modules/simulation/actions/useActionHandler.ts b/app/src/modules/simulation/actions/useActionHandler.ts index 23f2712..099e200 100644 --- a/app/src/modules/simulation/actions/useActionHandler.ts +++ b/app/src/modules/simulation/actions/useActionHandler.ts @@ -7,6 +7,7 @@ import { useMachineActions } from "./machine/useMachineActions"; import { useRoboticArmActions } from "./roboticArm/useRoboticArmActions"; import { useStorageActions } from "./storageUnit/useStorageUnitActions"; import { useVehicleActions } from "./vehicle/useVehicleActions"; +import { useHumanActions } from "./human/useHumanActions"; import { useCallback, useEffect } from "react"; export function useActionHandler() { @@ -17,6 +18,7 @@ export function useActionHandler() { const { handleRoboticArmAction, cleanup: cleanupRoboticArm } = useRoboticArmActions(); const { handleMachineAction, cleanup: cleanupMachine } = useMachineActions(); const { handleStorageAction, cleanup: cleanupStorage } = useStorageActions(); + const { handleHumanAction, cleanup: cleanupHuman } = useHumanActions(); const handleAction = useCallback((action: Action, materialId?: string) => { if (!action) return; @@ -37,6 +39,9 @@ export function useActionHandler() { case 'store': case 'retrieve': handleStorageAction(action as StorageAction, materialId as string); break; + case 'animation': case 'animatedTravel': + handleHumanAction(action as HumanAction, materialId as string); + break; default: console.warn(`Unknown action type: ${(action as Action).actionType}`); } @@ -44,7 +49,7 @@ export function useActionHandler() { echo.error("Failed to handle action"); console.error("Error handling action:", error); } - }, [handleConveyorAction, handleVehicleAction, handleRoboticArmAction, handleMachineAction, handleStorageAction,]); + }, [handleConveyorAction, handleVehicleAction, handleRoboticArmAction, handleMachineAction, handleStorageAction, handleHumanAction]); const cleanup = useCallback(() => { cleanupConveyor(); @@ -52,7 +57,8 @@ export function useActionHandler() { cleanupRoboticArm(); cleanupMachine(); cleanupStorage(); - }, [cleanupConveyor, cleanupVehicle, cleanupRoboticArm, cleanupMachine, cleanupStorage,]); + cleanupHuman(); + }, [cleanupConveyor, cleanupVehicle, cleanupRoboticArm, cleanupMachine, cleanupStorage, cleanupHuman]); useEffect(() => { return () => {