- Added detailed logging for default conveyor actions in useConveyorActions. - Integrated play and reset button states into useActionHandler for better control flow. - Updated PointsCreator to conditionally render based on play state and improved event handling. - Modified MaterialAnimator to support pause and resume functionality based on play state. - Enhanced MaterialInstance to trigger actions upon animation completion. - Implemented material clearing logic in Materials component on reset or stop. - Updated Simulator to respect play and reset states during action handling. - Improved trigger handling logic to accommodate new event retrieval methods. - Added utility functions in useProductStore for fetching events by trigger and point UUIDs. - Created a new file for default action handling in conveyor actions.
64 lines
2.6 KiB
TypeScript
64 lines
2.6 KiB
TypeScript
import { usePlayButtonStore, useResetButtonStore } from "../../../store/usePlayButtonStore";
|
|
import { useConveyorActions } from "./conveyor/useConveyorActions";
|
|
import { useMachineActions } from "./machine/useMachineActions";
|
|
import { useRoboticArmActions } from "./roboticArm/useRoboticArmActions";
|
|
import { useStorageActions } from "./storageUnit/useStorageUnitActions";
|
|
import { useVehicleActions } from "./vehicle/useVehicleActions";
|
|
import { useCallback, useEffect } from "react";
|
|
|
|
export function useActionHandler() {
|
|
const { isReset } = useResetButtonStore();
|
|
const { isPlaying } = usePlayButtonStore();
|
|
const { handleConveyorAction, cleanup: cleanupConveyor } = useConveyorActions();
|
|
const { handleVehicleAction, cleanup: cleanupVehicle } = useVehicleActions();
|
|
const { handleRoboticArmAction, cleanup: cleanupRoboticArm } = useRoboticArmActions();
|
|
const { handleMachineAction, cleanup: cleanupMachine } = useMachineActions();
|
|
const { handleStorageAction, cleanup: cleanupStorage } = useStorageActions();
|
|
|
|
const handleAction = useCallback((action: Action) => {
|
|
if (!action) return;
|
|
|
|
try {
|
|
switch (action.actionType) {
|
|
case 'default': case 'spawn': case 'swap': case 'delay': case 'despawn':
|
|
handleConveyorAction(action as ConveyorAction);
|
|
break;
|
|
case 'travel':
|
|
handleVehicleAction(action as VehicleAction);
|
|
break;
|
|
case 'pickAndPlace':
|
|
handleRoboticArmAction(action as RoboticArmAction);
|
|
break;
|
|
case 'process':
|
|
handleMachineAction(action as MachineAction);
|
|
break;
|
|
case 'store':
|
|
handleStorageAction(action as StorageAction);
|
|
break;
|
|
default:
|
|
console.warn(`Unknown action type: ${(action as Action).actionType}`);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error handling action:', error);
|
|
}
|
|
}, [handleConveyorAction, handleVehicleAction, handleRoboticArmAction, handleMachineAction, handleStorageAction]);
|
|
|
|
const cleanup = useCallback(() => {
|
|
cleanupConveyor();
|
|
cleanupVehicle();
|
|
cleanupRoboticArm();
|
|
cleanupMachine();
|
|
cleanupStorage();
|
|
}, [cleanupConveyor, cleanupVehicle, cleanupRoboticArm, cleanupMachine, cleanupStorage]);
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
cleanup();
|
|
};
|
|
}, [cleanup, isReset, isPlaying]);
|
|
|
|
return {
|
|
handleAction,
|
|
cleanup
|
|
};
|
|
} |