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/entityjs/core/entity.js
DELETED
@@ -1,516 +0,0 @@
|
|
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._e.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.addComp(c);
|
44
|
-
};
|
45
|
-
|
46
|
-
var p = e.prototype;
|
47
|
-
|
48
|
-
p.id = '';
|
49
|
-
|
50
|
-
p.addComp = function(com){
|
51
|
-
|
52
|
-
this._re_comp(com);
|
53
|
-
|
54
|
-
//check implement
|
55
|
-
if(this._re_interface){
|
56
|
-
|
57
|
-
for(var i in this._re_interface){
|
58
|
-
if(!this.hasOwnProperty(this._re_interface[i])){
|
59
|
-
throw 'implementation: '+this._re_interface[i]+' missing';
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
}
|
64
|
-
|
65
|
-
//check asserts
|
66
|
-
if(this._re_asserts){
|
67
|
-
for(var t in this._re_asserts){
|
68
|
-
if(this._re_comps.indexOf(c._re_asserts[t]) != -1){
|
69
|
-
throw 'assert: '+c.name+' cannot be coupled with '+c._re_asserts[t];
|
70
|
-
}
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
return this;
|
75
|
-
};
|
76
|
-
|
77
|
-
p.removeComp = function(com){
|
78
|
-
|
79
|
-
var pieces;
|
80
|
-
|
81
|
-
//handle string or array?
|
82
|
-
if(typeof com == 'object'){
|
83
|
-
pieces = com;
|
84
|
-
|
85
|
-
com = com[0];
|
86
|
-
} else {
|
87
|
-
pieces = com.split(' ');
|
88
|
-
}
|
89
|
-
|
90
|
-
if(pieces.length > 1){
|
91
|
-
|
92
|
-
for(var k in pieces){
|
93
|
-
this._re_comp(pieces[k]);
|
94
|
-
}
|
95
|
-
|
96
|
-
return this;
|
97
|
-
}
|
98
|
-
|
99
|
-
var c = re._c[com];
|
100
|
-
|
101
|
-
if(!this.has(com)) return this;
|
102
|
-
|
103
|
-
//remove from array
|
104
|
-
this._re_comps.splice(this._re_comps.indexOf(com), 1);
|
105
|
-
|
106
|
-
//only remove if it exists
|
107
|
-
if(c){
|
108
|
-
|
109
|
-
if(c._re_dispose){
|
110
|
-
c._re_dispose.call(this, c);
|
111
|
-
}
|
112
|
-
|
113
|
-
c.signal('dispose', this);
|
114
|
-
|
115
|
-
}
|
116
|
-
};
|
117
|
-
|
118
|
-
/*
|
119
|
-
//add components
|
120
|
-
this.comp('point text');
|
121
|
-
|
122
|
-
//add health component with 100 health
|
123
|
-
this.comp('health:100 physics');
|
124
|
-
|
125
|
-
//remove components
|
126
|
-
this.comp('-point');
|
127
|
-
*/
|
128
|
-
/*p.comp = function(com){
|
129
|
-
|
130
|
-
this._re_comp(com);
|
131
|
-
|
132
|
-
//check implement
|
133
|
-
if(this._re_interface){
|
134
|
-
|
135
|
-
for(var i in this._re_interface){
|
136
|
-
if(!this.hasOwnProperty(this._re_interface[i])){
|
137
|
-
throw 'implementation: '+this._re_interface[i]+' missing';
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
//check asserts
|
144
|
-
if(this._re_asserts){
|
145
|
-
for(var t in this._re_asserts){
|
146
|
-
if(this._re_comps.indexOf(c._re_asserts[t]) != -1){
|
147
|
-
throw 'assert: '+c.name+' cannot be coupled with '+c._re_asserts[t];
|
148
|
-
}
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
return this;
|
153
|
-
}*/
|
154
|
-
|
155
|
-
p._re_comp = function(com){
|
156
|
-
if(!com) return this;
|
157
|
-
|
158
|
-
//split a multi word string into smaller one word function calls
|
159
|
-
var pieces;
|
160
|
-
|
161
|
-
//handle array or string?
|
162
|
-
if(typeof com == 'object'){
|
163
|
-
pieces = com;
|
164
|
-
//set in case length is 1
|
165
|
-
com = com[0];
|
166
|
-
} else {
|
167
|
-
pieces = com.split(' ');
|
168
|
-
}
|
169
|
-
|
170
|
-
if(pieces.length > 1){
|
171
|
-
for(var k in pieces){
|
172
|
-
this._re_comp(pieces[k]);
|
173
|
-
}
|
174
|
-
|
175
|
-
return this;
|
176
|
-
}
|
177
|
-
|
178
|
-
//component reference
|
179
|
-
var c;
|
180
|
-
|
181
|
-
var vals = com.split(':');
|
182
|
-
|
183
|
-
com = vals[0];
|
184
|
-
|
185
|
-
//add component
|
186
|
-
c = re._c[com];
|
187
|
-
|
188
|
-
//swap values
|
189
|
-
vals[0] = c;
|
190
|
-
|
191
|
-
//if already has component
|
192
|
-
if(this.has(com)) return this;
|
193
|
-
|
194
|
-
//add comp first thing, to avoid dupe requirement calls
|
195
|
-
//and this lets the init remove the comp too.
|
196
|
-
this._re_comps.push(com);
|
197
|
-
|
198
|
-
//init component only if it exists
|
199
|
-
if(c){
|
200
|
-
this._re_comp(c._re_requires);
|
201
|
-
|
202
|
-
//add interface of component
|
203
|
-
if(c._re_implements){
|
204
|
-
if(!this._re_implements){
|
205
|
-
this._re_implements = [];
|
206
|
-
}
|
207
|
-
this._re_implements = this._re_implements.concat(c._re_implements);
|
208
|
-
}
|
209
|
-
|
210
|
-
if(c._re_asserts){
|
211
|
-
if(!this._re_asserts){
|
212
|
-
this._re_asserts = [];
|
213
|
-
}
|
214
|
-
this._re_asserts = this._re_asserts.concat(c._re_asserts);
|
215
|
-
}
|
216
|
-
|
217
|
-
if(c._re_inherits){
|
218
|
-
this.inherit(c._re_inherits);
|
219
|
-
}
|
220
|
-
|
221
|
-
if(c._re_extends){
|
222
|
-
this.extend(c._re_extends);
|
223
|
-
}
|
224
|
-
|
225
|
-
if(c._re_init){
|
226
|
-
c._re_init.apply(this, vals);
|
227
|
-
}
|
228
|
-
|
229
|
-
c.signal('init', this);
|
230
|
-
}
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
return this;
|
236
|
-
}
|
237
|
-
|
238
|
-
/*
|
239
|
-
Returns component array
|
240
|
-
*/
|
241
|
-
p.getComps = function(){
|
242
|
-
return this._re_comps.slice();
|
243
|
-
}
|
244
|
-
|
245
|
-
p.clone = function(count){
|
246
|
-
return re.e(this._re_comps, count);
|
247
|
-
}
|
248
|
-
|
249
|
-
/*
|
250
|
-
Calls methods of parent components.
|
251
|
-
|
252
|
-
Use '' to call entities components when overriding
|
253
|
-
*/
|
254
|
-
p.parent = function(comp, method){
|
255
|
-
|
256
|
-
var a = Array.prototype.slice.call(arguments, 2);
|
257
|
-
|
258
|
-
if(comp == ''){
|
259
|
-
//call entity parent methods
|
260
|
-
re.e.init[method].apply(this, a);
|
261
|
-
}
|
262
|
-
|
263
|
-
var c = re._c[comp];
|
264
|
-
|
265
|
-
if(c._re_extends[method]){
|
266
|
-
return c._re_extends[method].apply(this, a);
|
267
|
-
}
|
268
|
-
|
269
|
-
if(c._re_inherits[method]){
|
270
|
-
return c._re_inherits[method].apply(this, a);
|
271
|
-
}
|
272
|
-
|
273
|
-
return this;
|
274
|
-
}
|
275
|
-
|
276
|
-
/*
|
277
|
-
TODO extend has to multiple item query
|
278
|
-
|
279
|
-
//returns true if both present
|
280
|
-
this.has('draw update');
|
281
|
-
|
282
|
-
//return true if bitmap not present but has update
|
283
|
-
this.has('update -bitmap');
|
284
|
-
|
285
|
-
//returns true if has asset id and update signal
|
286
|
-
this.has('#asset ^update');
|
287
|
-
|
288
|
-
//expanded
|
289
|
-
this.has({
|
290
|
-
'comp':['draw'],
|
291
|
-
'id':'bob',
|
292
|
-
'signal':['draw'],
|
293
|
-
'not':['update']
|
294
|
-
});
|
295
|
-
*/
|
296
|
-
p.has = function(comp){
|
297
|
-
|
298
|
-
if(typeof comp == 'string'){
|
299
|
-
|
300
|
-
comp = re.query._toObj(comp);
|
301
|
-
}
|
302
|
-
|
303
|
-
comp.comp = comp.comp || [];
|
304
|
-
comp.id = comp.id || '';
|
305
|
-
comp.signal = comp.signal || [];
|
306
|
-
comp.not = comp.not || [];
|
307
|
-
|
308
|
-
//check if entitiy contains the correct components
|
309
|
-
for(p=0; p<comp.comp.length; p++){
|
310
|
-
|
311
|
-
//check if not containing components
|
312
|
-
if(this._re_comps.indexOf(comp.comp[p]) == -1){
|
313
|
-
return false;
|
314
|
-
}
|
315
|
-
}
|
316
|
-
|
317
|
-
//check if entity doesn't contain components
|
318
|
-
for(p=0; p<comp.not.length; p++){
|
319
|
-
if(this._re_comps.indexOf(comp.not[p]) != -1){
|
320
|
-
return false;
|
321
|
-
}
|
322
|
-
}
|
323
|
-
|
324
|
-
var s;
|
325
|
-
//check if entity contains signals
|
326
|
-
for(p=0; p<comp.signal.length; p++){
|
327
|
-
s = comp.signal[p];
|
328
|
-
if(!this._re_signals[s] || this._re_signals[s].length == 0){
|
329
|
-
return false;
|
330
|
-
}
|
331
|
-
}
|
332
|
-
|
333
|
-
if(comp.id != '' && this.id != comp.id){
|
334
|
-
return false;
|
335
|
-
}
|
336
|
-
|
337
|
-
|
338
|
-
return true;
|
339
|
-
};
|
340
|
-
|
341
|
-
/*
|
342
|
-
New way to add signals version 0.2.1.
|
343
|
-
|
344
|
-
//single
|
345
|
-
addSignal('draw', function(){});
|
346
|
-
|
347
|
-
//multiple
|
348
|
-
addSignal({
|
349
|
-
|
350
|
-
draw:function(){},
|
351
|
-
|
352
|
-
update:function(){}
|
353
|
-
|
354
|
-
});
|
355
|
-
*/
|
356
|
-
p.addSignal = function(type, method){
|
357
|
-
|
358
|
-
if(typeof type == 'object'){
|
359
|
-
|
360
|
-
for(var k in type){
|
361
|
-
this.addSignal(k, type[k]);
|
362
|
-
}
|
363
|
-
|
364
|
-
} else {
|
365
|
-
|
366
|
-
if(!this._re_signals[type]){
|
367
|
-
this._re_signals[type] = [];
|
368
|
-
}
|
369
|
-
|
370
|
-
this._re_signals[type].push(method);
|
371
|
-
|
372
|
-
}
|
373
|
-
|
374
|
-
return this;
|
375
|
-
};
|
376
|
-
|
377
|
-
/*
|
378
|
-
Added in V0.2.1
|
379
|
-
|
380
|
-
//remove single
|
381
|
-
removeSignal('draw', this.draw);
|
382
|
-
|
383
|
-
//remove multiple
|
384
|
-
removeSignal({
|
385
|
-
|
386
|
-
draw:this.draw,
|
387
|
-
update:this.update
|
388
|
-
|
389
|
-
});
|
390
|
-
*/
|
391
|
-
p.removeSignal = function(type, method){
|
392
|
-
|
393
|
-
if(typeof type == 'object'){
|
394
|
-
|
395
|
-
for(var k in type){
|
396
|
-
this.removeSignal(k, type[k]);
|
397
|
-
}
|
398
|
-
|
399
|
-
} else {
|
400
|
-
|
401
|
-
if(typeof method == 'function'){
|
402
|
-
|
403
|
-
for(var k in this._re_signals[type]){
|
404
|
-
|
405
|
-
if(this._re_signals[type][k] == method){
|
406
|
-
this._re_signals[type].splice(k, 1);
|
407
|
-
}
|
408
|
-
|
409
|
-
}
|
410
|
-
} else {
|
411
|
-
|
412
|
-
//no method was passed. Remove all signals
|
413
|
-
this._re_signals[type] = [];
|
414
|
-
|
415
|
-
}
|
416
|
-
}
|
417
|
-
|
418
|
-
return this;
|
419
|
-
};
|
420
|
-
|
421
|
-
/*
|
422
|
-
Signal dispatches events to entities.
|
423
|
-
Modified V0.2.1
|
424
|
-
|
425
|
-
|
426
|
-
-dispatch signals
|
427
|
-
this.signal('click');
|
428
|
-
this.signal('click draw');
|
429
|
-
this.signal('click', {data:0});
|
430
|
-
|
431
|
-
*/
|
432
|
-
p.signal = function(type){
|
433
|
-
|
434
|
-
if(!this._re_signals[type]) return this;
|
435
|
-
var b;
|
436
|
-
|
437
|
-
for(var i=0, l = this._re_signals[type].length; i<l; i++){
|
438
|
-
|
439
|
-
b = this._re_signals[type];
|
440
|
-
|
441
|
-
if(!b[i]) continue;
|
442
|
-
|
443
|
-
//return false remove?
|
444
|
-
if(b[i].apply( (b[i].c)?b[i].c : this , Array.prototype.slice.call(arguments, 1)) === false){
|
445
|
-
b.splice(i, 1);
|
446
|
-
}
|
447
|
-
|
448
|
-
}
|
449
|
-
|
450
|
-
return this;
|
451
|
-
};
|
452
|
-
|
453
|
-
p.extend = function(obj, value){
|
454
|
-
var a = typeof obj;
|
455
|
-
if(a == 'object'){
|
456
|
-
|
457
|
-
for(var key in obj){
|
458
|
-
if(!obj.hasOwnProperty(key)) continue;
|
459
|
-
|
460
|
-
this.extend(key, obj[key]);
|
461
|
-
}
|
462
|
-
|
463
|
-
}else {
|
464
|
-
//extend property
|
465
|
-
|
466
|
-
this[obj] = value;
|
467
|
-
}
|
468
|
-
|
469
|
-
return this;
|
470
|
-
}
|
471
|
-
|
472
|
-
p.inherit = function(obj, value){
|
473
|
-
|
474
|
-
if(typeof obj == 'object'){
|
475
|
-
|
476
|
-
for(var key in obj){
|
477
|
-
if(!obj.hasOwnProperty(key)) continue;
|
478
|
-
|
479
|
-
this.inherit(key, obj[key]);
|
480
|
-
|
481
|
-
}
|
482
|
-
|
483
|
-
} else {
|
484
|
-
//extend property
|
485
|
-
|
486
|
-
if(!this.hasOwnProperty(obj) || typeof this[obj] != typeof value){
|
487
|
-
|
488
|
-
this[obj] = value;
|
489
|
-
|
490
|
-
}
|
491
|
-
}
|
492
|
-
|
493
|
-
return this;
|
494
|
-
}
|
495
|
-
|
496
|
-
p.dispose = function(){
|
497
|
-
//delete from global array
|
498
|
-
re._e.splice(re._e.indexOf(this), 1);
|
499
|
-
|
500
|
-
for(var i in this._re_comps){
|
501
|
-
var k = re.c(this._re_comps[i]);
|
502
|
-
if(k._re_dispose){
|
503
|
-
k._re_dispose.call(this, k);
|
504
|
-
}
|
505
|
-
k.signal('dispose', this);
|
506
|
-
}
|
507
|
-
|
508
|
-
this.signal('dispose');
|
509
|
-
|
510
|
-
return this;
|
511
|
-
}
|
512
|
-
|
513
|
-
re.entity = re.e = q;
|
514
|
-
re.entity.init = e;
|
515
|
-
|
516
|
-
}(re));
|
data/src/entityjs/core/load.js
DELETED
@@ -1,224 +0,0 @@
|
|
1
|
-
(function(re){
|
2
|
-
|
3
|
-
var b = function(assets){
|
4
|
-
return new re.load.init(assets);
|
5
|
-
}
|
6
|
-
|
7
|
-
b.path = "";
|
8
|
-
|
9
|
-
b.imageExt = 'img';
|
10
|
-
b.soundExt = 'sfx';
|
11
|
-
b.images = ['gif', 'jpg', 'jpeg', 'png'];
|
12
|
-
b.sounds = ['wav', 'mp3', 'aac', 'ogg'];
|
13
|
-
|
14
|
-
/*
|
15
|
-
Loads images, sounds and other files into components.
|
16
|
-
|
17
|
-
All loaded assets will be put into a component with a ref to the asset.
|
18
|
-
|
19
|
-
//example of loading assets
|
20
|
-
re.load('tiles.png add.js attack.mp3')
|
21
|
-
.complete(function(arrayOfAssets){
|
22
|
-
//create new bitmap of tiles.png
|
23
|
-
re.e('bitmap tiles.png');
|
24
|
-
|
25
|
-
//new sound
|
26
|
-
re.e('sound attack.mp3');
|
27
|
-
|
28
|
-
//access image staticaly or localy
|
29
|
-
re.comp('tiles.png').image;
|
30
|
-
re.entity('tiles.png').image;
|
31
|
-
|
32
|
-
})
|
33
|
-
.error(function(assetThatCausedError){
|
34
|
-
//error
|
35
|
-
})
|
36
|
-
.progress(function(current, total, assetLoaded){
|
37
|
-
//called on loads
|
38
|
-
});
|
39
|
-
|
40
|
-
@warning only supports loading images and sounds
|
41
|
-
|
42
|
-
//load sound
|
43
|
-
|
44
|
-
//re.support will return the supported codec
|
45
|
-
re.load('run.'+re.support('ogg', 'aac'));
|
46
|
-
|
47
|
-
FUTURE remove directories from calls
|
48
|
-
|
49
|
-
*/
|
50
|
-
var l = function(assets){
|
51
|
-
|
52
|
-
if(typeof assets == 'string'){
|
53
|
-
this.assets = assets.split(' ');
|
54
|
-
} else {
|
55
|
-
this.assets = assets;
|
56
|
-
}
|
57
|
-
|
58
|
-
var a;
|
59
|
-
for(var i=0; i<this.assets.length; i++){
|
60
|
-
|
61
|
-
this.total++;
|
62
|
-
|
63
|
-
a = this.assets[i];
|
64
|
-
|
65
|
-
//find file extension
|
66
|
-
var j = a.lastIndexOf('.')+1;
|
67
|
-
var ext = a.substr(j).toLowerCase();
|
68
|
-
|
69
|
-
//copy full source path
|
70
|
-
var s = a;
|
71
|
-
|
72
|
-
//remove directories
|
73
|
-
var d = a.lastIndexOf('/');
|
74
|
-
if(d != -1){
|
75
|
-
a = a.substr(d+1, a.length);
|
76
|
-
}
|
77
|
-
|
78
|
-
//find name
|
79
|
-
var n = a.substr(0, j);
|
80
|
-
|
81
|
-
if(re.load.images.indexOf(ext) != -1){
|
82
|
-
|
83
|
-
this._loadImg(s, a, n);
|
84
|
-
|
85
|
-
} else if(re.load.sounds.indexOf(ext) != -1){
|
86
|
-
|
87
|
-
//check if support component exists first
|
88
|
-
if(!re.support || re.support(ext)){
|
89
|
-
this._loadSound(s, a, n);
|
90
|
-
}
|
91
|
-
|
92
|
-
}
|
93
|
-
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
return this;
|
98
|
-
}
|
99
|
-
|
100
|
-
var p = l.prototype;
|
101
|
-
|
102
|
-
p.current = 0;
|
103
|
-
p.total = 0;
|
104
|
-
|
105
|
-
p._loadImg = function(src, a, n){
|
106
|
-
|
107
|
-
var that = this;
|
108
|
-
var img = new Image();
|
109
|
-
|
110
|
-
//create new image component
|
111
|
-
re.c(a)
|
112
|
-
.alias(n+re.load.imgExt)
|
113
|
-
.global({
|
114
|
-
bitmap:img
|
115
|
-
})
|
116
|
-
.extend({
|
117
|
-
//save image for other components to copy or use
|
118
|
-
bitmap:img
|
119
|
-
});
|
120
|
-
|
121
|
-
img.onload = function(){
|
122
|
-
|
123
|
-
re.c(a).extend({
|
124
|
-
|
125
|
-
bisect:img.width,
|
126
|
-
sizeX:img.width,
|
127
|
-
sizeY:img.height
|
128
|
-
});
|
129
|
-
|
130
|
-
that.current++;
|
131
|
-
|
132
|
-
if(that._p){
|
133
|
-
that._p.call(that, that.current, that.total, a);
|
134
|
-
}
|
135
|
-
|
136
|
-
if(that.current >= that.total){
|
137
|
-
|
138
|
-
if(that._s){
|
139
|
-
that._s.call(that, that.assets);
|
140
|
-
}
|
141
|
-
|
142
|
-
}
|
143
|
-
};
|
144
|
-
|
145
|
-
img.onerror = function(){
|
146
|
-
|
147
|
-
if(that._e){
|
148
|
-
that._e.call(that, a);
|
149
|
-
}
|
150
|
-
|
151
|
-
};
|
152
|
-
|
153
|
-
img.src = re.load.path+src;
|
154
|
-
|
155
|
-
return this;
|
156
|
-
}
|
157
|
-
|
158
|
-
p._loadSound = function(src, a, n){
|
159
|
-
var that = this;
|
160
|
-
|
161
|
-
var s = new Audio(re.load.path+src);
|
162
|
-
s.preload = "auto";
|
163
|
-
s.load();
|
164
|
-
|
165
|
-
re.c(a)
|
166
|
-
//create global codec for easy use
|
167
|
-
.alias(n+re.load.soundExt)
|
168
|
-
.global({
|
169
|
-
sound:s
|
170
|
-
})
|
171
|
-
.extend({
|
172
|
-
sound:s
|
173
|
-
});
|
174
|
-
|
175
|
-
s.addEventListener('canplaythrough',function(){
|
176
|
-
that.current++;
|
177
|
-
|
178
|
-
if(that._p){
|
179
|
-
that._p.call(that, that.current, that.total, a);
|
180
|
-
}
|
181
|
-
|
182
|
-
if(that.current >= that.total){
|
183
|
-
if(that._s){
|
184
|
-
that._s.call(that, that.assets);
|
185
|
-
}
|
186
|
-
|
187
|
-
}
|
188
|
-
|
189
|
-
},false);
|
190
|
-
|
191
|
-
s.addEventListener('error',function(){
|
192
|
-
|
193
|
-
if(that._e){
|
194
|
-
that._e.call(that, a);
|
195
|
-
}
|
196
|
-
},false);
|
197
|
-
|
198
|
-
}
|
199
|
-
|
200
|
-
p.progress = function(m){
|
201
|
-
|
202
|
-
this._p = m;
|
203
|
-
|
204
|
-
return this;
|
205
|
-
}
|
206
|
-
|
207
|
-
p.complete = function(m){
|
208
|
-
|
209
|
-
this._s = m;
|
210
|
-
|
211
|
-
return this;
|
212
|
-
}
|
213
|
-
|
214
|
-
p.error = function(m){
|
215
|
-
|
216
|
-
this._e = m;
|
217
|
-
|
218
|
-
return this;
|
219
|
-
}
|
220
|
-
|
221
|
-
re.load = b;
|
222
|
-
re.load.init = l;
|
223
|
-
|
224
|
-
}(re));
|