-
Notifications
You must be signed in to change notification settings - Fork 0
/
System.js
64 lines (54 loc) · 1.44 KB
/
System.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
class System {
constructor(name = '', operates_on_list = [])
{
this.name = name;
this.operates_on = operates_on_list;
this.subscribed_to = [];
this.paused = false;
}
subscribe(entity_uid)
{
// todo: in theory I could check the entity against the operates_on list for this system to make sure
// it's an entity that this system can handle; the ECSManager *should* have done this already, though
if (this.subscribed_to.includes(entity_uid) === false) {
this.subscribed_to.push(entity_uid);
return true;
} else {
return false;
}
}
unsubscribe(entity_uid)
{
let index = this.subscribed_to.indexOf(entity_uid);
if (index !== -1) {
this.subscribed_to.splice(index, 1);
return true;
} else {
return false;
}
}
process()
{
if (this.paused === true) return false;
for (let index in this.subscribed_to) {
this.processEntity(this.subscribed_to[index]);
}
return true;
}
processEntity(entity_uid)
{
// each system should implement this method itself
console.log('processing entity UID: ' + entity_uid);
return false;
}
pause()
{
this.paused = true;
return true;
}
unpause()
{
this.paused = false;
return true;
}
}