-
Notifications
You must be signed in to change notification settings - Fork 7
/
Entity.js
executable file
·44 lines (43 loc) · 1.02 KB
/
Entity.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
define(['jo', 'Object', 'Behaviour'], function(jo, Object, Behaviour){
jo.Entity = Object.extend({
joObject: 'Entity',
init: function(){
this._super.apply(this, arguments);
},
applyB: function(name, args){
for(var i in this.b){
if(this.b[i].isBehaviour){
this.b[i][name].apply(this.b[i], args);
}
}
},
update: function(time){
this.applyB('update', [time]);
this._super(time);
this.applyB('postUpdate', [time]);
},
draw: function(opt, pos, srf){
this.applyB('draw', [opt, pos, srf]);
this._super(time);
this.applyB('postDraw', [opt, pos, srf]);
},
addBehaviour: function(name, b){
this.b[name] = b;
b.setup(this);
},
hasBehaviour: function(name){
return typeof this.b[name] !== 'undefined';
},
removeBehaviour: function(name){
if(this.hasBehaviour(name)){
delete this.b[name];
this.b[name]= undefined;
}
},
_postParse: function(){
this._super();
this.applyB(setup, [this]);
}
});
jo.Entity;
});