-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimal.js
60 lines (50 loc) · 1.52 KB
/
Animal.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
// this works fine but eslint complains for some reason??
const Osc = require('node-osc'); // eslint-disable-line import/no-unresolved
const { OSC_ADDRESS, OSC_PORT } = process.env;
const Resolume = new Osc.Client(OSC_ADDRESS, OSC_PORT);
const {
SparrowAnimation, RatAnimation,
RaccoonAnimation, PigeonAnimation,
FalconAnimation,
} = require('./AnimalAnimations');
const Electrode = require('./Electrode');
let allBlocked = false;
class Animal {
constructor(resolume, animation, index) {
this.resolume = resolume;
this.animation = animation;
this.electrode = new Electrode(
index,
() => this.OnTouch(),
);
this.blocked = false;
}
OnTouch() {
if ((!this.blocked) && (!allBlocked)) this.Play();
}
TriggerLoop() {
if ((!this.blocked) && (!allBlocked)) this.Loop();
}
Update(data) {
this.electrode.Update(data);
}
Play() {
this.animation.Play(
this.resolume,
(time) => {
this.blocked = true;
allBlocked = true;
setTimeout(() => { this.blocked = false; }, 1000 * time);
setTimeout(() => { allBlocked = false; }, 3000);
},
);
}
Loop() {
this.animation.Loop(this.resolume, () => {});
}
}
module.exports.Sparrow = new Animal(Resolume, SparrowAnimation, 5);
module.exports.Rat = new Animal(Resolume, RatAnimation, 1);
module.exports.Raccoon = new Animal(Resolume, RaccoonAnimation, 2);
module.exports.Pigeon = new Animal(Resolume, PigeonAnimation, 4);
module.exports.Falcon = new Animal(Resolume, FalconAnimation, 3);