-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaggerInputPin.js
More file actions
120 lines (105 loc) · 3.25 KB
/
Copy pathDaggerInputPin.js
File metadata and controls
120 lines (105 loc) · 3.25 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'use strict'
const DaggerBasePin = require('./DaggerBasePin.js').DaggerBasePin;
const DaggerTypes= require('./DaggerTypes.js');
/**
* Class that represents a directed input into a DaggerNode
* @extends DaggerBasePin
*/
class DaggerInputPin extends DaggerBasePin {
/**
* DaggerInputPin ctor
*/
constructor() {
super();
this._connectedTo = null;
}
/**
* Get the pin's direction
* @returns {DaggerBasePin.PinDirection.Input}
*/
get direction() {
return DaggerBasePin.PinDirection.Input;
}
/**
* Get the DaggerOutputPin this pin is connected to
* @returns {DaggerOutputPin}
*/
get connectedTo() {
return this._connectedTo;
}
/**
* Get the instance ID of the DaggerOutputPin this pin is connected to.
* @returns {string}
*/
get connectedToUUID() {
if(this.isConnected) {
return this._connectedTo.instanceUUID;
}
// the 'null' uuid
return "00000000-0000-0000-0000-000000000000";
}
/**
* Get if this pin is connected
* @returns {boolean}
*/
get isConnected() {
return (this._connectedTo !== null) ? true : false;
}
/**
* Returns true if this pin can connect to the given DaggerOutputPin
* @param {DaggerOutputPin} pin
*/
canConnectToPin(pin) {
let tsystem = this.topologySystem;
if(tsystem != pin.topologySystem) {
// pins must belong to the same topology system
this.emitError("pins must belong to the same topology system");
return false;
}
if(!this.parentNode) {
// this is an exported or non-node pin, so it can connect to any DaggerOutputPin
return super.canConnectToPin(pin);
}
if(this.parentNode == pin.parentNode) {
// big NO-NO!
this.emitError("pins belong to the same parent node");
return false;
}
let retv = false;
if(this._parentNode.parentGraph.enableTopology) {
if(!this.parentNode.descendents(tsystem).includes(pin.parentNode)) {
retv = super.canConnectToPin(pin);
} else if(pin.parentNode.ordinal(tsystem) <= this.parentNode.ordinal(tsystem)) {
retv = super.canConnectToPin(pin);
}
} else {
retv = true;
}
return retv;
}
/**
* Disconnects this pin.
* @param {boolean} forceDisconnect - when true, the pin will disconnect regardless if the topology says it shouldn't
*/
disconnectPin(forceDisconnect = false) {
if (this._parentNode === null)
return false;
// is it even connected?
if (this.isConnected) {
// call the OutputPin's Disconnect method
return this.connectedTo.disconnectPin(this, forceDisconnect);
}
// since we were never connected to this pin, they are technically disconnected
return true;
}
/**
* Clean up when object hierarchy is unraveled. Subclasses should always super.
*/
purgeAll() {
super.purgeAll();
this._connectedTo = null;
}
}
module.exports = {
DaggerInputPin: DaggerInputPin
};