feat: Refactor human action handling to support animated travel and streamline action structure

This commit is contained in:
2025-07-03 12:11:58 +05:30
parent b5c69f3335
commit 98f4d48db2
10 changed files with 75 additions and 282 deletions

View File

@@ -1,34 +0,0 @@
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

@@ -1,15 +1,9 @@
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]);
@@ -18,16 +12,13 @@ export function useHumanActions() {
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]);
}, [handleAnimatedTravelAction]);
const cleanup = useCallback(() => {
}, []);

View File

@@ -39,7 +39,7 @@ export function useActionHandler() {
case 'store': case 'retrieve':
handleStorageAction(action as StorageAction, materialId as string);
break;
case 'animation': case 'animatedTravel':
case 'animatedTravel':
handleHumanAction(action as HumanAction, materialId as string);
break;
default: