-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interlock.js
61 lines (52 loc) · 1.76 KB
/
Interlock.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
function Interlock(joins, initial) {
this.current = '';
this.last = '';
this.joins = joins
this.initial = initial
if(this.joins instanceof Array) {
console.log('watching joins')
console.log(this.joins)
if(joins.indexOf(this.initial) !== -1) setJoins.call(this, this.initial, 1)
CF.watch(CF.ObjectPressedEvent, this.joins, setJoins.bind(this))
CF.watch(CF.JoinChangeEvent, this.joins, setJoins.bind(this));
}
else if(typeof this.joins === 'object') {
console.log('watching joins')
var joins = Object.keys(this.joins)
console.log(joins)
if(joins.indexOf(this.initial) !== -1) {
console.log('stuff')
objSetJoins.call(this,this.initial, 1)
}
CF.watch(CF.ObjectPressedEvent, joins, objSetJoins.bind(this));
CF.watch(CF.JoinChangeEvent, joins, objSetJoins.bind(this));
}
else
CF.log("Joins need to be specified as an object in the form 'trigger':'result'");
/** set joins for matching input and output */
function setJoins(j, v) {
if(parseInt(v) === 1) {
this.last = this.current
this.current = j
var joinList = this.joins.map(function(join) {
return {join: join, value: 0}
})
CF.setJoins(joinList, false)
CF.setJoin(j, 1, false)
}
}
/** set joins for joins with different inputs and outputs */
function objSetJoins(j, v) {
if(parseInt(v) === 1) {
this.last = this.current
this.current = j
Object.keys(this.joins).map(function(join) {
var joinList = Object.keys(this.joins).map(function(join) {
return {join: this.joins[join], value: 0}
}.bind(this))
CF.setJoins(joinList, false)
CF.setJoin(this.joins[j], 1, false)
}.bind(this))
}
}
}