-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (37 loc) · 1.26 KB
/
index.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
function System() {
this.components = [];
this.index = null;
}
System.prototype.init = function (engine) {
var that;
that = this;
console.log("Script system loaded");
this.engine = engine;
this.index = this.engine.index("script");
this.engine.on("componentCreated", function (type, component, entity) {
var i, script;
if (type === "script") {
component = that.engine.get(entity, "script");
for (i = 0; i < component.scripts.length; ++i) {
script = component.scripts[i];
if (script.init && typeof script.init === "function") {
script.init.call(engine, component._entity);
}
}
}
});
};
System.prototype.update = function (dt) {
var entities, i, j, component, script;
entities = this.engine.getAll(this.index);
for (i = 0; i < entities.length; ++i) {
component = this.engine.get(entities[i], "script");
for (j = 0; j < component.scripts.length; ++j) {
script = component.scripts[j];
if (script.update && typeof script.update === "function") {
script.update.call(this.engine, component._entity, dt);
}
}
}
};
module.exports = System;