-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp.js
63 lines (54 loc) · 1.32 KB
/
p.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
class Pin extends Vector {
constructor(x,y,component,type,label='') {
super(x,y);
this.origin = vector(x,y);
this.orientation = type === 'output' ? 'right' : 'left';
this.connectionGroup = null;
this.component = component;
this.state = 0;
this.inverted = false;
this.type = type;
this.driving = false;
this.label = label;
this.bubble = true;
}
queue(state,drive) {
updateQueue.push([this,state,drive]);
}
update(state,drive) {
if (typeof drive === 'undefined') {
this.driving = state !== null && this.type !== 'input';
} else {
this.driving = drive;
}
this.state = state >>> 0;
this.connectionGroup.update(this);
}
remove() {
this.component.pins.removePin(this);
}
}
class Pins extends Array {
constructor() {
super();
}
removeInputs() {
this.splice(0, this.length, ...this.filter(pin => pin.type !== 'input'));
}
removeOutputs() {
this.splice(0, this.length, ...this.filter(pin => pin.type !== 'output'));
}
removePin(pin) {
var index = this.indexOf(pin);
if (index > -1) this.splice(index,1);
}
clearAll() {
this.length = 0;
}
get inputs() {
return this.filter(pin => ['input','dual'].includes(pin.type));
}
get outputs() {
return this.filter(pin => pin.type === 'output');
}
}