can't connect nodes that are already connected
This commit is contained in:
parent
247cfbab9a
commit
92049b4cd5
2 changed files with 33 additions and 8 deletions
|
@ -190,17 +190,26 @@ var Diagrams = /** @class */ (function () {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (node.pointInInputCircle(this.worldX, this.worldY)) {
|
if (node.pointInInputCircle(this.worldX, this.worldY)) {
|
||||||
this.addConnection(this.makingConnectionNode, node);
|
var connectionExists = false;
|
||||||
|
for (var _b = 0, _c = this.connections; _b < _c.length; _b++) {
|
||||||
|
var _d = _c[_b], output = _d[0], input = _d[1];
|
||||||
|
if (this.makingConnectionNode.id == output.id && node.id == input.id) {
|
||||||
|
connectionExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!connectionExists) {
|
||||||
|
this.addConnection(this.makingConnectionNode, node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.makingConnectionNode = null;
|
this.makingConnectionNode = null;
|
||||||
}
|
}
|
||||||
for (var _b = 0, _c = this.connections; _b < _c.length; _b++) {
|
for (var _e = 0, _f = this.connections; _e < _f.length; _e++) {
|
||||||
var _d = _c[_b], output = _d[0], input = _d[1];
|
var _g = _f[_e], output = _g[0], input = _g[1];
|
||||||
var _e = output.getOutputCircleXY(), outputX = _e[0], outputY = _e[1];
|
var _h = output.getOutputCircleXY(), outputX = _h[0], outputY = _h[1];
|
||||||
outputX += this.cameraX;
|
outputX += this.cameraX;
|
||||||
outputY += this.cameraY;
|
outputY += this.cameraY;
|
||||||
var _f = input.getInputCircleXY(), inputX = _f[0], inputY = _f[1];
|
var _j = input.getInputCircleXY(), inputX = _j[0], inputY = _j[1];
|
||||||
inputX += this.cameraX;
|
inputX += this.cameraX;
|
||||||
inputY += this.cameraY;
|
inputY += this.cameraY;
|
||||||
var dX = Math.abs(outputX - inputX);
|
var dX = Math.abs(outputX - inputX);
|
||||||
|
@ -217,7 +226,8 @@ var Diagrams = /** @class */ (function () {
|
||||||
var halfway = getBezierXY(0.5, outputX, outputY, cp1x, cp1y, cp2x, cp2y, inputX, inputY);
|
var halfway = getBezierXY(0.5, outputX, outputY, cp1x, cp1y, cp2x, cp2y, inputX, inputY);
|
||||||
var mouseOnHalfway = Math.pow(this.mouseX - halfway.x, 2) + Math.pow(this.mouseY - halfway.y, 2) <= 10 * 10;
|
var mouseOnHalfway = Math.pow(this.mouseX - halfway.x, 2) + Math.pow(this.mouseY - halfway.y, 2) <= 10 * 10;
|
||||||
if (mouseOnHalfway) {
|
if (mouseOnHalfway) {
|
||||||
this.connections.splice(this.connections.indexOf([output, input]), 1);
|
this.removeConnection(output, input);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.draw();
|
this.draw();
|
||||||
|
@ -311,6 +321,9 @@ var Diagrams = /** @class */ (function () {
|
||||||
Diagrams.prototype.addConnection = function (A, B) {
|
Diagrams.prototype.addConnection = function (A, B) {
|
||||||
this.connections.push([A, B]);
|
this.connections.push([A, B]);
|
||||||
};
|
};
|
||||||
|
Diagrams.prototype.removeConnection = function (A, B) {
|
||||||
|
this.connections.splice(this.connections.indexOf([A, B]), 1);
|
||||||
|
};
|
||||||
Diagrams.prototype.drawDiagramNode = function (node) {
|
Diagrams.prototype.drawDiagramNode = function (node) {
|
||||||
};
|
};
|
||||||
Diagrams.prototype.fillParent = function () {
|
Diagrams.prototype.fillParent = function () {
|
||||||
|
|
|
@ -226,7 +226,15 @@ class Diagrams {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(node.pointInInputCircle(this.worldX, this.worldY)){
|
if(node.pointInInputCircle(this.worldX, this.worldY)){
|
||||||
this.addConnection(this.makingConnectionNode, node);
|
let connectionExists = false;
|
||||||
|
for (let [output, input] of this.connections) {
|
||||||
|
if (this.makingConnectionNode.id == output.id && node.id == input.id){
|
||||||
|
connectionExists = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!connectionExists){
|
||||||
|
this.addConnection(this.makingConnectionNode, node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.makingConnectionNode = null;
|
this.makingConnectionNode = null;
|
||||||
|
@ -260,7 +268,8 @@ class Diagrams {
|
||||||
let halfway = getBezierXY(0.5, outputX, outputY, cp1x, cp1y, cp2x, cp2y, inputX, inputY)
|
let halfway = getBezierXY(0.5, outputX, outputY, cp1x, cp1y, cp2x, cp2y, inputX, inputY)
|
||||||
let mouseOnHalfway = Math.pow(this.mouseX - halfway.x, 2) + Math.pow(this.mouseY - halfway.y, 2) <= 10*10
|
let mouseOnHalfway = Math.pow(this.mouseX - halfway.x, 2) + Math.pow(this.mouseY - halfway.y, 2) <= 10*10
|
||||||
if (mouseOnHalfway){
|
if (mouseOnHalfway){
|
||||||
this.connections.splice(this.connections.indexOf([output, input]), 1)
|
this.removeConnection(output, input);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,6 +385,9 @@ class Diagrams {
|
||||||
addConnection(A: DiagramNode, B: DiagramNode){
|
addConnection(A: DiagramNode, B: DiagramNode){
|
||||||
this.connections.push([A, B]);
|
this.connections.push([A, B]);
|
||||||
}
|
}
|
||||||
|
removeConnection(A: DiagramNode, B: DiagramNode){
|
||||||
|
this.connections.splice(this.connections.indexOf([A, B]), 1);
|
||||||
|
}
|
||||||
|
|
||||||
drawDiagramNode(node: DiagramNode){
|
drawDiagramNode(node: DiagramNode){
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue