Refactor TriggerConnector to improve event handling: reset firstSelectedPoint on invalid intersections, update event model name, and ensure proper cleanup of state. Adjust event listener conditions for better performance.
This commit is contained in:
parent
01a03f5166
commit
a3b48d12c1
|
@ -171,10 +171,16 @@ function TriggerConnector() {
|
||||||
(intersect) =>
|
(intersect) =>
|
||||||
intersect.object.name === ('Event-Sphere')
|
intersect.object.name === ('Event-Sphere')
|
||||||
);
|
);
|
||||||
if (intersects.length === 0) return;
|
if (intersects.length === 0) {
|
||||||
|
setFirstSelectedPoint(null);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
const currentObject = intersects[0].object;
|
const currentObject = intersects[0].object;
|
||||||
if (!currentObject || currentObject.name !== 'Event-Sphere') return;
|
if (!currentObject || currentObject.name !== 'Event-Sphere') {
|
||||||
|
setFirstSelectedPoint(null);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
const modelUuid = currentObject.userData.modelUuid;
|
const modelUuid = currentObject.userData.modelUuid;
|
||||||
const pointUuid = currentObject.userData.pointUuid;
|
const pointUuid = currentObject.userData.pointUuid;
|
||||||
|
@ -189,7 +195,10 @@ function TriggerConnector() {
|
||||||
|
|
||||||
const event = getEventByModelUuid(selectedProduct.productId, modelUuid);
|
const event = getEventByModelUuid(selectedProduct.productId, modelUuid);
|
||||||
|
|
||||||
if (!point || !event) return;
|
if (!point || !event) {
|
||||||
|
setFirstSelectedPoint(null);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let actionUuid: string | undefined;
|
let actionUuid: string | undefined;
|
||||||
if ('action' in point && point.action) {
|
if ('action' in point && point.action) {
|
||||||
|
@ -254,7 +263,12 @@ function TriggerConnector() {
|
||||||
pointUuid
|
pointUuid
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!point) return;
|
const event = getEventByModelUuid(selectedProduct.productId, modelUuid);
|
||||||
|
|
||||||
|
if (!point || !event) {
|
||||||
|
setFirstSelectedPoint(null);
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let actionUuid: string | undefined;
|
let actionUuid: string | undefined;
|
||||||
if ('action' in point && point.action) {
|
if ('action' in point && point.action) {
|
||||||
|
@ -270,12 +284,12 @@ function TriggerConnector() {
|
||||||
delay: 0,
|
delay: 0,
|
||||||
triggeredAsset: {
|
triggeredAsset: {
|
||||||
triggeredModel: {
|
triggeredModel: {
|
||||||
modelName: currentObject.parent?.parent?.name || 'Unknown',
|
modelName: event.modelName || 'Unknown',
|
||||||
modelUuid: modelUuid
|
modelUuid: modelUuid
|
||||||
},
|
},
|
||||||
triggeredPoint: {
|
triggeredPoint: {
|
||||||
pointName: currentObject.name,
|
pointName: 'Point',
|
||||||
pointUuid: pointUuid
|
pointUuid: point.uuid
|
||||||
},
|
},
|
||||||
triggeredAction: actionUuid ? {
|
triggeredAction: actionUuid ? {
|
||||||
actionName: getActionByUuid(selectedProduct.productId, actionUuid)?.actionName || 'Action',
|
actionName: getActionByUuid(selectedProduct.productId, actionUuid)?.actionName || 'Action',
|
||||||
|
@ -285,13 +299,24 @@ function TriggerConnector() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (firstSelectedPoint.actionUuid) {
|
if (firstSelectedPoint.actionUuid) {
|
||||||
addTrigger(selectedProduct.productId, firstSelectedPoint.actionUuid, trigger);
|
const event = addTrigger(selectedProduct.productId, firstSelectedPoint.actionUuid, trigger);
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
updateBackend(
|
||||||
|
selectedProduct.productName,
|
||||||
|
selectedProduct.productId,
|
||||||
|
organization,
|
||||||
|
event
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
setFirstSelectedPoint(null);
|
||||||
|
} else if (firstSelectedPoint) {
|
||||||
setFirstSelectedPoint(null);
|
setFirstSelectedPoint(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (subModule === 'simulations') {
|
if (subModule === 'simulations' && !deleteTool) {
|
||||||
canvasElement.addEventListener("mousedown", onMouseDown);
|
canvasElement.addEventListener("mousedown", onMouseDown);
|
||||||
canvasElement.addEventListener("mouseup", onMouseUp);
|
canvasElement.addEventListener("mouseup", onMouseUp);
|
||||||
canvasElement.addEventListener("mousemove", onMouseMove);
|
canvasElement.addEventListener("mousemove", onMouseMove);
|
||||||
|
@ -305,7 +330,7 @@ function TriggerConnector() {
|
||||||
canvasElement.removeEventListener('contextmenu', handleRightClick);
|
canvasElement.removeEventListener('contextmenu', handleRightClick);
|
||||||
};
|
};
|
||||||
|
|
||||||
}, [gl, subModule, selectedProduct, firstSelectedPoint]);
|
}, [gl, subModule, selectedProduct, firstSelectedPoint, deleteTool]);
|
||||||
|
|
||||||
|
|
||||||
useFrame(() => {
|
useFrame(() => {
|
||||||
|
|
Loading…
Reference in New Issue