Enhance RoboticArmInstance and useTriggerHandler: add action handling for pickup and drop triggers, improve event retrieval with getEventByActionUuid, and streamline material location management in storage units.
This commit is contained in:
parent
f2a2811af7
commit
a37faf7adb
|
@ -30,7 +30,7 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
|||
const { decrementVehicleLoad, removeLastMaterial } = useVehicleStore();
|
||||
const { setIsVisible, getMaterialById } = useMaterialStore();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
const { getActionByUuid, getEventByModelUuid } = useProductStore();
|
||||
const { getActionByUuid, getEventByActionUuid, getEventByModelUuid } = useProductStore();
|
||||
const { triggerPointActions } = useTriggerHandler();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { isReset } = useResetButtonStore();
|
||||
|
@ -43,20 +43,20 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
|||
|
||||
const action = getActionByUuid(selectedProduct.productId, armBot.currentAction?.actionUuid || '');
|
||||
|
||||
const handleTrigger = () => {
|
||||
const handlePickUpTrigger = () => {
|
||||
if (armBot.currentAction && armBot.currentAction.materialId) {
|
||||
const material = getMaterialById(armBot.currentAction.materialId);
|
||||
if (material && material.previous && material.previous.modelUuid) {
|
||||
const model = getEventByModelUuid(selectedProduct.productId, material.previous.modelUuid);
|
||||
if (model) {
|
||||
if (model.type === 'transfer') {
|
||||
const previousModel = getEventByActionUuid(selectedProduct.productId, material.previous.actionUuid);
|
||||
if (previousModel) {
|
||||
if (previousModel.type === 'transfer') {
|
||||
setIsVisible(armBot.currentAction.materialId, false);
|
||||
} else if (model.type === 'machine') {
|
||||
} else if (previousModel.type === 'machine') {
|
||||
// machine specific logic
|
||||
} else if (model.type === 'vehicle') {
|
||||
decrementVehicleLoad(model.modelUuid, 1);
|
||||
removeLastMaterial(model.modelUuid);
|
||||
} else if (model.type === 'storageUnit') {
|
||||
} else if (previousModel.type === 'vehicle') {
|
||||
decrementVehicleLoad(previousModel.modelUuid, 1);
|
||||
removeLastMaterial(previousModel.modelUuid);
|
||||
} else if (previousModel.type === 'storageUnit') {
|
||||
// storage unit logic
|
||||
}
|
||||
} else {
|
||||
|
@ -68,6 +68,30 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
|||
}
|
||||
}
|
||||
|
||||
const handleDropTrigger = () => {
|
||||
|
||||
if (armBot.currentAction) {
|
||||
const action = getActionByUuid(selectedProduct.productId, armBot.currentAction.actionUuid);
|
||||
if (action && action.triggers[0].triggeredAsset?.triggeredModel.modelUuid) {
|
||||
const model = getEventByModelUuid(selectedProduct.productId, action?.triggers[0].triggeredAsset?.triggeredModel.modelUuid);
|
||||
if (!model) return;
|
||||
if (model.type === 'transfer') {
|
||||
setIsVisible(armBot.currentAction.materialId || '', true);
|
||||
} else if (model.type === 'machine') {
|
||||
//
|
||||
} else if (model.type === 'vehicle') {
|
||||
//
|
||||
} else if (model.type === 'storageUnit') {
|
||||
//
|
||||
}
|
||||
}
|
||||
if (action && armBot.currentAction.materialId) {
|
||||
triggerPointActions(action, armBot.currentAction.materialId)
|
||||
removeCurrentAction(armBot.modelUuid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function step() {
|
||||
if (isPausedRef.current) {
|
||||
if (!pauseTimeRef.current) {
|
||||
|
@ -103,7 +127,7 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
|||
logStatus(armBot.modelUuid, "picking the object");
|
||||
setPath(curve.points.map(point => [point.x, point.y, point.z]))
|
||||
|
||||
handleTrigger();
|
||||
handlePickUpTrigger();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -122,17 +146,8 @@ function RoboticArmInstance({ armBot }: { armBot: ArmBotStatus }) {
|
|||
logStatus(armBot.modelUuid, "dropping the object");
|
||||
setPath(curve.points.map(point => [point.x, point.y, point.z]));
|
||||
|
||||
if (armBot.currentAction) {
|
||||
setIsVisible(armBot.currentAction.materialId || '', true);
|
||||
}
|
||||
handleDropTrigger();
|
||||
|
||||
if (armBot.currentAction) {
|
||||
const action = getActionByUuid(selectedProduct.productId, armBot.currentAction.actionUuid);
|
||||
if (action && armBot.currentAction.materialId) {
|
||||
triggerPointActions(action, armBot.currentAction.materialId)
|
||||
removeCurrentAction(armBot.modelUuid)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logStatus(armBot.modelUuid, "Moving armBot from end point to rest position.")
|
||||
|
|
|
@ -517,7 +517,43 @@ export function useTriggerHandler() {
|
|||
|
||||
} else if (toEvent?.type === 'storageUnit') {
|
||||
// Robotic Arm to Storage Unit
|
||||
if (materialId && trigger.triggeredAsset && trigger.triggeredAsset.triggeredPoint && trigger.triggeredAsset.triggeredAction) {
|
||||
const material = getMaterialById(materialId);
|
||||
if (material) {
|
||||
const action = getActionByUuid(selectedProduct.productId, trigger.triggeredAsset.triggeredAction.actionUuid);
|
||||
const storageUnit = getStorageUnitById(trigger.triggeredAsset?.triggeredModel.modelUuid);
|
||||
|
||||
setPreviousLocation(material.materialId, {
|
||||
modelUuid: material.current.modelUuid,
|
||||
pointUuid: material.current.pointUuid,
|
||||
actionUuid: material.current.actionUuid,
|
||||
})
|
||||
|
||||
setCurrentLocation(material.materialId, {
|
||||
modelUuid: trigger.triggeredAsset.triggeredModel.modelUuid,
|
||||
pointUuid: trigger.triggeredAsset.triggeredPoint.pointUuid,
|
||||
actionUuid: trigger.triggeredAsset?.triggeredAction?.actionUuid,
|
||||
});
|
||||
|
||||
setNextLocation(material.materialId, null);
|
||||
|
||||
setIsVisible(materialId, false);
|
||||
|
||||
if (action && storageUnit) {
|
||||
|
||||
if (storageUnit.currentLoad < storageUnit.point.action.storageCapacity) {
|
||||
|
||||
// Handle current action from vehicle
|
||||
handleAction(action, materialId);
|
||||
|
||||
} else {
|
||||
|
||||
// Event Manager Needed
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (fromEvent?.type === 'storageUnit') {
|
||||
if (toEvent?.type === 'transfer') {
|
||||
|
|
|
@ -61,6 +61,7 @@ type ProductsStore = {
|
|||
// Helper functions
|
||||
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
||||
getEventByModelUuid: (productId: string, modelUuid: string) => EventsSchema | undefined;
|
||||
getEventByActionUuid: (productId: string, actionUuid: string) => EventsSchema | undefined;
|
||||
getEventByTriggerUuid: (productId: string, triggerUuid: string) => EventsSchema | undefined;
|
||||
getEventByPointUuid: (productId: string, pointUuid: string) => EventsSchema | undefined;
|
||||
getPointByUuid: (productId: string, modelUuid: string, pointUuid: string) => ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
||||
|
@ -543,6 +544,32 @@ export const useProductStore = create<ProductsStore>()(
|
|||
return product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
},
|
||||
|
||||
getEventByActionUuid: (productId, actionUuid) => {
|
||||
const product = get().getProductById(productId);
|
||||
if (!product) return undefined;
|
||||
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action?.actionUuid === actionUuid) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action?.actionUuid === actionUuid) {
|
||||
return event;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getEventByTriggerUuid: (productId, triggerUuid) => {
|
||||
const product = get().getProductById(productId);
|
||||
if (!product) return undefined;
|
||||
|
|
Loading…
Reference in New Issue