entityjs 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/lib/entityjs/config.rb +4 -4
- data/lib/entityjs/dirc.rb +2 -2
- data/lib/entityjs/page.rb +7 -1
- data/lib/entityjs/version.rb +1 -1
- data/public/qunit/qunit.entity.js +27 -12
- data/spec/javascripts/src/core/comp_spec.js +11 -0
- data/spec/javascripts/src/core/entity_spec.js +88 -5
- data/spec/javascripts/src/core/query_spec.js +196 -15
- data/spec/javascripts/src/cycle/drawlist_spec.js +36 -0
- data/spec/javascripts/src/cycle/tween_spec.js +1 -1
- data/spec/javascripts/src/cycle/wait_spec.js +31 -0
- data/spec/javascripts/src/{cycle → display}/draw_spec.js +25 -9
- data/spec/javascripts/src/display/sprite_spec.js +18 -0
- data/spec/javascripts/src/display/text_spec.js +8 -0
- data/spec/javascripts/src/input/mouse_spec.js +24 -36
- data/spec/javascripts/src/math/bisect_spec.js +4 -4
- data/spec/javascripts/src/math/distance_spec.js +11 -0
- data/spec/javascripts/src/math/iso_spec.js +131 -0
- data/spec/javascripts/src/math/point_spec.js +3 -3
- data/spec/javascripts/src/{util → math}/random_spec.js +0 -0
- data/spec/javascripts/src/math/range_spec.js +9 -0
- data/spec/javascripts/src/math/tile_spec.js +22 -7
- data/spec/javascripts/src/pattern/automap_spec.js +2 -2
- data/spec/javascripts/src/pattern/flicker_spec.js +34 -22
- data/spec/javascripts/src/pattern/pathfind_spec.js +55 -0
- data/src/core/comp.js +16 -16
- data/src/core/entity.js +52 -51
- data/src/core/load.js +5 -5
- data/src/core/query.js +214 -74
- data/src/core/system.js +16 -6
- data/src/cycle/drawlist.js +79 -0
- data/src/cycle/tween.js +7 -20
- data/src/cycle/wait.js +10 -19
- data/src/{cycle → display}/draw.js +24 -34
- data/src/display/image.js +1 -1
- data/src/display/screen.js +3 -3
- data/src/display/sprite.js +3 -3
- data/src/display/text.js +3 -1
- data/src/input/mouse.js +35 -12
- data/src/math/bisect.js +11 -10
- data/src/math/distance.js +7 -0
- data/src/math/iso.js +147 -0
- data/src/math/point.js +1 -5
- data/src/math/random.js +21 -0
- data/src/math/range.js +14 -0
- data/src/math/tile.js +40 -27
- data/src/pattern/automap.js +12 -11
- data/src/pattern/flicker.js +87 -135
- data/src/pattern/pathfind.js +168 -0
- data/src/pattern/timestep.js +4 -1
- data/src/util/polyfill.js +1 -1
- data/templates/isometric/assets/images/isotiles.png +0 -0
- data/templates/isometric/config.yml +22 -0
- data/templates/isometric/readme.txt +79 -0
- data/templates/isometric/scripts/displays/cursor.js +34 -0
- data/templates/isometric/scripts/displays/isoimage.js +32 -0
- data/templates/isometric/scripts/init.js +7 -0
- data/templates/isometric/scripts/levels/level.js +55 -0
- data/templates/isometric/scripts/levels/level1.js +11 -0
- data/templates/isometric/scripts/scenes/home.js +10 -0
- data/templates/isometric/scripts/scenes/load.js +11 -0
- data/templates/isometric/tests/scenes/load_test.js +15 -0
- metadata +42 -21
- data/src/net/socket.js +0 -52
- data/src/util/random.js +0 -24
data/.gitignore
CHANGED
data/lib/entityjs/config.rb
CHANGED
@@ -54,7 +54,7 @@ module Entityjs
|
|
54
54
|
if @yml.nil?
|
55
55
|
return 500
|
56
56
|
end
|
57
|
-
@yml['width']
|
57
|
+
@yml['width'] || 500
|
58
58
|
end
|
59
59
|
|
60
60
|
def canvas_border
|
@@ -62,14 +62,14 @@ module Entityjs
|
|
62
62
|
return true
|
63
63
|
end
|
64
64
|
|
65
|
-
return @yml['canvas-border']
|
65
|
+
return @yml['canvas-border'] || true
|
66
66
|
end
|
67
67
|
|
68
68
|
def height
|
69
69
|
if @yml.nil?
|
70
70
|
return 400
|
71
71
|
end
|
72
|
-
@yml['height']
|
72
|
+
@yml['height'] || 400
|
73
73
|
end
|
74
74
|
|
75
75
|
def scripts_ignore
|
@@ -121,7 +121,7 @@ module Entityjs
|
|
121
121
|
return 'game-canvas'
|
122
122
|
end
|
123
123
|
|
124
|
-
@yml['canvas-id']
|
124
|
+
@yml['canvas-id'] || 'game-canvas'
|
125
125
|
end
|
126
126
|
|
127
127
|
def license
|
data/lib/entityjs/dirc.rb
CHANGED
data/lib/entityjs/page.rb
CHANGED
@@ -39,7 +39,13 @@ module Entityjs
|
|
39
39
|
protected
|
40
40
|
#defines varaibles on the template htmls for view on webpage
|
41
41
|
def self.set_vars(path, tests=false)
|
42
|
-
|
42
|
+
#search locally first
|
43
|
+
local = Dirc.game_root+'/'+path
|
44
|
+
if File.file? local
|
45
|
+
contents = IO.read(local);
|
46
|
+
else
|
47
|
+
contents = IO.read("#{Entityjs::root}/public/#{path}")
|
48
|
+
end
|
43
49
|
|
44
50
|
#reload config for changes
|
45
51
|
Config.instance.reload
|
data/lib/entityjs/version.rb
CHANGED
@@ -21,10 +21,6 @@ Disable re.ready for testing
|
|
21
21
|
*/
|
22
22
|
re.ready = function(){};
|
23
23
|
|
24
|
-
window.addEventListener('load', function(){
|
25
|
-
re.sys.init(re.canvas).start();
|
26
|
-
}, true);
|
27
|
-
|
28
24
|
/*
|
29
25
|
Expects a trigger call from the given obj.
|
30
26
|
|
@@ -173,17 +169,36 @@ e.has('coin') //true
|
|
173
169
|
var coin2 = f('coin');
|
174
170
|
coin2.value //10
|
175
171
|
|
172
|
+
//create coin with custom factory
|
173
|
+
//still has other defines properties
|
174
|
+
|
175
|
+
var customCoin = f('coin', function(){
|
176
|
+
this.getValue = function(){
|
177
|
+
return this.value;
|
178
|
+
};
|
179
|
+
});
|
180
|
+
|
181
|
+
customCoin.value //10
|
182
|
+
customCoin.getValue(); //10
|
183
|
+
|
176
184
|
*/
|
177
185
|
var _factories = {};
|
178
186
|
function factory(comps, func){
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
+
//define new factory
|
188
|
+
if(func && !_factories[comps]){
|
189
|
+
_factories[comps] = func;
|
190
|
+
|
191
|
+
} else {
|
192
|
+
//create
|
193
|
+
var e = re.e(comps);
|
194
|
+
|
195
|
+
//call defined factory
|
196
|
+
if(_factories[comps]) _factories[comps].call(e);
|
197
|
+
|
198
|
+
//call custom method
|
199
|
+
if(func) func.call(e);
|
200
|
+
return e;
|
201
|
+
}
|
187
202
|
}
|
188
203
|
var f = factory;
|
189
204
|
|
@@ -20,6 +20,17 @@ describe('comp', function(){
|
|
20
20
|
eq(k.yep, 'yep')
|
21
21
|
})
|
22
22
|
|
23
|
+
it('should add events', function(){
|
24
|
+
k.events('mouseup', function(){})
|
25
|
+
k.events({
|
26
|
+
mousedown:function(){}
|
27
|
+
});
|
28
|
+
|
29
|
+
is(k._re_events.mouseup)
|
30
|
+
is(k._re_events.mousedown)
|
31
|
+
|
32
|
+
})
|
33
|
+
|
23
34
|
it('should requires', function(){
|
24
35
|
k
|
25
36
|
.requires('test test2');
|
@@ -29,6 +29,18 @@ describe('entity', function(){
|
|
29
29
|
ok(e.has('yep45 ok12'))
|
30
30
|
})
|
31
31
|
|
32
|
+
it('should add events from comp', function(){
|
33
|
+
var func = function(){
|
34
|
+
|
35
|
+
}
|
36
|
+
c.events('mousedown', func);
|
37
|
+
|
38
|
+
e.comp(c.name);
|
39
|
+
|
40
|
+
ok(e.has('^mousedown'));
|
41
|
+
is(e.mousedown);
|
42
|
+
})
|
43
|
+
|
32
44
|
it('should define properly', function(){
|
33
45
|
re.c('blah1')
|
34
46
|
.defines({
|
@@ -140,7 +152,7 @@ describe('entity', function(){
|
|
140
152
|
|
141
153
|
e.comp(c.name)
|
142
154
|
|
143
|
-
e.removeComp(c.name)
|
155
|
+
e.removeComp(['blah', c.name])
|
144
156
|
not(e.has(c.name))
|
145
157
|
ok(called)
|
146
158
|
ok(called2)
|
@@ -159,6 +171,10 @@ describe('entity', function(){
|
|
159
171
|
eq(e.clone(2).comps(), e.comps())
|
160
172
|
})
|
161
173
|
|
174
|
+
it('should clone empty entity', function(){
|
175
|
+
is(re.e().clone())
|
176
|
+
})
|
177
|
+
|
162
178
|
it('parent', function(){
|
163
179
|
c.defines('d', function(v){return v; })
|
164
180
|
.defaults('y', function(v){return v;})
|
@@ -166,7 +182,45 @@ describe('entity', function(){
|
|
166
182
|
eq(e.parent(c.name, 'd', 100), 100)
|
167
183
|
eq(e.parent(c.name, 'y', 'bob'), 'bob')
|
168
184
|
e.comp(c.name)
|
169
|
-
ok(e.parent('',
|
185
|
+
ok(e.parent('','has', c.name))
|
186
|
+
})
|
187
|
+
|
188
|
+
it('attr overwrite method', function(){
|
189
|
+
|
190
|
+
var called = false;
|
191
|
+
|
192
|
+
e.attr({
|
193
|
+
blah:function(){}
|
194
|
+
});
|
195
|
+
|
196
|
+
e.attr({
|
197
|
+
blah:function(){
|
198
|
+
called = true;
|
199
|
+
}
|
200
|
+
});
|
201
|
+
|
202
|
+
e.blah();
|
203
|
+
|
204
|
+
ok(called);
|
205
|
+
});
|
206
|
+
|
207
|
+
it('should dispose of all components properly', function(){
|
208
|
+
var called = false, called2 = false;
|
209
|
+
|
210
|
+
e.comp('image iso');
|
211
|
+
|
212
|
+
re.c('draw').on('dispose', function(e){
|
213
|
+
called = true;
|
214
|
+
})
|
215
|
+
|
216
|
+
re.c('draw').dispose(function(){
|
217
|
+
called2 = true;
|
218
|
+
})
|
219
|
+
|
220
|
+
e.dispose();
|
221
|
+
ok(called);
|
222
|
+
ok(called2)
|
223
|
+
|
170
224
|
})
|
171
225
|
|
172
226
|
it('should throw error on undefined parent method', function(){
|
@@ -224,8 +278,9 @@ describe('entity', function(){
|
|
224
278
|
not(e.has('^yep'))
|
225
279
|
|
226
280
|
ok(e.has('^ok'))
|
227
|
-
|
228
|
-
|
281
|
+
e.off({ok:func})
|
282
|
+
|
283
|
+
not(e.has('^ok'))
|
229
284
|
|
230
285
|
//remove all
|
231
286
|
e.on('key', function(){});
|
@@ -233,7 +288,25 @@ describe('entity', function(){
|
|
233
288
|
eq(e._re_signals, {});
|
234
289
|
})
|
235
290
|
|
236
|
-
it('should
|
291
|
+
it('should change context of event', function(){
|
292
|
+
|
293
|
+
var obj = {};
|
294
|
+
|
295
|
+
e.on({
|
296
|
+
blah:function(){
|
297
|
+
eq(obj, this);
|
298
|
+
}
|
299
|
+
}, obj);
|
300
|
+
|
301
|
+
e.on('blah2', function(){
|
302
|
+
eq(obj, this);
|
303
|
+
}, obj);
|
304
|
+
|
305
|
+
e.trigger('blah2').trigger('blah');
|
306
|
+
|
307
|
+
});
|
308
|
+
|
309
|
+
it('should add multiple events', function(){
|
237
310
|
|
238
311
|
var called = false;
|
239
312
|
var called2 = false;
|
@@ -298,22 +371,32 @@ describe('entity', function(){
|
|
298
371
|
var co;
|
299
372
|
var en;
|
300
373
|
var called2 = false;
|
374
|
+
|
375
|
+
//listen for dispose call on component
|
301
376
|
c.dispose(function(comp){
|
302
377
|
called = true
|
303
378
|
co = comp
|
304
379
|
})
|
380
|
+
|
381
|
+
//component dispose trigger
|
305
382
|
c.on('dispose', function(e){
|
306
383
|
called2 = true
|
307
384
|
en = e
|
308
385
|
})
|
386
|
+
|
387
|
+
//add comp to testing entity
|
309
388
|
e.comp(c.name)
|
389
|
+
|
310
390
|
var called3 = false
|
391
|
+
//listen for dispose trigger on entity
|
311
392
|
e.on('dispose', function(){
|
312
393
|
called3 = true
|
313
394
|
});
|
314
395
|
|
396
|
+
//call it
|
315
397
|
e.dispose()
|
316
398
|
|
399
|
+
//asserts
|
317
400
|
ok(called)
|
318
401
|
eq(co, c)
|
319
402
|
ok(called2)
|
@@ -1,5 +1,9 @@
|
|
1
1
|
describe('query', function(){
|
2
2
|
|
3
|
+
beforeEach(function(){
|
4
|
+
query = re();
|
5
|
+
})
|
6
|
+
|
3
7
|
it('should query', function(){
|
4
8
|
re.e('tesee');
|
5
9
|
re.e('tesee bob99');
|
@@ -25,6 +29,10 @@ describe('query', function(){
|
|
25
29
|
eq(re(g).length, 1)
|
26
30
|
});
|
27
31
|
|
32
|
+
it('should return empty query', function(){
|
33
|
+
eq(re().length, 0);
|
34
|
+
})
|
35
|
+
|
28
36
|
it('should select *', function(){
|
29
37
|
var c = re._e.length;
|
30
38
|
eq(re('*').length, c);
|
@@ -38,13 +46,24 @@ describe('query', function(){
|
|
38
46
|
}).length, 1)
|
39
47
|
});
|
40
48
|
|
41
|
-
it('
|
42
|
-
|
49
|
+
it('should create query from array', function(){
|
50
|
+
var a = [1,2,3];
|
51
|
+
|
52
|
+
var q = re(a);
|
53
|
+
|
54
|
+
eq(q[0], a[0])
|
55
|
+
eq(q[1], a[1])
|
56
|
+
eq(q[2], a[2])
|
57
|
+
|
58
|
+
})
|
59
|
+
|
60
|
+
it('invoke', function(){
|
61
|
+
eq(re.e('ok', 3).invoke('comp', 'b').comps(), ['ok', 'b'])
|
43
62
|
});
|
44
63
|
|
45
64
|
it('each', function(){
|
46
65
|
var i = 0;
|
47
|
-
is(re('dd', 3).each(function(c, l){
|
66
|
+
is(re('dd', 3).each(function(e, c, l){
|
48
67
|
eq(i++, c);
|
49
68
|
eq(l, 3)
|
50
69
|
}))
|
@@ -52,10 +71,10 @@ describe('query', function(){
|
|
52
71
|
|
53
72
|
it('tilemap', function(){
|
54
73
|
|
55
|
-
is(re.e('tile', 10).tilemap(5, function(x, y, i, l){
|
74
|
+
is(re.e('tile', 10).tilemap(5, function(e, x, y, i, l){
|
56
75
|
ok(x < 5)
|
57
76
|
ok(y < 2)
|
58
|
-
|
77
|
+
is(l)
|
59
78
|
}));
|
60
79
|
|
61
80
|
});
|
@@ -75,29 +94,100 @@ describe('query', function(){
|
|
75
94
|
eq(k[0].f, re('tile')[0].f);
|
76
95
|
eq(k[0].y, re('tile')[0].y);
|
77
96
|
});
|
78
|
-
|
97
|
+
|
98
|
+
it('e', function(){
|
99
|
+
|
100
|
+
var q = re();
|
101
|
+
|
102
|
+
q.e('blah');
|
103
|
+
|
104
|
+
ok(q.last().has('blah'))
|
105
|
+
|
106
|
+
})
|
107
|
+
|
108
|
+
it('should last', function(){
|
109
|
+
var b = re.e();
|
110
|
+
query.last(b);
|
111
|
+
eq(query.last(), b)
|
112
|
+
})
|
113
|
+
|
114
|
+
it('should first', function(){
|
115
|
+
var b = re.e();
|
116
|
+
query.first(b);
|
117
|
+
eq(query.first(), b)
|
118
|
+
|
119
|
+
})
|
120
|
+
|
121
|
+
it('insertAfter', function(){
|
122
|
+
var b = re.e();
|
123
|
+
|
124
|
+
query.last(10, 6);
|
125
|
+
|
126
|
+
query.insertAfter(10, b);
|
127
|
+
|
128
|
+
eq(query.indexOf(b), 1);
|
129
|
+
})
|
130
|
+
|
131
|
+
it('insertBefore', function(){
|
132
|
+
|
133
|
+
var b = re.e();
|
134
|
+
|
135
|
+
query.last(10, 6);
|
136
|
+
|
137
|
+
query.insertBefore(6, b);
|
138
|
+
|
139
|
+
eq(query.indexOf(b), 1);
|
140
|
+
})
|
141
|
+
|
142
|
+
it('swap', function(){
|
143
|
+
query.last(10, 6);
|
144
|
+
|
145
|
+
|
146
|
+
query.swap(10, 6);
|
147
|
+
|
148
|
+
eq(query[0], 6);
|
149
|
+
eq(query[1], 10);
|
150
|
+
})
|
151
|
+
|
152
|
+
it('should erase', function(){
|
153
|
+
|
154
|
+
var q = re();
|
155
|
+
|
156
|
+
var e = re.e();
|
157
|
+
|
158
|
+
q.push(e);
|
159
|
+
|
160
|
+
//add in
|
161
|
+
var n = re.e();
|
162
|
+
|
163
|
+
q.erase(e);
|
164
|
+
|
165
|
+
not(q.include(e))
|
166
|
+
|
167
|
+
})
|
168
|
+
|
79
169
|
it('attr', function(){
|
80
170
|
re('tile').attr('first', 'asdf');
|
81
|
-
re('tile').each(function(){
|
82
|
-
eq(
|
171
|
+
re('tile').each(function(e){
|
172
|
+
eq(e.first, 'asdf')
|
83
173
|
})
|
84
174
|
|
85
175
|
re('tile').attr({yap:'1232'});
|
86
|
-
re('tile').each(function(){
|
87
|
-
eq(
|
176
|
+
re('tile').each(function(e){
|
177
|
+
eq(e.yap, '1232')
|
88
178
|
})
|
89
179
|
});
|
90
180
|
|
91
181
|
it('def', function(){
|
92
182
|
re('tile').def('first', 'asdf');
|
93
|
-
re('tile').each(function(){
|
94
|
-
eq(
|
183
|
+
re('tile').each(function(e){
|
184
|
+
eq(e.first, 'asdf')
|
95
185
|
})
|
96
186
|
|
97
187
|
re('tile').def({yap:'1232', first:'d'});
|
98
|
-
re('tile').each(function(){
|
99
|
-
eq(
|
100
|
-
eq(
|
188
|
+
re('tile').each(function(e){
|
189
|
+
eq(e.yap, '1232')
|
190
|
+
eq(e.first, 'asdf')
|
101
191
|
})
|
102
192
|
|
103
193
|
});
|
@@ -149,6 +239,97 @@ describe('query', function(){
|
|
149
239
|
not(re.e('sdf',2).has('^wef'));
|
150
240
|
});
|
151
241
|
|
242
|
+
it('include', function(){
|
243
|
+
|
244
|
+
var en = re.e();
|
245
|
+
|
246
|
+
var query = re();
|
247
|
+
|
248
|
+
not(query.include(en));
|
249
|
+
|
250
|
+
query.push(en);
|
251
|
+
|
252
|
+
ok(query.include(en));
|
253
|
+
|
254
|
+
})
|
255
|
+
|
256
|
+
it('min', function(){
|
257
|
+
var query = re();
|
258
|
+
|
259
|
+
query.push(0)
|
260
|
+
query.push(10)
|
261
|
+
query.push(2)
|
262
|
+
query.push(5)
|
263
|
+
|
264
|
+
eq(query.min(function(e, i, l){
|
265
|
+
eq(this, 'ok')
|
266
|
+
is(i)
|
267
|
+
is(l)
|
268
|
+
|
269
|
+
return e;
|
270
|
+
|
271
|
+
}, 'ok'), 0)
|
272
|
+
})
|
273
|
+
|
274
|
+
it('max', function(){
|
275
|
+
|
276
|
+
var query = re();
|
277
|
+
|
278
|
+
query.push(0)
|
279
|
+
query.push(10)
|
280
|
+
query.push(2)
|
281
|
+
query.push(5)
|
282
|
+
|
283
|
+
eq(query.max(function(e, i, l){
|
284
|
+
eq(this, 'ok')
|
285
|
+
is(i)
|
286
|
+
is(l)
|
287
|
+
|
288
|
+
return e;
|
289
|
+
|
290
|
+
}, 'ok'), 10)
|
291
|
+
})
|
292
|
+
|
293
|
+
it('find', function(){
|
294
|
+
var e = re();
|
295
|
+
e.push(1);
|
296
|
+
e.push(10);
|
297
|
+
|
298
|
+
//find index with 10
|
299
|
+
eq(e.find(function(t){
|
300
|
+
eq(e, this)
|
301
|
+
return t == 10;
|
302
|
+
}), 10);
|
303
|
+
})
|
304
|
+
|
305
|
+
it('isEmpty', function(){
|
306
|
+
ok(re().isEmpty())
|
307
|
+
})
|
308
|
+
|
309
|
+
it('every', function(){
|
310
|
+
|
311
|
+
//check if all entities in query have value blah
|
312
|
+
var e = re();
|
313
|
+
e.push(re.e());
|
314
|
+
e.push(re.e().attr('blah', true));
|
315
|
+
|
316
|
+
not(e.every(function(e){
|
317
|
+
return e.blah;
|
318
|
+
}));
|
319
|
+
|
320
|
+
e.attr('blah', true)
|
321
|
+
|
322
|
+
//should now all have blah
|
323
|
+
ok(e.every(function(e){
|
324
|
+
return e.blah;
|
325
|
+
}));
|
326
|
+
|
327
|
+
//length zero..
|
328
|
+
ok(re().every(function(){
|
329
|
+
return false;
|
330
|
+
}))
|
331
|
+
})
|
332
|
+
|
152
333
|
it('dispose', function(){
|
153
334
|
is(re.e('rgfdvdvdfv', 2).dispose());
|
154
335
|
eq(re('rgfdvdvdfv').length, 0);
|