diff --git a/src/editor/js/structures/graph/graph.ts b/src/editor/js/structures/graph/graph.ts index ebf36c2020c337a9f32aae697b6034ace8c660ca..b6d42d32301a1f1aac63870dfac77f3190da84d7 100644 --- a/src/editor/js/structures/graph/graph.ts +++ b/src/editor/js/structures/graph/graph.ts @@ -295,6 +295,21 @@ export class Graph extends ManagedData { return true; } + getLink(sourceId: number, targetId: number, directionSensitive = true): Link { + return this.links.find((l) => { + if (l.sourceId === sourceId && l.targetId === targetId) { + return true; + } + + // Check other direction if allowed + if (!directionSensitive && (l.sourceId === targetId && l.targetId === sourceId)) { + return true; + } + + return false; + }); + } + getNode(id: number): Node { return this.getElementWithId(this.nodes, id); } @@ -318,7 +333,7 @@ export class Graph extends ManagedData { * @returns True, if successful. */ public addLink(link: Link): boolean { - if (this.data.links.includes(link)) { + if (this.getLink(link.sourceId, link.targetId, false) !== undefined) { return true; // Already exists in graph. }