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
@@ -0,0 +1,324 @@
|
|
1
|
+
describe('entity', function(){
|
2
|
+
|
3
|
+
var e;
|
4
|
+
var c;
|
5
|
+
|
6
|
+
beforeEach(function(){
|
7
|
+
e = re.e()
|
8
|
+
c = re.c(f('name'))
|
9
|
+
});
|
10
|
+
|
11
|
+
it('multiple', function(){
|
12
|
+
eq(re.e('bob', 10).length, 10);
|
13
|
+
eq(re.e('ki', 2).comps(), ['ki']);
|
14
|
+
|
15
|
+
});
|
16
|
+
|
17
|
+
it('should create 1 in query', function(){
|
18
|
+
eq(re.e('dfggggg', 1).length, 1)
|
19
|
+
|
20
|
+
eq(re('dfggggg').length, 1)
|
21
|
+
})
|
22
|
+
|
23
|
+
it('comp', function(){
|
24
|
+
e.comp('qwdqwd wer')
|
25
|
+
|
26
|
+
ok(e.has('qwdqwd wer'))
|
27
|
+
|
28
|
+
e.comp(['yep45', 'ok12'])
|
29
|
+
ok(e.has('yep45 ok12'))
|
30
|
+
})
|
31
|
+
|
32
|
+
it('should define properly', function(){
|
33
|
+
re.c('blah1')
|
34
|
+
.defines({
|
35
|
+
f:function(){
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
});
|
39
|
+
|
40
|
+
re.c('sdfdff')
|
41
|
+
.requires('blah1')
|
42
|
+
.defines({
|
43
|
+
f:function(){
|
44
|
+
return true;
|
45
|
+
}
|
46
|
+
});
|
47
|
+
|
48
|
+
ok(re.e('sdfdff').f())
|
49
|
+
})
|
50
|
+
|
51
|
+
it('should call init', function(){
|
52
|
+
var called = false
|
53
|
+
var v1, v2;
|
54
|
+
c.init(function(comp, val1, val2){
|
55
|
+
called = true
|
56
|
+
v1 = val1
|
57
|
+
v2 = val2
|
58
|
+
})
|
59
|
+
var called2 = false
|
60
|
+
c.on('init', function(y){
|
61
|
+
called2 = true
|
62
|
+
ok(y == e)
|
63
|
+
})
|
64
|
+
e.comp(c.name+':10:99')
|
65
|
+
|
66
|
+
//future?
|
67
|
+
//e.comp(c.name, 10, 99)
|
68
|
+
|
69
|
+
ok(called)
|
70
|
+
eq(v1, '10')
|
71
|
+
eq(v2, '99')
|
72
|
+
ok(called2)
|
73
|
+
})
|
74
|
+
|
75
|
+
it('requires', function(){
|
76
|
+
c.requires('bob')
|
77
|
+
c.requires(['bob2'])
|
78
|
+
|
79
|
+
e.comp(c.name)
|
80
|
+
|
81
|
+
ok(e.has('bob bob2'))
|
82
|
+
})
|
83
|
+
|
84
|
+
it('comp defaults', function(){
|
85
|
+
c.defaults({ok:10, b:99})
|
86
|
+
c.defaults('yep', 'y')
|
87
|
+
|
88
|
+
e.ok = 'same'
|
89
|
+
e.comp(c.name)
|
90
|
+
|
91
|
+
eq(e.ok, 'same')
|
92
|
+
eq(e.b, 99)
|
93
|
+
eq(e.yep, 'y')
|
94
|
+
})
|
95
|
+
|
96
|
+
it('comp defines', function(){
|
97
|
+
c.defines({ok:10, b:99})
|
98
|
+
c.defines('yep', 'y')
|
99
|
+
|
100
|
+
e.comp(c.name)
|
101
|
+
|
102
|
+
eq(e.ok, 10)
|
103
|
+
eq(e.b, 99)
|
104
|
+
eq(e.yep, 'y')
|
105
|
+
})
|
106
|
+
|
107
|
+
it('comp interface', function(){
|
108
|
+
re.c('temp')
|
109
|
+
.interfaces('yep');
|
110
|
+
|
111
|
+
try {
|
112
|
+
re.e('temp');
|
113
|
+
}catch(e){
|
114
|
+
eq(e, 'Interface: yep missing')
|
115
|
+
}
|
116
|
+
})
|
117
|
+
|
118
|
+
it('comp asserts', function(){
|
119
|
+
c
|
120
|
+
.asserts('yep');
|
121
|
+
|
122
|
+
try {
|
123
|
+
re.e(c.name+' yep');
|
124
|
+
}catch(e){
|
125
|
+
eq(e, 'Assert: yep is not allowed')
|
126
|
+
}
|
127
|
+
})
|
128
|
+
|
129
|
+
it('removeComp', function(){
|
130
|
+
var called = false
|
131
|
+
c.dispose(function(){
|
132
|
+
called = true
|
133
|
+
})
|
134
|
+
var called2 = false
|
135
|
+
var en = null
|
136
|
+
c.on('dispose', function(y){
|
137
|
+
called2 = true
|
138
|
+
en = y
|
139
|
+
})
|
140
|
+
|
141
|
+
e.comp(c.name)
|
142
|
+
|
143
|
+
e.removeComp(c.name)
|
144
|
+
not(e.has(c.name))
|
145
|
+
ok(called)
|
146
|
+
ok(called2)
|
147
|
+
ok(en == e)
|
148
|
+
})
|
149
|
+
|
150
|
+
it('comps', function(){
|
151
|
+
e.comp('ok bob')
|
152
|
+
|
153
|
+
eq(e.comps(), ['ok', 'bob'])
|
154
|
+
})
|
155
|
+
|
156
|
+
it('clone', function(){
|
157
|
+
e.comp('yep bob')
|
158
|
+
eq(e.clone().comps(), e.comps())
|
159
|
+
eq(e.clone(2).comps(), e.comps())
|
160
|
+
})
|
161
|
+
|
162
|
+
it('parent', function(){
|
163
|
+
c.defines('d', function(v){return v; })
|
164
|
+
.defaults('y', function(v){return v;})
|
165
|
+
|
166
|
+
eq(e.parent(c.name, 'd', 100), 100)
|
167
|
+
eq(e.parent(c.name, 'y', 'bob'), 'bob')
|
168
|
+
e.comp(c.name)
|
169
|
+
ok(e.parent('', 'has', c.name))
|
170
|
+
})
|
171
|
+
|
172
|
+
it('should throw error on undefined parent method', function(){
|
173
|
+
var called = false;
|
174
|
+
try {
|
175
|
+
e.parent('image', 'asdfsdf')
|
176
|
+
} catch(e){
|
177
|
+
called = true;
|
178
|
+
}
|
179
|
+
ok(called)
|
180
|
+
})
|
181
|
+
|
182
|
+
it('has', function(){
|
183
|
+
ok(e.has('!bob'))
|
184
|
+
ok(!e.has('^sig'))
|
185
|
+
not(e.has('#asdsd'))
|
186
|
+
not(e.has('sdcsdc'))
|
187
|
+
|
188
|
+
e.on('values', function(){})
|
189
|
+
ok(e.has('^values'))
|
190
|
+
|
191
|
+
e.comp('tst')
|
192
|
+
ok(e.has('tst'))
|
193
|
+
ok(e.has('tst ^values'))
|
194
|
+
e.id = 'we'
|
195
|
+
ok(e.has('#we'))
|
196
|
+
not(e.has('!tst'))
|
197
|
+
|
198
|
+
ok(e.has('^values tst #we'))
|
199
|
+
})
|
200
|
+
|
201
|
+
it('bindings', function(){
|
202
|
+
var called = false, va, va2
|
203
|
+
e.on('values', function(v, v2){
|
204
|
+
called = true
|
205
|
+
va = v
|
206
|
+
va2 = v2
|
207
|
+
return false
|
208
|
+
});
|
209
|
+
|
210
|
+
ok(e.has('^values'))
|
211
|
+
eq(e.trigger('values', 10, 55),e)
|
212
|
+
ok(called)
|
213
|
+
eq(va, 10)
|
214
|
+
eq(va2, 55)
|
215
|
+
not(e.has('^values'))
|
216
|
+
|
217
|
+
var func = function(){};
|
218
|
+
e.on({
|
219
|
+
yep:function(){},
|
220
|
+
ok:func
|
221
|
+
})
|
222
|
+
ok(e.has('^yep'))
|
223
|
+
e.off('yep')
|
224
|
+
not(e.has('^yep'))
|
225
|
+
|
226
|
+
ok(e.has('^ok'))
|
227
|
+
e.off({ok:func})
|
228
|
+
not(e.has('^ok'))
|
229
|
+
|
230
|
+
//remove all
|
231
|
+
e.on('key', function(){});
|
232
|
+
is(e.off());
|
233
|
+
eq(e._re_signals, {});
|
234
|
+
})
|
235
|
+
|
236
|
+
it('should add multiple bindings', function(){
|
237
|
+
|
238
|
+
var called = false;
|
239
|
+
var called2 = false;
|
240
|
+
|
241
|
+
e.on({
|
242
|
+
call:function(){called = true},
|
243
|
+
call2:function(){called2 = true}
|
244
|
+
});
|
245
|
+
|
246
|
+
e.trigger('call');
|
247
|
+
e.trigger('call2');
|
248
|
+
|
249
|
+
ok(called)
|
250
|
+
ok(called2)
|
251
|
+
|
252
|
+
})
|
253
|
+
|
254
|
+
it('attr', function(){
|
255
|
+
//add attributes
|
256
|
+
e.attr({x:10, y:'sdd', func:function(){}})
|
257
|
+
|
258
|
+
eq(e.x, 10)
|
259
|
+
eq(e.y, 'sdd')
|
260
|
+
is(e.func, 'function')
|
261
|
+
|
262
|
+
e.attr('ok', 87)
|
263
|
+
eq(e.ok, 87)
|
264
|
+
|
265
|
+
//run setter methods
|
266
|
+
e.posX = function(value1){
|
267
|
+
this.val = value1;
|
268
|
+
};
|
269
|
+
|
270
|
+
e.attr('posX', 154)
|
271
|
+
eq(e.val, 154)
|
272
|
+
|
273
|
+
//multiple
|
274
|
+
e.size = function(width, height){
|
275
|
+
this.width = width
|
276
|
+
this.height = height
|
277
|
+
};
|
278
|
+
e.attr({
|
279
|
+
size:[45, 40]
|
280
|
+
});
|
281
|
+
|
282
|
+
eq(e.width, 45)
|
283
|
+
eq(e.height, 40)
|
284
|
+
})
|
285
|
+
|
286
|
+
it('def', function(){
|
287
|
+
e.first = 99
|
288
|
+
e.def('first', 10)
|
289
|
+
eq(e.first, 99)
|
290
|
+
|
291
|
+
e.def({ok:10, yep:99});
|
292
|
+
eq(e.ok, 10)
|
293
|
+
eq(e.yep, 99)
|
294
|
+
})
|
295
|
+
|
296
|
+
it('dispose', function(){
|
297
|
+
var called = false
|
298
|
+
var co;
|
299
|
+
var en;
|
300
|
+
var called2 = false;
|
301
|
+
c.dispose(function(comp){
|
302
|
+
called = true
|
303
|
+
co = comp
|
304
|
+
})
|
305
|
+
c.on('dispose', function(e){
|
306
|
+
called2 = true
|
307
|
+
en = e
|
308
|
+
})
|
309
|
+
e.comp(c.name)
|
310
|
+
var called3 = false
|
311
|
+
e.on('dispose', function(){
|
312
|
+
called3 = true
|
313
|
+
});
|
314
|
+
|
315
|
+
e.dispose()
|
316
|
+
|
317
|
+
ok(called)
|
318
|
+
eq(co, c)
|
319
|
+
ok(called2)
|
320
|
+
eq(en, e)
|
321
|
+
ok(called3)
|
322
|
+
})
|
323
|
+
|
324
|
+
})
|
@@ -0,0 +1,71 @@
|
|
1
|
+
describe('load', function(){
|
2
|
+
|
3
|
+
it('load', function(){
|
4
|
+
//add images
|
5
|
+
re.load.path = '__spec__/'
|
6
|
+
var img = 'helpers/accept.png'
|
7
|
+
var sfx = 'helpers/alligator.mp3'
|
8
|
+
var sfx2 = 'helpers/alligator.ogg'
|
9
|
+
|
10
|
+
var called = false
|
11
|
+
var prog = false
|
12
|
+
|
13
|
+
re.load([img, sfx, sfx2])
|
14
|
+
.complete(function(assets){
|
15
|
+
called = true
|
16
|
+
is(assets, 'array')
|
17
|
+
ok(prog)
|
18
|
+
is(re.c('accept.png').image)
|
19
|
+
|
20
|
+
is(re.c('accept.img').image)
|
21
|
+
is(re.c('alligator.sfx').sound)
|
22
|
+
|
23
|
+
var b = re.e('accept.png')
|
24
|
+
is(b._image)
|
25
|
+
eq(b.sizeX, b._image.width)
|
26
|
+
eq(b.sizeY, b._image.height)
|
27
|
+
eq(b.bisect, b._image.width)
|
28
|
+
|
29
|
+
b = re.e('alligator.sfx')
|
30
|
+
is(b._sound)
|
31
|
+
})
|
32
|
+
.progress(function(current, total, name){
|
33
|
+
prog = true
|
34
|
+
is(name, 'string')
|
35
|
+
is(current, 'number')
|
36
|
+
is(total, 'number')
|
37
|
+
})
|
38
|
+
.error(function(){
|
39
|
+
ok(false)
|
40
|
+
})
|
41
|
+
|
42
|
+
waits(500)
|
43
|
+
runs(function(){
|
44
|
+
ok(called)
|
45
|
+
})
|
46
|
+
});
|
47
|
+
|
48
|
+
it('should call complete on empty load', function(){
|
49
|
+
var called = false
|
50
|
+
re.load([])
|
51
|
+
.complete(function(){
|
52
|
+
called = true
|
53
|
+
});
|
54
|
+
ok(called)
|
55
|
+
});
|
56
|
+
|
57
|
+
it('should throw error on not found image', function(){
|
58
|
+
var called = false
|
59
|
+
|
60
|
+
re.load('sdfsdf.png')
|
61
|
+
.error(function(e){
|
62
|
+
called = true
|
63
|
+
})
|
64
|
+
|
65
|
+
waits(200)
|
66
|
+
runs(function(){
|
67
|
+
ok(called)
|
68
|
+
})
|
69
|
+
});
|
70
|
+
|
71
|
+
});
|
@@ -0,0 +1,157 @@
|
|
1
|
+
describe('query', function(){
|
2
|
+
|
3
|
+
it('should query', function(){
|
4
|
+
re.e('tesee');
|
5
|
+
re.e('tesee bob99');
|
6
|
+
|
7
|
+
eq(re('bob99 tesee').length, 1);
|
8
|
+
eq(re('tesee').length, 2);
|
9
|
+
|
10
|
+
re.e('tesee ttt')
|
11
|
+
eq(re('tesee').length, 3);
|
12
|
+
eq(re('tesee !ttt').length, 2);
|
13
|
+
|
14
|
+
re.e('tesee').on('sig', function(){});
|
15
|
+
eq(re('tesee ^sig').length, 1);
|
16
|
+
|
17
|
+
re.e('tesee').attr('id', 'id');
|
18
|
+
ok(re('tesee').length != 0);
|
19
|
+
eq(re('#id').length, 1);
|
20
|
+
});
|
21
|
+
|
22
|
+
it('should be right length', function(){
|
23
|
+
var g = f('name')
|
24
|
+
re.e(g)
|
25
|
+
eq(re(g).length, 1)
|
26
|
+
});
|
27
|
+
|
28
|
+
it('should select *', function(){
|
29
|
+
var c = re._e.length;
|
30
|
+
eq(re('*').length, c);
|
31
|
+
});
|
32
|
+
|
33
|
+
it('should filter', function(){
|
34
|
+
re.e().attr({k:99});
|
35
|
+
|
36
|
+
eq(re(function(){
|
37
|
+
return this.k == 99
|
38
|
+
}).length, 1)
|
39
|
+
});
|
40
|
+
|
41
|
+
it('method', function(){
|
42
|
+
eq(re.e('ok', 3).method('comp', 'b').comps(), ['ok', 'b'])
|
43
|
+
});
|
44
|
+
|
45
|
+
it('each', function(){
|
46
|
+
var i = 0;
|
47
|
+
is(re('dd', 3).each(function(c, l){
|
48
|
+
eq(i++, c);
|
49
|
+
eq(l, 3)
|
50
|
+
}))
|
51
|
+
});
|
52
|
+
|
53
|
+
it('tilemap', function(){
|
54
|
+
|
55
|
+
is(re.e('tile', 10).tilemap(5, function(x, y, i, l){
|
56
|
+
ok(x < 5)
|
57
|
+
ok(y < 2)
|
58
|
+
eq(l, 10)
|
59
|
+
}));
|
60
|
+
|
61
|
+
});
|
62
|
+
|
63
|
+
it('comps', function(){
|
64
|
+
eq(re('tile').comps(), ['tile'])
|
65
|
+
});
|
66
|
+
|
67
|
+
it('random', function(){
|
68
|
+
is(re('tile').random(), 'object')
|
69
|
+
});
|
70
|
+
|
71
|
+
it('pluck', function(){
|
72
|
+
re('tile').attr({f:10, y:'d'});
|
73
|
+
var k = re('tile').pluck('f y');
|
74
|
+
eq(k.length, re('tile').length);
|
75
|
+
eq(k[0].f, re('tile')[0].f);
|
76
|
+
eq(k[0].y, re('tile')[0].y);
|
77
|
+
});
|
78
|
+
|
79
|
+
it('attr', function(){
|
80
|
+
re('tile').attr('first', 'asdf');
|
81
|
+
re('tile').each(function(){
|
82
|
+
eq(this.first, 'asdf')
|
83
|
+
})
|
84
|
+
|
85
|
+
re('tile').attr({yap:'1232'});
|
86
|
+
re('tile').each(function(){
|
87
|
+
eq(this.yap, '1232')
|
88
|
+
})
|
89
|
+
});
|
90
|
+
|
91
|
+
it('def', function(){
|
92
|
+
re('tile').def('first', 'asdf');
|
93
|
+
re('tile').each(function(){
|
94
|
+
eq(this.first, 'asdf')
|
95
|
+
})
|
96
|
+
|
97
|
+
re('tile').def({yap:'1232', first:'d'});
|
98
|
+
re('tile').each(function(){
|
99
|
+
eq(this.yap, '1232')
|
100
|
+
eq(this.first, 'asdf')
|
101
|
+
})
|
102
|
+
|
103
|
+
});
|
104
|
+
|
105
|
+
it('comp', function(){
|
106
|
+
is(re.e('re',3).comp('yy'));
|
107
|
+
|
108
|
+
ok(re('re').has('yy'));
|
109
|
+
});
|
110
|
+
|
111
|
+
it('removeComp', function(){
|
112
|
+
is(re.e('kw gg33', 2).removeComp('gg33'))
|
113
|
+
|
114
|
+
eq(re('gg33').length, 0)
|
115
|
+
});
|
116
|
+
|
117
|
+
it('on', function(){
|
118
|
+
is(re.e('ssss', 1).on('mousedown', function(){}));
|
119
|
+
|
120
|
+
eq(re('ssss ^mousedown').length, 1)
|
121
|
+
});
|
122
|
+
|
123
|
+
it('off', function(){
|
124
|
+
is(re.e('k54',1).on('mouse', function(){}).off());
|
125
|
+
ok(re('k54 ^mouse').length == 0)
|
126
|
+
});
|
127
|
+
|
128
|
+
it('trigger', function(){
|
129
|
+
re.e('g55');
|
130
|
+
var called = null;
|
131
|
+
re('g55').on('bind', function(v){called=v});
|
132
|
+
re('g55').trigger('bind', 'bob');
|
133
|
+
|
134
|
+
eq('bob', called);
|
135
|
+
});
|
136
|
+
|
137
|
+
it('has', function(){
|
138
|
+
var k = re.e('bob ref',2).on('key', function(){});
|
139
|
+
|
140
|
+
ok(k.has('bob'));
|
141
|
+
ok(k.has('ref'));
|
142
|
+
ok(k.has('^key'));
|
143
|
+
ok(k.has('!sddd'));
|
144
|
+
ok(k.has('bob ref ^key !sddd'));
|
145
|
+
|
146
|
+
//empty query should always return false
|
147
|
+
not(re().has('ok'))
|
148
|
+
|
149
|
+
not(re.e('sdf',2).has('^wef'));
|
150
|
+
});
|
151
|
+
|
152
|
+
it('dispose', function(){
|
153
|
+
is(re.e('rgfdvdvdfv', 2).dispose());
|
154
|
+
eq(re('rgfdvdvdfv').length, 0);
|
155
|
+
});
|
156
|
+
|
157
|
+
})
|
@@ -0,0 +1,61 @@
|
|
1
|
+
describe('re', function(){
|
2
|
+
|
3
|
+
re.e('queryre')
|
4
|
+
|
5
|
+
it('should query', function(){
|
6
|
+
eq(re('queryre').length, 1)
|
7
|
+
})
|
8
|
+
|
9
|
+
it('should get element by id', function(){
|
10
|
+
setup_canvas()
|
11
|
+
|
12
|
+
is(re.$('#game-canvas'))
|
13
|
+
is(re.$('#game-canvas'))
|
14
|
+
is(re.$('#game-canvas'))
|
15
|
+
|
16
|
+
teardown_canvas()
|
17
|
+
})
|
18
|
+
|
19
|
+
it('should get element by tag', function(){
|
20
|
+
setup_canvas()
|
21
|
+
|
22
|
+
is(re.$('canvas'))
|
23
|
+
is(re.$('canvas'))
|
24
|
+
is(re.$('canvas'))
|
25
|
+
|
26
|
+
teardown_canvas()
|
27
|
+
})
|
28
|
+
|
29
|
+
it('should create element', function(){
|
30
|
+
is(re.$new('canvas'), 'htmlcanvaselement')
|
31
|
+
})
|
32
|
+
|
33
|
+
it('should re.is work', function(){
|
34
|
+
ok(re.is({}))
|
35
|
+
ok(re.is(1))
|
36
|
+
ok(re.is(1, 'Number'))
|
37
|
+
|
38
|
+
not(re.is(null))
|
39
|
+
not(re.is(undefined))
|
40
|
+
|
41
|
+
not(re.is(null, 'array'))
|
42
|
+
not(re.is(1, 'string'))
|
43
|
+
not(re.is('', 'number'))
|
44
|
+
not(re.is('', 'Number'))
|
45
|
+
|
46
|
+
ok(re.is('', 'string'))
|
47
|
+
ok(re.is(1, 'number'))
|
48
|
+
ok(re.is([], 'array'))
|
49
|
+
ok(re.is(/sd/, 'regexp'))
|
50
|
+
ok(re.is(re.$new('canvas'), 'htmlcanvaselement'))
|
51
|
+
var k = {};
|
52
|
+
ok(re.is(k, 'object'))
|
53
|
+
var f = function(){};
|
54
|
+
ok(re.is(f, 'function'))
|
55
|
+
})
|
56
|
+
|
57
|
+
it('should define indexof', function(){
|
58
|
+
is(Array.prototype.indexOf, 'function')
|
59
|
+
})
|
60
|
+
|
61
|
+
})
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe('system', function(){
|
2
|
+
|
3
|
+
var s;
|
4
|
+
|
5
|
+
it('init', function(){
|
6
|
+
|
7
|
+
is(re.sys.context);
|
8
|
+
});
|
9
|
+
|
10
|
+
it('clear', function(){
|
11
|
+
var s = re.sys;
|
12
|
+
is(re.sys.start());
|
13
|
+
|
14
|
+
spyOn(s.context, 'fillRect');
|
15
|
+
|
16
|
+
is(s.clear('#FF0000'));
|
17
|
+
called(s.context.fillRect);
|
18
|
+
|
19
|
+
is(s.clear('rgb(200, 0, 0)'));
|
20
|
+
called(s.context.fillRect);
|
21
|
+
|
22
|
+
is(s.clear());
|
23
|
+
|
24
|
+
is(s.stop());
|
25
|
+
});
|
26
|
+
|
27
|
+
it('loop', function(){
|
28
|
+
var called = false;
|
29
|
+
var old = re.sys.system_loop;
|
30
|
+
//setup custom loop
|
31
|
+
re.sys
|
32
|
+
.loop(function(){
|
33
|
+
called = true;
|
34
|
+
}).start().stop();
|
35
|
+
|
36
|
+
re.sys.loop(old)
|
37
|
+
|
38
|
+
ok(called);
|
39
|
+
});
|
40
|
+
|
41
|
+
});
|