feat: Enhance conveyor actions and event handling
- 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.
This commit is contained in:
@@ -6,6 +6,7 @@ type MaterialsStore = {
|
||||
|
||||
addMaterial: (material: MaterialSchema) => MaterialSchema | undefined;
|
||||
removeMaterial: (materialId: string) => MaterialSchema | undefined;
|
||||
clearMaterials: () => void;
|
||||
updateMaterial: (materialId: string, updates: Partial<MaterialSchema>) => MaterialSchema | undefined;
|
||||
|
||||
setCurrentLocation: (
|
||||
@@ -35,6 +36,7 @@ type MaterialsStore = {
|
||||
setIsRendered: (materialId: string, isRendered: boolean) => MaterialSchema | undefined;
|
||||
|
||||
getMaterialById: (materialId: string) => MaterialSchema | undefined;
|
||||
getMaterialByCurrentModelUuid: (currentModelUuid: string) => MaterialSchema | undefined;
|
||||
getMaterialsByPoint: (pointUuid: string) => MaterialSchema[];
|
||||
getMaterialsByModel: (modelUuid: string) => MaterialSchema[];
|
||||
};
|
||||
@@ -63,6 +65,12 @@ export const useMaterialStore = create<MaterialsStore>()(
|
||||
return updatedMaterial;
|
||||
},
|
||||
|
||||
clearMaterials: () => {
|
||||
set((state) => {
|
||||
state.materials = [];
|
||||
});
|
||||
},
|
||||
|
||||
updateMaterial: (materialId, updates) => {
|
||||
let updatedMaterial: MaterialSchema | undefined;
|
||||
set((state) => {
|
||||
@@ -186,6 +194,10 @@ export const useMaterialStore = create<MaterialsStore>()(
|
||||
getMaterialById: (materialId) => {
|
||||
return get().materials.find(m => m.materialId === materialId);
|
||||
},
|
||||
|
||||
getMaterialByCurrentModelUuid: (currentModelUuid) => {
|
||||
return get().materials.find(m => m.current?.modelUuid === currentModelUuid);
|
||||
},
|
||||
|
||||
getMaterialsByPoint: (pointUuid) => {
|
||||
return get().materials.filter(m =>
|
||||
|
||||
@@ -61,6 +61,8 @@ type ProductsStore = {
|
||||
// Helper functions
|
||||
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
||||
getEventByModelUuid: (productId: string, modelUuid: 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;
|
||||
getActionByUuid: (productId: string, actionUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
||||
getModelUuidByPointUuid: (productId: string, actionUuid: string) => (string) | undefined;
|
||||
@@ -540,6 +542,53 @@ export const useProductStore = create<ProductsStore>()(
|
||||
return product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
},
|
||||
|
||||
getEventByTriggerUuid: (productId, triggerUuid) => {
|
||||
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?.triggers?.some(t => t.triggerUuid === triggerUuid)) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point) {
|
||||
if (point.action?.triggers?.some((t: any) => t.triggerUuid === triggerUuid)) {
|
||||
return event;
|
||||
}
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if (action.triggers?.some((t: any) => t.triggerUuid === triggerUuid)) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getEventByPointUuid: (productId, pointUuid) => {
|
||||
const product = get().getProductById(productId);
|
||||
if (!product) return undefined;
|
||||
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
if ((event as ConveyorEventSchema).points.some(p => p.uuid === pointUuid)) {
|
||||
return event;
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
if ((event as any).point?.uuid === pointUuid) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getPointByUuid: (productId, modelUuid, pointUuid) => {
|
||||
const event = get().getEventByModelUuid(productId, modelUuid);
|
||||
if (!event) return undefined;
|
||||
|
||||
Reference in New Issue
Block a user