entityjs 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -6
- data/.rspec +2 -0
- data/README.md +170 -49
- data/Rakefile +9 -0
- data/bin/entityjs +24 -14
- data/entityjs.gemspec +15 -9
- data/lib/entityjs/assets.rb +167 -0
- data/lib/entityjs/command.rb +52 -27
- data/lib/entityjs/commands/build.rb +128 -0
- data/lib/entityjs/commands/comp.rb +74 -0
- data/lib/entityjs/commands/font.rb +73 -0
- data/lib/entityjs/commands/new.rb +59 -0
- data/lib/entityjs/commands/server.rb +54 -0
- data/lib/entityjs/commands/templates.rb +28 -0
- data/lib/entityjs/commands/test.rb +69 -0
- data/lib/entityjs/config.rb +130 -0
- data/lib/entityjs/dirc.rb +184 -0
- data/lib/entityjs/parsers/parse_tmx.rb +41 -0
- data/lib/entityjs/parsers/parse_xml.rb +39 -0
- data/lib/entityjs/version.rb +1 -1
- data/lib/entityjs.rb +53 -0
- data/license.txt +1 -1
- data/public/play.html +122 -0
- data/public/qunit/qunit.css +226 -0
- data/public/qunit/qunit.entity.js +190 -0
- data/public/qunit/qunit.input.js +200 -0
- data/public/qunit/qunit.js +1598 -0
- data/public/qunit/qunit.mock.js +97 -0
- data/public/tests.html +45 -0
- data/spec/javascripts/helpers/accept.png +0 -0
- data/spec/javascripts/helpers/alligator.mp3 +0 -0
- data/spec/javascripts/helpers/alligator.ogg +0 -0
- data/spec/javascripts/helpers/canvas.js +15 -0
- data/spec/javascripts/helpers/entityunit.js +50 -0
- data/spec/javascripts/helpers/factories.js +11 -0
- data/spec/javascripts/helpers/jquery-1.7.1.min.js +4 -0
- data/spec/javascripts/src/core/comp_spec.js +145 -0
- data/spec/javascripts/src/core/entity_spec.js +324 -0
- data/spec/javascripts/src/core/load_spec.js +71 -0
- data/spec/javascripts/src/core/query_spec.js +157 -0
- data/spec/javascripts/src/core/re_spec.js +61 -0
- data/spec/javascripts/src/core/system_spec.js +41 -0
- data/spec/javascripts/src/cycle/draw_spec.js +106 -0
- data/spec/javascripts/src/cycle/tick_spec.js +20 -0
- data/spec/javascripts/src/cycle/update_spec.js +86 -0
- data/spec/javascripts/src/display/align_spec.js +43 -0
- data/spec/javascripts/src/display/circle_spec.js +26 -0
- data/spec/javascripts/src/display/group_spec.js +7 -0
- data/spec/javascripts/src/display/image_spec.js +32 -0
- data/spec/javascripts/src/display/imgtext_spec.js +32 -0
- data/spec/javascripts/src/display/rect_spec.js +13 -0
- data/spec/javascripts/src/display/screen_spec.js +47 -0
- data/spec/javascripts/src/display/sprite_spec.js +28 -0
- data/spec/javascripts/src/display/text_spec.js +30 -0
- data/spec/javascripts/src/input/keyboard_spec.js +67 -0
- data/spec/javascripts/src/input/mouse_spec.js +133 -0
- data/spec/javascripts/src/input/pressed_spec.js +31 -0
- data/spec/javascripts/src/math/bisect_spec.js +59 -0
- data/spec/javascripts/src/math/body_spec.js +30 -0
- data/spec/javascripts/src/math/drag_spec.js +38 -0
- data/spec/javascripts/src/math/force_spec.js +134 -0
- data/spec/javascripts/src/math/hit_spec.js +28 -0
- data/spec/javascripts/src/math/hitmap_spec.js +52 -0
- data/spec/javascripts/src/math/limit_spec.js +35 -0
- data/spec/javascripts/src/math/point_spec.js +57 -0
- data/spec/javascripts/src/math/tile_spec.js +78 -0
- data/spec/javascripts/src/media/sound_spec.js +40 -0
- data/spec/javascripts/src/pattern/automap_spec.js +93 -0
- data/spec/javascripts/src/pattern/flicker_spec.js +66 -0
- data/spec/javascripts/src/pattern/timestep_spec.js +23 -0
- data/spec/javascripts/src/save/storage_spec.js +37 -0
- data/spec/javascripts/src/util/log_spec.js +9 -0
- data/spec/javascripts/src/util/polyfill_spec.js +13 -0
- data/spec/javascripts/src/util/random_spec.js +33 -0
- data/spec/javascripts/src/util/scene_spec.js +52 -0
- data/spec/javascripts/src/util/sheet_spec.js +25 -0
- data/spec/javascripts/src/util/support_spec.js +17 -0
- data/spec/javascripts/support/jasmine.yml +76 -0
- data/spec/javascripts/support/jasmine_config.rb +32 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/lib/entityjs/assets_spec.rb +216 -0
- data/spec/lib/entityjs/command_spec.rb +53 -0
- data/spec/lib/entityjs/commands/build_spec.rb +69 -0
- data/spec/lib/entityjs/commands/comp_spec.rb +45 -0
- data/spec/lib/entityjs/commands/font_spec.rb +7 -0
- data/spec/lib/entityjs/commands/new_spec.rb +20 -0
- data/spec/lib/entityjs/commands/templates_spec.rb +9 -0
- data/spec/lib/entityjs/commands/test_spec.rb +31 -0
- data/spec/lib/entityjs/config_spec.rb +19 -0
- data/spec/lib/entityjs/dirc_spec.rb +83 -0
- data/spec/lib/entityjs/version_spec.rb +9 -0
- data/spec/spec_helper.rb +21 -3
- data/spec/support/factories.rb +19 -0
- data/spec/support/mygame.rb +11 -0
- data/src/core/comp.js +318 -0
- data/src/core/entity.js +549 -0
- data/src/core/load.js +242 -0
- data/src/core/query.js +354 -0
- data/src/core/re.js +74 -0
- data/src/core/system.js +121 -0
- data/src/cycle/draw.js +178 -0
- data/src/cycle/tick.js +25 -0
- data/src/{entityjs/cycle → cycle}/tween.js +60 -60
- data/src/{entityjs/cycle → cycle}/update.js +86 -85
- data/src/{entityjs/cycle → cycle}/wait.js +22 -21
- data/src/{entityjs/cycle → cycle}/worker.js +8 -8
- data/src/display/align.js +45 -0
- data/src/display/circle.js +33 -0
- data/src/{entityjs/display → display}/group.js +62 -62
- data/src/display/image.js +35 -0
- data/src/display/imgtext.js +102 -0
- data/src/{entityjs/display → display}/rect.js +18 -18
- data/src/display/screen.js +57 -0
- data/src/display/sprite.js +54 -0
- data/src/display/text.js +44 -0
- data/src/{entityjs/input → input}/keyboard.js +152 -150
- data/src/input/mouse.js +111 -0
- data/src/input/pressed.js +41 -0
- data/src/{entityjs/input → input}/touch.js +24 -28
- data/src/math/bisect.js +84 -0
- data/src/math/body.js +70 -0
- data/src/{entityjs/math → math}/drag.js +44 -38
- data/src/math/force.js +143 -0
- data/src/math/hit.js +32 -0
- data/src/math/hitmap.js +167 -0
- data/src/math/limit.js +37 -0
- data/src/math/point.js +40 -0
- data/src/math/tile.js +109 -0
- data/src/media/channel.js +93 -0
- data/src/{entityjs/media → media}/playlist.js +4 -4
- data/src/media/sound.js +114 -0
- data/src/{entityjs/net → net}/socket.js +51 -51
- data/src/pattern/automap.js +133 -0
- data/src/{entityjs/pattern → pattern}/flicker.js +206 -213
- data/src/pattern/timestep.js +31 -0
- data/src/{entityjs/save → save}/database.js +6 -6
- data/src/{entityjs/save → save}/storage.js +47 -56
- data/src/{entityjs/util → util}/log.js +17 -25
- data/src/{entityjs/util → util}/polyfill.js +24 -24
- data/src/util/random.js +20 -0
- data/src/util/scene.js +102 -0
- data/src/util/sheet.js +35 -0
- data/src/{entityjs/util → util}/support.js +109 -132
- data/{examples/keys → templates/arrow_keys/assets/images}/arrow.png +0 -0
- data/templates/arrow_keys/config.yml +22 -0
- data/templates/arrow_keys/readme.txt +9 -0
- data/templates/arrow_keys/scripts/display/arrow.js +69 -0
- data/templates/arrow_keys/scripts/init.js +10 -0
- data/templates/arrow_keys/scripts/input/controls.js +35 -0
- data/templates/arrow_keys/scripts/scenes/home.js +20 -0
- data/templates/arrow_keys/scripts/scenes/load.js +57 -0
- data/templates/arrow_keys/tests/display/arrow_test.js +29 -0
- data/templates/arrow_keys/tests/init_test.js +4 -0
- data/templates/arrow_keys/tests/input/controls_test.js +32 -0
- data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +16 -0
- data/templates/blank/config.yml +22 -0
- data/templates/blank/readme.txt +79 -0
- data/templates/platform/assets/images/bit.png +0 -0
- data/templates/platform/assets/images/hero.png +0 -0
- data/templates/platform/assets/images/items.png +0 -0
- data/templates/platform/assets/images/tiles.png +0 -0
- data/templates/platform/assets/levels/level1.tmx +44 -0
- data/templates/platform/assets/sounds/coin.mp3 +0 -0
- data/templates/platform/assets/sounds/coin.ogg +0 -0
- data/templates/platform/config.yml +22 -0
- data/templates/platform/readme.txt +87 -0
- data/templates/platform/scripts/display/bit.js +12 -0
- data/templates/platform/scripts/display/hero.js +77 -0
- data/templates/platform/scripts/display/tile.js +2 -0
- data/templates/platform/scripts/display/tsprite.js +17 -0
- data/templates/platform/scripts/init.js +7 -0
- data/templates/platform/scripts/items/coin.js +27 -0
- data/templates/platform/scripts/items/item.js +41 -0
- data/templates/platform/scripts/items/spring.js +25 -0
- data/templates/platform/scripts/scenes/home.js +10 -0
- data/templates/platform/scripts/scenes/load.js +27 -0
- data/templates/platform/scripts/scenes/play.js +31 -0
- data/templates/platform/scripts/util/counter.js +34 -0
- data/templates/platform/scripts/util/level.js +84 -0
- data/templates/platform/tests/display/bit_test.js +7 -0
- data/templates/platform/tests/display/hero_test.js +73 -0
- data/templates/platform/tests/display/tile_test.js +7 -0
- data/templates/platform/tests/display/tsprite_test.js +8 -0
- data/templates/platform/tests/factories.js +30 -0
- data/templates/platform/tests/items/coin_test.js +28 -0
- data/templates/platform/tests/items/item_test.js +36 -0
- data/templates/platform/tests/items/spring_test.js +21 -0
- data/templates/platform/tests/scenes/home_test.js +9 -0
- data/templates/platform/tests/scenes/load_test.js +11 -0
- data/templates/platform/tests/scenes/play_test.js +15 -0
- data/templates/platform/tests/util/counter_test.js +9 -0
- data/templates/platform/tests/util/level_test.js +29 -0
- metadata +249 -97
- data/build/build_debug.bat +0 -1
- data/build/build_min.bat +0 -1
- data/build/config.php +0 -64
- data/build/debug.php +0 -48
- data/build/files.php +0 -74
- data/build/jsmin.php +0 -376
- data/build/min.php +0 -50
- data/changelog.txt +0 -53
- data/examples/keys/keys.html +0 -59
- data/examples/keys/keys.js +0 -148
- data/examples/mouse/mouse.html +0 -58
- data/examples/mouse/mouse.js +0 -60
- data/examples/scenes/home.png +0 -0
- data/examples/scenes/scenes.html +0 -55
- data/examples/scenes/scenes.js +0 -134
- data/examples/scenes/win.png +0 -0
- data/examples/sounds/sound1.mp3 +0 -0
- data/examples/sounds/sound1.ogg +0 -0
- data/examples/sounds/sounds.html +0 -56
- data/examples/sounds/sounds.js +0 -44
- data/examples/style/background.png +0 -0
- data/examples/style/sheet.css +0 -762
- data/examples/tiles/tiles.html +0 -56
- data/examples/tiles/tiles.js +0 -85
- data/examples/tiles/tiles.png +0 -0
- data/lib/blank/config.js +0 -4
- data/lib/blank/config.yml +0 -21
- data/lib/blank/home.js +0 -11
- data/lib/blank/init.js +0 -7
- data/lib/blank/load.js +0 -21
- data/lib/blank/play.html +0 -29
- data/lib/entity.debug.js +0 -52
- data/lib/entity.min.js +0 -184
- data/lib/entityjs/comp.rb +0 -11
- data/lib/entityjs/game.rb +0 -93
- data/lib/entityjs/min.rb +0 -11
- data/lib/entityjs/refresh.rb +0 -14
- data/spec/lib/entityjs/game_spec.rb +0 -11
- data/src/entityjs/core/component.js +0 -306
- data/src/entityjs/core/entity.js +0 -516
- data/src/entityjs/core/load.js +0 -224
- data/src/entityjs/core/query.js +0 -410
- data/src/entityjs/core/re.js +0 -70
- data/src/entityjs/core/system.js +0 -125
- data/src/entityjs/cycle/draw.js +0 -185
- data/src/entityjs/cycle/ticker.js +0 -27
- data/src/entityjs/display/anchor.js +0 -53
- data/src/entityjs/display/bitfont.js +0 -93
- data/src/entityjs/display/bitmap.js +0 -37
- data/src/entityjs/display/circle.js +0 -30
- data/src/entityjs/display/font.js +0 -41
- data/src/entityjs/display/screen.js +0 -46
- data/src/entityjs/display/sprite.js +0 -37
- data/src/entityjs/input/mouse.js +0 -123
- data/src/entityjs/input/pressed.js +0 -81
- data/src/entityjs/math/bind.js +0 -76
- data/src/entityjs/math/bisect.js +0 -69
- data/src/entityjs/math/body.js +0 -39
- data/src/entityjs/math/hitmap.js +0 -165
- data/src/entityjs/math/hittest.js +0 -26
- data/src/entityjs/math/physics.js +0 -142
- data/src/entityjs/math/point.js +0 -57
- data/src/entityjs/math/tile.js +0 -91
- data/src/entityjs/media/channel.js +0 -93
- data/src/entityjs/media/sound.js +0 -110
- data/src/entityjs/pattern/arraymap.js +0 -89
- data/src/entityjs/pattern/timestep.js +0 -34
- data/src/entityjs/util/random.js +0 -38
- data/src/entityjs/util/scene.js +0 -101
- data/src/entityjs/util/sheet.js +0 -51
data/src/core/entity.js
ADDED
@@ -0,0 +1,549 @@
|
|
1
|
+
(function(re){
|
2
|
+
|
3
|
+
/*
|
4
|
+
Main function for re.e
|
5
|
+
|
6
|
+
//create multiple entities
|
7
|
+
re.e('spider', 10)
|
8
|
+
//returns a query with all entities
|
9
|
+
.each(function(index){
|
10
|
+
this.posX = index * 10;
|
11
|
+
});
|
12
|
+
|
13
|
+
*/
|
14
|
+
var q = function(c, count){
|
15
|
+
if(!count){
|
16
|
+
return new re.entity.init(c);
|
17
|
+
}
|
18
|
+
|
19
|
+
//optimize for multiple calls
|
20
|
+
var q = re();
|
21
|
+
|
22
|
+
//create entity by number of count
|
23
|
+
for(var i=0; i<count; i++){
|
24
|
+
q.push(re.e(c));
|
25
|
+
}
|
26
|
+
|
27
|
+
return q;
|
28
|
+
};
|
29
|
+
|
30
|
+
q.id = 0;
|
31
|
+
|
32
|
+
var e = function(c){
|
33
|
+
|
34
|
+
this._re_comps = [];
|
35
|
+
this._re_signals = {};
|
36
|
+
|
37
|
+
this.id = q.id+'';
|
38
|
+
|
39
|
+
q.id++;
|
40
|
+
|
41
|
+
re._e.push(this);
|
42
|
+
|
43
|
+
this.comp(c);
|
44
|
+
};
|
45
|
+
|
46
|
+
var p = e.prototype;
|
47
|
+
|
48
|
+
p.id = '';
|
49
|
+
|
50
|
+
p.addComp = function(c){
|
51
|
+
re.log('AddComp deprecated use comp')
|
52
|
+
this.comp(c);
|
53
|
+
};
|
54
|
+
|
55
|
+
p.comp = function(com){
|
56
|
+
|
57
|
+
this._re_comp(com);
|
58
|
+
|
59
|
+
//check implement
|
60
|
+
if(this._re_implements){
|
61
|
+
|
62
|
+
for(var i in this._re_implements){
|
63
|
+
if(!this.hasOwnProperty(this._re_implements[i])){
|
64
|
+
throw 'Interface: '+this._re_implements[i]+' missing';
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
}
|
69
|
+
|
70
|
+
//check asserts
|
71
|
+
if(this._re_asserts){
|
72
|
+
for(var t in this._re_asserts){
|
73
|
+
if(this._re_comps.indexOf(this._re_asserts[t]) != -1){
|
74
|
+
throw 'Assert: '+this._re_asserts[t]+' is not allowed';
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
return this;
|
80
|
+
};
|
81
|
+
|
82
|
+
p.removeComp = function(com){
|
83
|
+
|
84
|
+
var pieces;
|
85
|
+
|
86
|
+
//handle string or array?
|
87
|
+
if(re.is(com,'array')){
|
88
|
+
pieces = com;
|
89
|
+
|
90
|
+
com = com[0];
|
91
|
+
} else {
|
92
|
+
pieces = com.split(' ');
|
93
|
+
}
|
94
|
+
|
95
|
+
if(pieces.length > 1){
|
96
|
+
|
97
|
+
for(var k in pieces){
|
98
|
+
this._re_comp(pieces[k]);
|
99
|
+
}
|
100
|
+
|
101
|
+
return this;
|
102
|
+
}
|
103
|
+
|
104
|
+
var c = re._c[com];
|
105
|
+
|
106
|
+
if(!this.has(com)) return this;
|
107
|
+
|
108
|
+
//remove from array
|
109
|
+
this._re_comps.splice(this._re_comps.indexOf(com), 1);
|
110
|
+
|
111
|
+
//only remove if it exists
|
112
|
+
if(c){
|
113
|
+
|
114
|
+
if(c._re_dispose){
|
115
|
+
c._re_dispose.call(this, c);
|
116
|
+
}
|
117
|
+
|
118
|
+
c.trigger('dispose', this);
|
119
|
+
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
/*
|
124
|
+
//add components
|
125
|
+
this.comp('point text');
|
126
|
+
|
127
|
+
//add health component with 100 health
|
128
|
+
this.comp('health:100 physics');
|
129
|
+
|
130
|
+
//remove components
|
131
|
+
this.comp('-point');
|
132
|
+
*/
|
133
|
+
/*p.comp = function(com){
|
134
|
+
|
135
|
+
this._re_comp(com);
|
136
|
+
|
137
|
+
//check implement
|
138
|
+
if(this._re_interface){
|
139
|
+
|
140
|
+
for(var i in this._re_interface){
|
141
|
+
if(!this.hasOwnProperty(this._re_interface[i])){
|
142
|
+
throw 'implementation: '+this._re_interface[i]+' missing';
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
}
|
147
|
+
|
148
|
+
//check asserts
|
149
|
+
if(this._re_asserts){
|
150
|
+
for(var t in this._re_asserts){
|
151
|
+
if(this._re_comps.indexOf(c._re_asserts[t]) != -1){
|
152
|
+
throw 'assert: '+c.name+' cannot be coupled with '+c._re_asserts[t];
|
153
|
+
}
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
return this;
|
158
|
+
}*/
|
159
|
+
|
160
|
+
p._re_comp = function(com){
|
161
|
+
if(!com) return this;
|
162
|
+
|
163
|
+
//split a multi word string into smaller one word function calls
|
164
|
+
var pieces;
|
165
|
+
|
166
|
+
//handle array or string?
|
167
|
+
if(re.is(com, 'array')){
|
168
|
+
pieces = com;
|
169
|
+
//set in case length is 1
|
170
|
+
com = com[0];
|
171
|
+
} else {
|
172
|
+
pieces = com.split(' ');
|
173
|
+
}
|
174
|
+
|
175
|
+
if(pieces.length > 1){
|
176
|
+
for(var k in pieces){
|
177
|
+
this._re_comp(pieces[k]);
|
178
|
+
}
|
179
|
+
|
180
|
+
return this;
|
181
|
+
}
|
182
|
+
|
183
|
+
//component reference
|
184
|
+
var c;
|
185
|
+
|
186
|
+
var vals = com.split(':');
|
187
|
+
|
188
|
+
com = vals[0];
|
189
|
+
|
190
|
+
//add component
|
191
|
+
c = re._c[com];
|
192
|
+
|
193
|
+
//swap values
|
194
|
+
vals[0] = c;
|
195
|
+
|
196
|
+
//if already has component
|
197
|
+
if(this.has(com)) return this;
|
198
|
+
|
199
|
+
//add comp first thing, to avoid dupe requiresment calls
|
200
|
+
//and this lets the init remove the comp too.
|
201
|
+
this._re_comps.push(com);
|
202
|
+
|
203
|
+
//init component only if it exists
|
204
|
+
if(c){
|
205
|
+
this._re_comp(c._re_requires);
|
206
|
+
|
207
|
+
//add interface of component
|
208
|
+
if(c._re_implements){
|
209
|
+
if(!this._re_implements){
|
210
|
+
this._re_implements = [];
|
211
|
+
}
|
212
|
+
this._re_implements = this._re_implements.concat(c._re_implements);
|
213
|
+
}
|
214
|
+
|
215
|
+
if(c._re_asserts){
|
216
|
+
if(!this._re_asserts){
|
217
|
+
this._re_asserts = [];
|
218
|
+
}
|
219
|
+
this._re_asserts = this._re_asserts.concat(c._re_asserts);
|
220
|
+
}
|
221
|
+
|
222
|
+
if(c._re_inherits){
|
223
|
+
this.def(c._re_inherits);
|
224
|
+
}
|
225
|
+
|
226
|
+
if(c._re_defines){
|
227
|
+
this.attr(c._re_defines);
|
228
|
+
}
|
229
|
+
|
230
|
+
if(c._re_init){
|
231
|
+
c._re_init.apply(this, vals);
|
232
|
+
}
|
233
|
+
|
234
|
+
c.trigger('init', this);
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
return this;
|
241
|
+
}
|
242
|
+
|
243
|
+
/*
|
244
|
+
Returns component array
|
245
|
+
*/
|
246
|
+
p.comps = function(){
|
247
|
+
return this._re_comps.slice();
|
248
|
+
}
|
249
|
+
|
250
|
+
p.clone = function(count){
|
251
|
+
return re.e(this._re_comps, count);
|
252
|
+
}
|
253
|
+
|
254
|
+
/*
|
255
|
+
Calls methods of parent components.
|
256
|
+
|
257
|
+
Use '' to call super of entity
|
258
|
+
|
259
|
+
re.e('draw')
|
260
|
+
.parent('draw', 'screenX')()
|
261
|
+
|
262
|
+
*/
|
263
|
+
p.parent = function(comp, method){
|
264
|
+
|
265
|
+
var a = Array.prototype.slice.call(arguments, 2);
|
266
|
+
|
267
|
+
if(comp == ''){
|
268
|
+
//call entity parent methods
|
269
|
+
return re.e.init.prototype[method].apply(this, a);
|
270
|
+
}
|
271
|
+
|
272
|
+
var c = re._c[comp];
|
273
|
+
|
274
|
+
if(c._re_defines[method]){
|
275
|
+
return c._re_defines[method].apply(this, a);
|
276
|
+
}
|
277
|
+
|
278
|
+
return c._re_inherits[method].apply(this, a);
|
279
|
+
}
|
280
|
+
|
281
|
+
/*
|
282
|
+
TODO defines has to multiple item query
|
283
|
+
|
284
|
+
//returns true if both present
|
285
|
+
this.has('draw update');
|
286
|
+
|
287
|
+
//return true if bitmap not present but has update
|
288
|
+
this.has('update -bitmap');
|
289
|
+
|
290
|
+
//returns true if has asset id and update bind
|
291
|
+
this.has('#asset ^update');
|
292
|
+
|
293
|
+
//expanded
|
294
|
+
this.has({
|
295
|
+
'comp':['draw'],
|
296
|
+
'id':'bob',
|
297
|
+
'on':['draw'],
|
298
|
+
'not':['update']
|
299
|
+
});
|
300
|
+
*/
|
301
|
+
p.has = function(comp){
|
302
|
+
|
303
|
+
if(re.is(comp ,'string')){
|
304
|
+
|
305
|
+
comp = re.query._toObj(comp);
|
306
|
+
}
|
307
|
+
|
308
|
+
comp.comp = comp.comp || [];
|
309
|
+
comp.id = comp.id || '';
|
310
|
+
comp.on = comp.on || [];
|
311
|
+
comp.not = comp.not || [];
|
312
|
+
|
313
|
+
//check if entitiy contains the correct components
|
314
|
+
for(p=0; p<comp.comp.length; p++){
|
315
|
+
|
316
|
+
//check if not containing components
|
317
|
+
if(this._re_comps.indexOf(comp.comp[p]) == -1){
|
318
|
+
return false;
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
//check if entity doesn't contain components
|
323
|
+
for(p=0; p<comp.not.length; p++){
|
324
|
+
if(this._re_comps.indexOf(comp.not[p]) != -1){
|
325
|
+
return false;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
|
329
|
+
var s;
|
330
|
+
//check if entity contains signals
|
331
|
+
for(p=0; p<comp.on.length; p++){
|
332
|
+
s = comp.on[p];
|
333
|
+
if(!this._re_signals[s] || this._re_signals[s].length == 0){
|
334
|
+
return false;
|
335
|
+
}
|
336
|
+
}
|
337
|
+
|
338
|
+
if(comp.id != '' && this.id != comp.id){
|
339
|
+
return false;
|
340
|
+
}
|
341
|
+
|
342
|
+
|
343
|
+
return true;
|
344
|
+
};
|
345
|
+
|
346
|
+
/*
|
347
|
+
New way to add signals version 0.2.1.
|
348
|
+
|
349
|
+
//single
|
350
|
+
bind('draw', function(){});
|
351
|
+
|
352
|
+
//multiple
|
353
|
+
bind({
|
354
|
+
|
355
|
+
draw:function(){},
|
356
|
+
|
357
|
+
update:function(){}
|
358
|
+
|
359
|
+
});
|
360
|
+
*/
|
361
|
+
p.on = function(type, method){
|
362
|
+
|
363
|
+
if(re.is(type, 'object')){
|
364
|
+
|
365
|
+
for(var k in type){
|
366
|
+
this.on(k, type[k]);
|
367
|
+
}
|
368
|
+
|
369
|
+
} else {
|
370
|
+
|
371
|
+
if(!this._re_signals[type]){
|
372
|
+
this._re_signals[type] = [];
|
373
|
+
}
|
374
|
+
if(!re.is(method)) throw 'Method is null'
|
375
|
+
this._re_signals[type].push(method);
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
return this;
|
380
|
+
};
|
381
|
+
|
382
|
+
/*
|
383
|
+
Added in V0.2.1
|
384
|
+
|
385
|
+
//remove bind from function
|
386
|
+
off('draw', this.draw);
|
387
|
+
|
388
|
+
//remove multiple
|
389
|
+
off({
|
390
|
+
draw:this.draw,
|
391
|
+
update:this.update
|
392
|
+
});
|
393
|
+
|
394
|
+
//remove all keydown binds
|
395
|
+
off('keydown')
|
396
|
+
|
397
|
+
//remove all binds
|
398
|
+
off()
|
399
|
+
*/
|
400
|
+
p.off = function(type, method){
|
401
|
+
|
402
|
+
if(re.is(type, 'object')){
|
403
|
+
|
404
|
+
for(var k in type){
|
405
|
+
this.off(k, type[k]);
|
406
|
+
}
|
407
|
+
|
408
|
+
} else {
|
409
|
+
|
410
|
+
if(method){
|
411
|
+
|
412
|
+
for(var k in this._re_signals[type]){
|
413
|
+
|
414
|
+
if(this._re_signals[type][k] == method){
|
415
|
+
this._re_signals[type].splice(k, 1);
|
416
|
+
}
|
417
|
+
|
418
|
+
}
|
419
|
+
} else if(type){
|
420
|
+
|
421
|
+
//no method was passed. Remove all signals
|
422
|
+
this._re_signals[type] = [];
|
423
|
+
|
424
|
+
} else {
|
425
|
+
//remove all signals
|
426
|
+
this._re_signals = {};
|
427
|
+
}
|
428
|
+
}
|
429
|
+
|
430
|
+
return this;
|
431
|
+
};
|
432
|
+
|
433
|
+
/*
|
434
|
+
Signal dispatches events to entities.
|
435
|
+
Modified V0.3
|
436
|
+
|
437
|
+
|
438
|
+
-dispatch signals
|
439
|
+
this.trigger('click');
|
440
|
+
this.trigger('click draw');
|
441
|
+
this.trigger('click', {data:0});
|
442
|
+
|
443
|
+
*/
|
444
|
+
p.trigger = function(type){
|
445
|
+
|
446
|
+
if(!this._re_signals[type]) return this;
|
447
|
+
var b;
|
448
|
+
|
449
|
+
for(var i=0, l = this._re_signals[type].length; i<l; i++){
|
450
|
+
|
451
|
+
b = this._re_signals[type];
|
452
|
+
|
453
|
+
if(!b) break;
|
454
|
+
if(!b[i]) continue;
|
455
|
+
|
456
|
+
//return false remove?
|
457
|
+
if(b[i].apply( (b[i].c)?b[i].c : this , Array.prototype.slice.call(arguments, 1)) === false){
|
458
|
+
b.splice(i, 1);
|
459
|
+
}
|
460
|
+
|
461
|
+
}
|
462
|
+
|
463
|
+
return this;
|
464
|
+
};
|
465
|
+
|
466
|
+
p.extend = function(){
|
467
|
+
throw 'Deprecated use attr'
|
468
|
+
};
|
469
|
+
|
470
|
+
p.attr = function(obj, value){
|
471
|
+
|
472
|
+
if(re.is(obj, 'object')){
|
473
|
+
|
474
|
+
for(var key in obj){
|
475
|
+
if(!obj.hasOwnProperty(key)) continue;
|
476
|
+
|
477
|
+
this.attr(key, obj[key]);
|
478
|
+
}
|
479
|
+
|
480
|
+
}else {
|
481
|
+
//defines property
|
482
|
+
if(re.is(this[obj], 'function') && !re.is(value, 'function')){
|
483
|
+
if(re.is(value, 'array')){
|
484
|
+
this[obj].apply(this, value);
|
485
|
+
} else {
|
486
|
+
this[obj].call(this, value);
|
487
|
+
}
|
488
|
+
} else {
|
489
|
+
this[obj] = value;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
return this;
|
494
|
+
};
|
495
|
+
|
496
|
+
p.inherit = function(){
|
497
|
+
|
498
|
+
throw 'Deprecated use def'
|
499
|
+
}
|
500
|
+
|
501
|
+
p.defaults = function(){
|
502
|
+
throw 'Deprecated use def'
|
503
|
+
}
|
504
|
+
|
505
|
+
p.def = function(obj, value){
|
506
|
+
|
507
|
+
if(re.is(obj , 'object')){
|
508
|
+
|
509
|
+
for(var key in obj){
|
510
|
+
if(!obj.hasOwnProperty(key)) continue;
|
511
|
+
|
512
|
+
this.def(key, obj[key]);
|
513
|
+
|
514
|
+
}
|
515
|
+
|
516
|
+
} else {
|
517
|
+
//defines property
|
518
|
+
|
519
|
+
if(!this.hasOwnProperty(obj) || !re.is(this[obj])){
|
520
|
+
|
521
|
+
this[obj] = value;
|
522
|
+
|
523
|
+
}
|
524
|
+
}
|
525
|
+
|
526
|
+
return this;
|
527
|
+
}
|
528
|
+
|
529
|
+
p.dispose = function(){
|
530
|
+
//delete from statics array
|
531
|
+
re._e.splice(re._e.indexOf(this), 1);
|
532
|
+
|
533
|
+
for(var i in this._re_comps){
|
534
|
+
var k = re.c(this._re_comps[i]);
|
535
|
+
if(k._re_dispose){
|
536
|
+
k._re_dispose.call(this, k);
|
537
|
+
}
|
538
|
+
k.trigger('dispose', this);
|
539
|
+
}
|
540
|
+
|
541
|
+
this.trigger('dispose');
|
542
|
+
|
543
|
+
return this;
|
544
|
+
}
|
545
|
+
|
546
|
+
re.entity = re.e = q;
|
547
|
+
re.entity.init = e;
|
548
|
+
|
549
|
+
}(re));
|