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/src/core/load.js
CHANGED
@@ -140,12 +140,12 @@
|
|
140
140
|
});
|
141
141
|
|
142
142
|
img.onload = function(){
|
143
|
-
re.c(a).
|
143
|
+
re.c(a).defines({
|
144
144
|
sizeX:img.width,
|
145
|
-
sizeY:img.height
|
146
|
-
|
147
|
-
|
148
|
-
|
145
|
+
sizeY:img.height,
|
146
|
+
bisect:img.width
|
147
|
+
});
|
148
|
+
|
149
149
|
that._loaded();
|
150
150
|
};
|
151
151
|
|
data/src/core/query.js
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
//takes values from all objects and returns an array
|
30
30
|
.pluck('width height');
|
31
31
|
|
32
|
-
//find all bitmap entities with update
|
32
|
+
//find all bitmap entities with update event.
|
33
33
|
re('bitmap ^update');
|
34
34
|
|
35
35
|
//add color comp to all text components
|
@@ -49,8 +49,7 @@
|
|
49
49
|
//calls reset method on all entities
|
50
50
|
.method('reset');
|
51
51
|
|
52
|
-
|
53
|
-
re('#player').health = 100;
|
52
|
+
re('#player')[0].health = 100;
|
54
53
|
|
55
54
|
*/
|
56
55
|
var q = function(selector){
|
@@ -135,6 +134,8 @@
|
|
135
134
|
if(select.call(e, i, l)) this.push(e);
|
136
135
|
}
|
137
136
|
|
137
|
+
} else if(re.is(select, 'array')){
|
138
|
+
this.push.apply(this, select);
|
138
139
|
}
|
139
140
|
|
140
141
|
return this;
|
@@ -143,13 +144,12 @@
|
|
143
144
|
/*
|
144
145
|
Calls the given method name on all entities.
|
145
146
|
|
146
|
-
re('enemies').
|
147
|
+
re('enemies').invoke('rest');
|
147
148
|
*/
|
148
|
-
p.
|
149
|
+
p.invoke = function(m){
|
149
150
|
var b = Array.prototype.slice.call(arguments, 1);
|
150
|
-
return this.each(function(){
|
151
|
-
|
152
|
-
this[m].apply(this, b);
|
151
|
+
return this.each(function(e){
|
152
|
+
e[m].apply(e, b);
|
153
153
|
});
|
154
154
|
|
155
155
|
}
|
@@ -162,10 +162,10 @@
|
|
162
162
|
|
163
163
|
returning false will break the loop
|
164
164
|
*/
|
165
|
-
p.each = function(m){
|
166
|
-
|
167
|
-
|
168
|
-
|
165
|
+
p.each = function(m, context){
|
166
|
+
var l = this.length, i = -1, e;
|
167
|
+
|
168
|
+
while(++i < l && (e = this[i]) != null && m.call(context || this, e, i, this) !== false);
|
169
169
|
|
170
170
|
return this;
|
171
171
|
}
|
@@ -175,9 +175,9 @@
|
|
175
175
|
|
176
176
|
//map through and increase y every 3 entities.
|
177
177
|
|
178
|
-
re('draw').tilemap(3, function(x, y){
|
179
|
-
|
180
|
-
|
178
|
+
re('draw').tilemap(3, function(e, x, y){
|
179
|
+
e.x(x * width);
|
180
|
+
e.y(Y * height);
|
181
181
|
});
|
182
182
|
|
183
183
|
//so instead of getting this back
|
@@ -194,13 +194,13 @@
|
|
194
194
|
returning false will break the loop
|
195
195
|
|
196
196
|
*/
|
197
|
-
p.tilemap = function(w, method){
|
197
|
+
p.tilemap = function(w, method, context){
|
198
198
|
var x = 0;
|
199
199
|
var y = 0;
|
200
200
|
|
201
201
|
return this.each(function(i, l){
|
202
202
|
|
203
|
-
if(method.call(this[i], x, y, i,
|
203
|
+
if(method.call(context, this[i], x, y, i, this) == false) return false;
|
204
204
|
|
205
205
|
x++;
|
206
206
|
|
@@ -217,8 +217,8 @@
|
|
217
217
|
p.comps = function(){
|
218
218
|
var l = [];
|
219
219
|
|
220
|
-
this.each(function(){
|
221
|
-
var k =
|
220
|
+
this.each(function(e){
|
221
|
+
var k = e.comps();
|
222
222
|
for(var i=0; i<k.length; i++){
|
223
223
|
if(l.indexOf(k[i]) == -1){
|
224
224
|
l.push(k[i])
|
@@ -233,7 +233,48 @@
|
|
233
233
|
Returns a random entity.
|
234
234
|
*/
|
235
235
|
p.random = function(){
|
236
|
-
return this[
|
236
|
+
return this[(Math.random()*this.length)|0];
|
237
|
+
}
|
238
|
+
|
239
|
+
p.attr = function(obj, value){
|
240
|
+
return this.invoke('attr', obj, value);
|
241
|
+
|
242
|
+
}
|
243
|
+
|
244
|
+
p.def = function(obj, value){
|
245
|
+
return this.invoke('def', obj, value);
|
246
|
+
}
|
247
|
+
|
248
|
+
p.comp = function(c){
|
249
|
+
return this.invoke('comp', c);
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
p.removeComp = function(c){
|
254
|
+
return this.invoke('removeComp', c);
|
255
|
+
}
|
256
|
+
|
257
|
+
p.on = function(type, method){
|
258
|
+
return this.invoke('on', type, method);
|
259
|
+
}
|
260
|
+
|
261
|
+
p.off = function(type, method){
|
262
|
+
return this.invoke('off', type, method);
|
263
|
+
}
|
264
|
+
|
265
|
+
p.trigger = function(){
|
266
|
+
var p = arguments;
|
267
|
+
return this.each(function(e){
|
268
|
+
e.trigger.apply(e, p);
|
269
|
+
});
|
270
|
+
}
|
271
|
+
|
272
|
+
p.has = function(comp){
|
273
|
+
//return false if empty
|
274
|
+
if(!this.length) return false;
|
275
|
+
return this.every(function(e){
|
276
|
+
return e.has(comp);
|
277
|
+
});
|
237
278
|
}
|
238
279
|
|
239
280
|
/*
|
@@ -255,13 +296,12 @@
|
|
255
296
|
|
256
297
|
var k = value.split(' ');
|
257
298
|
|
258
|
-
this.each(function(){
|
299
|
+
this.each(function(e){
|
259
300
|
var o = {};
|
260
301
|
|
261
302
|
for(var p in k){
|
262
|
-
|
263
|
-
|
264
|
-
}
|
303
|
+
var name = k[p];
|
304
|
+
o[name] = e[name];
|
265
305
|
}
|
266
306
|
|
267
307
|
t.push(o);
|
@@ -271,84 +311,184 @@
|
|
271
311
|
return t;
|
272
312
|
}
|
273
313
|
|
274
|
-
p.
|
275
|
-
|
314
|
+
p.isEmpty = function(){
|
315
|
+
return !this.length;
|
276
316
|
}
|
277
317
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
318
|
+
/*
|
319
|
+
Returns the first entity that passes the truth iterator method.
|
320
|
+
|
321
|
+
re('tile').find(function(e){
|
322
|
+
return e.tileX() == 0 && e.tileY() == 1;
|
323
|
+
});
|
324
|
+
|
325
|
+
*/
|
326
|
+
p.find = function(method, context){
|
327
|
+
for(var i=0, l=this.length; i<l; i++){
|
328
|
+
if(method.call(context || this, this[i], i, this)) return this[i];
|
329
|
+
}
|
330
|
+
|
331
|
+
return null;
|
332
|
+
}
|
333
|
+
|
334
|
+
/*
|
335
|
+
Returns the lowest entity from the given iterator.
|
336
|
+
|
337
|
+
var weakestRat = re('rat').min(function(e){
|
338
|
+
return e.health;
|
339
|
+
});
|
340
|
+
|
341
|
+
*/
|
342
|
+
p.min = function(method, context){
|
343
|
+
var lowest = Infinity, val;
|
344
|
+
this.each(function(e, i, l){
|
345
|
+
var next = method.call(context || this, e, i, l);
|
346
|
+
if(next < lowest){
|
347
|
+
lowest = next;
|
348
|
+
val = e;
|
349
|
+
}
|
282
350
|
|
351
|
+
});
|
352
|
+
|
353
|
+
return val;
|
283
354
|
}
|
284
355
|
|
285
|
-
p.
|
286
|
-
|
356
|
+
p.max = function(method, context){
|
357
|
+
var lowest = -Infinity, val;
|
358
|
+
this.each(function(e, i, l){
|
359
|
+
var next = method.call(context || this, e, i, l);
|
360
|
+
if(next > lowest){
|
361
|
+
lowest = next;
|
362
|
+
val = e;
|
363
|
+
}
|
364
|
+
});
|
365
|
+
|
366
|
+
return val;
|
287
367
|
}
|
288
368
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
});
|
293
|
-
|
369
|
+
//without this filter would return a normal array.
|
370
|
+
p.filter = function(){
|
371
|
+
return re(Array.prototype.filter.apply(this, arguments));
|
294
372
|
}
|
295
373
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
374
|
+
/*
|
375
|
+
Finds first entity with components
|
376
|
+
|
377
|
+
re('draw').findWith('circle !red');
|
378
|
+
|
379
|
+
*/
|
380
|
+
p.findWith = function(comps, c){
|
381
|
+
return this.find(function(e){
|
382
|
+
return e.has(comps);
|
383
|
+
}, c);
|
302
384
|
}
|
303
385
|
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
386
|
+
/*
|
387
|
+
Creates a new entity and pushes it into the array.
|
388
|
+
*/
|
389
|
+
p.e = function(comps, count){
|
390
|
+
var e = re.e(comps, count);
|
391
|
+
if(count){
|
392
|
+
//add all in query
|
393
|
+
for(var i in e){
|
394
|
+
this.push(e[i]);
|
395
|
+
}
|
396
|
+
} else {
|
397
|
+
this.push(e);
|
398
|
+
}
|
399
|
+
|
400
|
+
return this;
|
308
401
|
}
|
309
402
|
|
310
|
-
p.
|
311
|
-
|
312
|
-
return this.each(function(){
|
313
|
-
this.on(type,method);
|
314
|
-
});
|
315
|
-
|
403
|
+
p.include = function(ref){
|
404
|
+
return this.indexOf(ref) != -1;
|
316
405
|
}
|
317
406
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
407
|
+
/*
|
408
|
+
Removes first reference found from array.
|
409
|
+
|
410
|
+
var blah = re.e();
|
411
|
+
|
412
|
+
var q = re()
|
413
|
+
q.push(blah);
|
414
|
+
|
415
|
+
q.erase(blah);
|
416
|
+
|
417
|
+
q.include(blah) //false
|
418
|
+
|
419
|
+
Can also add in other in its place.
|
420
|
+
|
421
|
+
q.erase(blah, re.e());
|
422
|
+
|
423
|
+
*/
|
424
|
+
p.erase = function(ref){
|
425
|
+
for(var i=this.length; i--;){
|
426
|
+
if(this[i] == ref) this.splice(i, 1);
|
427
|
+
}
|
428
|
+
return this;
|
322
429
|
}
|
323
430
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
431
|
+
/*
|
432
|
+
Inserts an element after the other.
|
433
|
+
*/
|
434
|
+
p.insertAfter = function(target, ref){
|
435
|
+
this.splice(this.indexOf(target)+1, 0, ref);
|
436
|
+
return this;
|
437
|
+
}
|
330
438
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
439
|
+
/*
|
440
|
+
Inserts an element before the other.
|
441
|
+
*/
|
442
|
+
p.insertBefore = function(target, ref){
|
443
|
+
this.splice(this.indexOf(target), 0, ref);
|
444
|
+
return this;
|
445
|
+
}
|
446
|
+
|
447
|
+
/*
|
448
|
+
Swaps the indexes of the given elements.
|
449
|
+
*/
|
450
|
+
p.swap = function(ref1, ref2){
|
451
|
+
var ref1i = this.indexOf(ref1);
|
452
|
+
var ref2i = this.indexOf(ref2);
|
453
|
+
|
454
|
+
var t = this[ref1i];
|
455
|
+
this[ref1i] = ref2;
|
456
|
+
this[ref2i] = t;
|
457
|
+
|
458
|
+
return this;
|
340
459
|
}
|
341
460
|
|
342
461
|
p.dispose = function(){
|
343
462
|
|
344
|
-
return this.each(function(){
|
463
|
+
return this.each(function(e){
|
345
464
|
|
346
|
-
|
465
|
+
e.dispose();
|
347
466
|
|
348
467
|
});
|
349
468
|
|
350
469
|
}
|
351
470
|
|
471
|
+
/*
|
472
|
+
returns first element or appends it to front
|
473
|
+
|
474
|
+
re().first(1).first(); //1
|
475
|
+
*/
|
476
|
+
p.first = function(r){
|
477
|
+
if(arguments.length){
|
478
|
+
this.unshift.apply(this, arguments);
|
479
|
+
return this;
|
480
|
+
}
|
481
|
+
return this[0];
|
482
|
+
}
|
483
|
+
|
484
|
+
p.last = function(ref){
|
485
|
+
if(arguments.length){
|
486
|
+
this.push.apply(this, arguments);
|
487
|
+
return this;
|
488
|
+
}
|
489
|
+
return this[this.length-1];
|
490
|
+
}
|
491
|
+
|
352
492
|
re.query = q;
|
353
493
|
|
354
494
|
}(re));
|
data/src/core/system.js
CHANGED
@@ -44,6 +44,7 @@ re.c('system')
|
|
44
44
|
(function m(){
|
45
45
|
|
46
46
|
that.system_loop();
|
47
|
+
|
47
48
|
if(that.running){
|
48
49
|
that.requestAnimationFrame(m, that.canvas);
|
49
50
|
}
|
@@ -67,7 +68,7 @@ re.c('system')
|
|
67
68
|
},
|
68
69
|
|
69
70
|
//scale is currently not implemented!
|
70
|
-
init:function(canvasId,
|
71
|
+
init:function(canvasId, contextType){
|
71
72
|
|
72
73
|
//add comps here because system is defined earlier than other comps
|
73
74
|
this.comp('polyfill tick timestep');
|
@@ -79,8 +80,6 @@ re.c('system')
|
|
79
80
|
this.canvas = re.$(canvasId);
|
80
81
|
}
|
81
82
|
|
82
|
-
this.scale = scale || 1;
|
83
|
-
|
84
83
|
this.context = this.canvas.getContext(contextType || '2d');
|
85
84
|
|
86
85
|
var s = re.screen = re.e('screen');
|
@@ -98,6 +97,8 @@ re.c('system')
|
|
98
97
|
if(re._c.touch){
|
99
98
|
re._c.touch.i();
|
100
99
|
}
|
100
|
+
this.system_loop = this.defaultLoop;
|
101
|
+
this.second = this.stepSize * 30;
|
101
102
|
|
102
103
|
return this;
|
103
104
|
},
|
@@ -105,16 +106,25 @@ re.c('system')
|
|
105
106
|
/*
|
106
107
|
Default main loop
|
107
108
|
*/
|
108
|
-
|
109
|
+
defaultLoop:function(){
|
109
110
|
|
110
111
|
this.timestep(Math.min(this.tick() / 1000, this.maxTick), function(){
|
111
112
|
//update
|
112
|
-
|
113
|
+
this.update();
|
113
114
|
});
|
114
115
|
|
115
116
|
//clear
|
116
117
|
this.clear(this.clearColor);
|
117
|
-
|
118
|
+
this.draw();
|
119
|
+
},
|
120
|
+
|
121
|
+
update:function(){
|
122
|
+
re._c.update.update(this.stepSize);
|
123
|
+
},
|
124
|
+
|
125
|
+
draw:function(){
|
126
|
+
//renders default drawlist
|
127
|
+
re.drawlist().drawlist(this.context);
|
118
128
|
}
|
119
129
|
|
120
130
|
|