feat: Add human action handling with animation and animated travel capabilities

This commit is contained in:
2025-07-02 15:41:24 +05:30
parent 7519aa90c6
commit 2f0acbda3c
5 changed files with 122 additions and 3 deletions

View File

@@ -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,
};
}

View File

@@ -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,
};
}

View File

@@ -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
};
}

View File

@@ -27,7 +27,7 @@ export function useStorageActions() {
default:
console.warn(`Unknown storage action type: ${action.actionType}`);
}
}, [handleStoreAction]);
}, [handleStoreAction, handleRetrieveAction]);
const cleanup = useCallback(() => {
}, []);

View File

@@ -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 () => {