feat: Refactor human action handling to replace animatedTravel with worker actions and enhance animation management

This commit is contained in:
2025-07-03 14:23:57 +05:30
parent 98f4d48db2
commit eb5683eadc
11 changed files with 606 additions and 112 deletions

View File

@@ -2,7 +2,7 @@ import { useCallback } from "react";
import { useSceneContext } from "../../../../scene/sceneContext";
import { useProductContext } from "../../../products/productContext";
export function useAnimatedTravelHandler() {
export function useWorkerHandler() {
const { materialStore, humanStore, productStore } = useSceneContext();
const { getMaterialById } = materialStore();
const { } = humanStore();
@@ -10,12 +10,12 @@ export function useAnimatedTravelHandler() {
const { selectedProductStore } = useProductContext();
const { selectedProduct } = selectedProductStore();
const animatedTravelLogStatus = (materialUuid: string, status: string) => {
const workerLogStatus = (materialUuid: string, status: string) => {
echo.info(`${materialUuid}, ${status}`);
}
const handleAnimatedTravel = useCallback((action: HumanAction, materialId?: string) => {
if (!action || action.actionType !== 'animatedTravel' || !materialId) return;
const handleWorker = useCallback((action: HumanAction, materialId?: string) => {
if (!action || action.actionType !== 'worker' || !materialId) return;
const material = getMaterialById(materialId);
if (!material) return;
@@ -24,11 +24,11 @@ export function useAnimatedTravelHandler() {
if (!modelUuid) return;
animatedTravelLogStatus(material.materialName, `performing animatedTravel`);
workerLogStatus(material.materialName, `performing worker action`);
}, [getMaterialById]);
return {
handleAnimatedTravel,
handleWorker,
};
}

View File

@@ -1,24 +1,24 @@
import { useEffect, useCallback } from 'react';
import { useAnimatedTravelHandler } from './actionHandler/useAnimatedTravelHandler';
import { useWorkerHandler } from './actionHandler/useWorkerHandler';
export function useHumanActions() {
const { handleAnimatedTravel } = useAnimatedTravelHandler();
const { handleWorker } = useWorkerHandler();
const handleAnimatedTravelAction = useCallback((action: HumanAction) => {
handleAnimatedTravel(action);
}, [handleAnimatedTravel]);
const handleWorkerAction = useCallback((action: HumanAction) => {
handleWorker(action);
}, [handleWorker]);
const handleHumanAction = useCallback((action: HumanAction, materialId: string) => {
if (!action) return;
switch (action.actionType) {
case 'animatedTravel':
handleAnimatedTravelAction(action);
case 'worker':
handleWorkerAction(action);
break;
default:
console.warn(`Unknown Human action type: ${action.actionType}`);
}
}, [handleAnimatedTravelAction]);
}, [handleWorkerAction]);
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 'animatedTravel':
case 'worker':
handleHumanAction(action as HumanAction, materialId as string);
break;
default:

View File

@@ -155,8 +155,8 @@ function TriggerConnector() {
// Handle Human point
else if (event.type === "human" && 'point' in event) {
const point = event.point;
if (point.action?.triggers) {
point.action.triggers.forEach(trigger => {
point.actions?.forEach(action => {
action.triggers?.forEach(trigger => {
if (trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint) {
newConnections.push({
id: `${point.uuid}-${trigger.triggeredAsset.triggeredPoint.pointUuid}-${trigger.triggerUuid}`,
@@ -166,7 +166,7 @@ function TriggerConnector() {
});
}
});
}
});
}
});