-
Notifications
You must be signed in to change notification settings - Fork 2
/
Graph.js
72 lines (52 loc) · 1.67 KB
/
Graph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module.declare("Graph", [
"Utilities/Eventable"
], function () {
var Eventable = module.require("Utilities/Eventable");
var Graph = {};
Graph.Node = (function () {
function Node () {
// override
this.inputs = {};
this.outputs = {};
}
Node.prototype.getInputKeys = function () {
return Object.keys(this.inputs);
};
Node.prototype.getOutputKeys = function () {
return Object.keys(this.outputs);
};
Node.prototype.getInput = function (input_name) {
return this.inputs[input_name];
};
Node.prototype.getOutput = function (output_name) {
return this.outputs[output_name];
};
return Node;
})();
Graph.IOInterface = (function () {
function IOInterface () {
Eventable(this);
this.connections = [];
}
IOInterface.prototype.getConnections = function () {
return this.connections;
};
IOInterface.prototype.connectTo = function (other_iointerface) {
if (this.connections.indexOf(other_iointerface) != -1) {
console.warn("Graph.IOInterface(.connectTo): Attempted redundant connection.");
return;
}
this.connections.push(other_iointerface);
this.launchEvent("connect", other_iointerface);
};
IOInterface.prototype.disconnectTo = function (other_iointerface) {
if (this.connections.indexOf(other_iointerface) == -1) {
throw new Error("Graph.IOInterface(.disconnectTo): No such connected IOInterface.");
}
this.connections.splice(this.connections.indexOf(other_iointerface), 1);
this.launchEvent("disconnect", other_iointerface);
};
return IOInterface;
})();
return Graph;
});