entityjs 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -36,7 +36,7 @@ describe('point', function(){
|
|
36
36
|
it('should be correct distance', function(){
|
37
37
|
e.posX = 12;
|
38
38
|
e.posY = 54;
|
39
|
-
eq(e.distance(23,74), 23)
|
39
|
+
eq(e.distance(23,74)+0.5|0, 23)
|
40
40
|
})
|
41
41
|
|
42
42
|
it('should be correct distance with from', function(){
|
@@ -46,12 +46,12 @@ describe('point', function(){
|
|
46
46
|
|
47
47
|
var o = {x:23, y:74}
|
48
48
|
|
49
|
-
eq(e.distance(o), 23)
|
49
|
+
eq(e.distance(o) +0.5 | 0, 23)
|
50
50
|
|
51
51
|
|
52
52
|
o = {posX:23, posY:74}
|
53
53
|
|
54
|
-
eq(e.distance(o), 23)
|
54
|
+
eq(e.distance(o)+0.5|0, 23)
|
55
55
|
})
|
56
56
|
|
57
57
|
});
|
File without changes
|
@@ -9,27 +9,42 @@ describe('tile', function(){
|
|
9
9
|
e = re.e('tile');
|
10
10
|
});
|
11
11
|
|
12
|
-
|
12
|
+
|
13
|
+
it('toPos', function(){
|
14
|
+
var e = re.tile.toPos(88, 40);
|
15
|
+
|
16
|
+
eq(e.posX, 80);
|
17
|
+
eq(e.posY, 40);
|
18
|
+
})
|
19
|
+
|
20
|
+
it('toPosX', function(){
|
13
21
|
|
14
|
-
eq(re.tile.
|
22
|
+
eq(re.tile.toPosX(88, 40), 80);
|
15
23
|
|
16
24
|
re.tile.sizeX = 40;
|
17
|
-
eq(re.tile.
|
25
|
+
eq(re.tile.toPosX(88), 80);
|
18
26
|
|
19
27
|
});
|
20
28
|
|
21
|
-
it('
|
29
|
+
it('toPosY', function(){
|
22
30
|
|
23
|
-
eq(re.tile.
|
31
|
+
eq(re.tile.toPosY(88, 40), 80);
|
24
32
|
|
25
33
|
re.tile.sizeY = 40;
|
26
|
-
eq(re.tile.
|
34
|
+
eq(re.tile.toPosY(88), 80);
|
27
35
|
|
28
36
|
});
|
29
37
|
|
38
|
+
it('toTile', function(){
|
39
|
+
var e = re.tile.toTile(88, 40);
|
40
|
+
|
41
|
+
eq(e.tileX, 2);
|
42
|
+
eq(e.tileY, 1);
|
43
|
+
})
|
44
|
+
|
30
45
|
it('toTileX', function(){
|
31
46
|
|
32
|
-
eq(re.tile.toTileX(88
|
47
|
+
eq(re.tile.toTileX(88), 2);
|
33
48
|
|
34
49
|
re.tile.sizeX = 40;
|
35
50
|
eq(re.tile.toTileX(88), 2);
|
@@ -37,7 +37,7 @@ describe('automap', function(){
|
|
37
37
|
[6,5,4,3,2,1]
|
38
38
|
];
|
39
39
|
|
40
|
-
is(e.automap(level))
|
40
|
+
is(e.automap(level, true))
|
41
41
|
eq(e.lenX, level[0].length)
|
42
42
|
eq(e.lenY, level.length)
|
43
43
|
|
@@ -54,7 +54,7 @@ describe('automap', function(){
|
|
54
54
|
[6,5,4,3,2,1]
|
55
55
|
];
|
56
56
|
|
57
|
-
is(e.automap(level
|
57
|
+
is(e.automap(level))
|
58
58
|
eq(e.lenX, level[0].length)
|
59
59
|
eq(e.lenY, level.length)
|
60
60
|
|
@@ -13,32 +13,15 @@ describe('flicker', function(){
|
|
13
13
|
.comp('flicker');
|
14
14
|
|
15
15
|
});
|
16
|
-
|
17
|
-
it('addFlicker', function(){
|
18
|
-
|
19
|
-
e.addFlicker('heal', 5, 200, [10])
|
20
|
-
|
21
|
-
is(e.flicker_reels['heal'])
|
22
|
-
|
23
|
-
});
|
24
|
-
|
25
|
-
it('removeFlicker', function(){
|
26
|
-
|
27
|
-
is(e.addFlicker('heal', 5, 200, [10]))
|
28
|
-
|
29
|
-
is(e.flicker_reels['heal'])
|
30
|
-
|
31
|
-
is(e.removeFlicker('heal'))
|
32
|
-
|
33
|
-
eq(e.flicker_reels['heal'], null)
|
34
|
-
})
|
35
16
|
|
36
17
|
it('flicker', function(){
|
37
18
|
|
38
|
-
|
19
|
+
//should take 4 seconds to finis
|
20
|
+
var time = 4;
|
39
21
|
|
40
22
|
var called = false;
|
41
23
|
var called2 = false;
|
24
|
+
var called3 = false;
|
42
25
|
|
43
26
|
e.on('flicker:start', function(){
|
44
27
|
called = true;
|
@@ -47,8 +30,15 @@ describe('flicker', function(){
|
|
47
30
|
called2 = true;
|
48
31
|
is(v, 'string')
|
49
32
|
})
|
33
|
+
.on('flicker:update', function(f, i, array, loop){
|
34
|
+
is(f)
|
35
|
+
is(i)
|
36
|
+
is(array)
|
37
|
+
is(loop)
|
38
|
+
called3 = true;
|
39
|
+
})
|
50
40
|
|
51
|
-
e.flicker('heal')
|
41
|
+
e.flicker(time, [5, 5, 5, 5], 1, 'heal')
|
52
42
|
|
53
43
|
ok(e.flickering('heal'))
|
54
44
|
|
@@ -57,11 +47,33 @@ describe('flicker', function(){
|
|
57
47
|
ok(called)
|
58
48
|
|
59
49
|
//manually call update
|
60
|
-
|
50
|
+
|
51
|
+
for(var i=0; i<60 * time; i++){
|
52
|
+
if(i == 37){
|
53
|
+
eq(e.health, 5);
|
54
|
+
} else if(i==37+37){
|
55
|
+
eq(e.health, 10);
|
56
|
+
}
|
57
|
+
e.flicker_update(re.sys.stepSize);
|
58
|
+
}
|
61
59
|
|
62
60
|
eq(e.health, 20)
|
63
61
|
|
64
62
|
ok(called2)
|
63
|
+
ok(called3)
|
64
|
+
})
|
65
|
+
|
66
|
+
it('should flicker correctly', function(){
|
67
|
+
|
68
|
+
e.flicker(1, [5]);
|
69
|
+
|
70
|
+
eq(e.health, 5)
|
71
|
+
|
72
|
+
for(var i=60;i--;){
|
73
|
+
e.flicker_update(re.sys.stepSize);
|
74
|
+
eq(e.health, 5);
|
75
|
+
}
|
76
|
+
|
65
77
|
})
|
66
78
|
|
67
79
|
});
|
@@ -0,0 +1,55 @@
|
|
1
|
+
describe('pattern/pathfind', function(){
|
2
|
+
|
3
|
+
var map, pathfind, automap;
|
4
|
+
|
5
|
+
beforeEach(function(){
|
6
|
+
//zero is walkable
|
7
|
+
map =
|
8
|
+
[
|
9
|
+
[0,0,0,0,0],
|
10
|
+
[0,1,0,0,0],
|
11
|
+
[0,0,0,1,0]
|
12
|
+
];
|
13
|
+
|
14
|
+
//supplies within method
|
15
|
+
automap = re.e('automap').automap(map);
|
16
|
+
|
17
|
+
pathfind = re.e('pathfind');
|
18
|
+
|
19
|
+
//implement custom check method
|
20
|
+
pathfind.checkNode = function(x, y){
|
21
|
+
return automap.within(x, y) && automap.automap(x, y) == 0;
|
22
|
+
};
|
23
|
+
|
24
|
+
});
|
25
|
+
|
26
|
+
it('should move on self', function(){
|
27
|
+
|
28
|
+
var path = pathfind.pathfind(0, 0, 0, 0);
|
29
|
+
|
30
|
+
eq(path.length, 2)
|
31
|
+
|
32
|
+
})
|
33
|
+
|
34
|
+
it('should move up one tile', function(){
|
35
|
+
|
36
|
+
var path = pathfind.pathfind(0, 0, 0, 1);
|
37
|
+
|
38
|
+
eq(path.length, 2);
|
39
|
+
|
40
|
+
eq(path.pop(), 1);
|
41
|
+
|
42
|
+
});
|
43
|
+
|
44
|
+
it('should navigate around 1s', function(){
|
45
|
+
|
46
|
+
var path = pathfind.pathfind(0, 1, 2, 1);
|
47
|
+
|
48
|
+
//first int is Y
|
49
|
+
path.pop();
|
50
|
+
//second is X
|
51
|
+
not(path.pop(), 1);
|
52
|
+
|
53
|
+
});
|
54
|
+
|
55
|
+
});
|
data/src/core/comp.js
CHANGED
@@ -37,6 +37,7 @@
|
|
37
37
|
this._re_signals = {};
|
38
38
|
this._re_inherits = {};
|
39
39
|
this._re_defines = {};
|
40
|
+
this._re_events = {};
|
40
41
|
this._re_final = false;
|
41
42
|
};
|
42
43
|
|
@@ -61,14 +62,10 @@ re.c.init.prototype = {
|
|
61
62
|
}
|
62
63
|
},
|
63
64
|
|
64
|
-
global:function(){
|
65
|
-
throw 'Deprecated use statics'
|
66
|
-
},
|
67
|
-
|
68
65
|
statics:function(obj, value){
|
69
66
|
this._checkFinal();
|
70
67
|
|
71
|
-
if(
|
68
|
+
if(!re.is(value)){
|
72
69
|
|
73
70
|
for(var type in obj){
|
74
71
|
this[type] = obj[type];
|
@@ -81,8 +78,20 @@ re.c.init.prototype = {
|
|
81
78
|
return this;
|
82
79
|
},
|
83
80
|
|
84
|
-
|
85
|
-
|
81
|
+
events:function(obj, value){
|
82
|
+
this._checkFinal();
|
83
|
+
|
84
|
+
if(!re.is(value)){
|
85
|
+
|
86
|
+
for(var type in obj){
|
87
|
+
this._re_events[type] = obj[type];
|
88
|
+
}
|
89
|
+
|
90
|
+
} else {
|
91
|
+
this._re_events[obj] = value;
|
92
|
+
}
|
93
|
+
|
94
|
+
return this;
|
86
95
|
},
|
87
96
|
|
88
97
|
requires:function(r){
|
@@ -184,10 +193,6 @@ re.c.init.prototype = {
|
|
184
193
|
return re.e.init.prototype.trigger.apply(this, arguments);
|
185
194
|
},
|
186
195
|
|
187
|
-
inherit:function(){
|
188
|
-
throw 'Deprecated use defaults'
|
189
|
-
},
|
190
|
-
|
191
196
|
/*
|
192
197
|
Default adds onto but doesn't overwrite values.
|
193
198
|
*/
|
@@ -246,11 +251,6 @@ re.c.init.prototype = {
|
|
246
251
|
return this;
|
247
252
|
},
|
248
253
|
|
249
|
-
extend:function(){
|
250
|
-
this.defines.apply(this, arguments);
|
251
|
-
re.log('warning extend is deprecated, use defines');
|
252
|
-
},
|
253
|
-
|
254
254
|
/*
|
255
255
|
defines overrides everything.
|
256
256
|
*/
|
data/src/core/entity.js
CHANGED
@@ -81,37 +81,38 @@
|
|
81
81
|
//handle string or array?
|
82
82
|
if(re.is(com,'array')){
|
83
83
|
pieces = com;
|
84
|
-
|
85
|
-
com = com[0];
|
86
84
|
} else {
|
87
85
|
pieces = com.split(' ');
|
88
86
|
}
|
89
87
|
|
90
88
|
if(pieces.length > 1){
|
91
89
|
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
var k;
|
91
|
+
while(k = pieces.shift()){
|
92
|
+
this.removeComp(k);
|
93
|
+
}
|
95
94
|
|
96
95
|
return this;
|
96
|
+
} else {
|
97
|
+
com = pieces[0];
|
97
98
|
}
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
100
|
+
if(this.has(com)){
|
101
|
+
|
102
|
+
var c = re._c[com];
|
103
|
+
//only remove if it exists
|
104
|
+
if(c){
|
105
|
+
|
106
|
+
if(c._re_dispose){
|
107
|
+
c._re_dispose.call(this, c);
|
108
|
+
}
|
109
|
+
|
110
|
+
c.trigger('dispose', this);
|
111
|
+
|
112
|
+
}
|
113
|
+
|
114
|
+
//remove from array
|
115
|
+
this._re_comps.splice(this._re_comps.indexOf(com), 1);
|
115
116
|
}
|
116
117
|
return this;
|
117
118
|
};
|
@@ -136,8 +137,6 @@
|
|
136
137
|
//handle array or string?
|
137
138
|
if(re.is(com, 'array')){
|
138
139
|
pieces = com;
|
139
|
-
//set in case length is 1
|
140
|
-
com = com[0];
|
141
140
|
} else {
|
142
141
|
pieces = com.split(' ');
|
143
142
|
}
|
@@ -147,8 +146,12 @@
|
|
147
146
|
this._re_comp(pieces[i]);
|
148
147
|
}
|
149
148
|
return this;
|
149
|
+
} else {
|
150
|
+
com = pieces[0];
|
150
151
|
}
|
151
152
|
|
153
|
+
if(!com) return this;
|
154
|
+
|
152
155
|
//component reference
|
153
156
|
var c;
|
154
157
|
|
@@ -163,7 +166,7 @@
|
|
163
166
|
vals[0] = c;
|
164
167
|
|
165
168
|
//if already has component
|
166
|
-
if(this.has(com))
|
169
|
+
if(!this.has(com)){
|
167
170
|
|
168
171
|
//add comp first thing, to avoid dupe requirement calls
|
169
172
|
//and this lets the init remove the comp too.
|
@@ -195,6 +198,10 @@
|
|
195
198
|
if(c._re_defines){
|
196
199
|
this.attr(c._re_defines);
|
197
200
|
}
|
201
|
+
if(c._re_events){
|
202
|
+
this.attr(c._re_events)
|
203
|
+
.on(c._re_events);
|
204
|
+
}
|
198
205
|
|
199
206
|
if(c._re_init){
|
200
207
|
c._re_init.apply(this, vals);
|
@@ -203,7 +210,7 @@
|
|
203
210
|
c.trigger('init', this);
|
204
211
|
}
|
205
212
|
|
206
|
-
|
213
|
+
}
|
207
214
|
|
208
215
|
|
209
216
|
return this;
|
@@ -313,7 +320,6 @@
|
|
313
320
|
};
|
314
321
|
|
315
322
|
/*
|
316
|
-
New way to add signals version 0.2.1.
|
317
323
|
|
318
324
|
//single
|
319
325
|
bind('draw', function(){});
|
@@ -327,14 +333,13 @@
|
|
327
333
|
|
328
334
|
});
|
329
335
|
*/
|
330
|
-
p.on = function(type, method){
|
336
|
+
p.on = function(type, method, context){
|
331
337
|
|
332
338
|
if(re.is(type, 'object')){
|
333
339
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
}
|
340
|
+
for(var k in type){
|
341
|
+
this.on(k, type[k], method);
|
342
|
+
}
|
338
343
|
|
339
344
|
} else {
|
340
345
|
|
@@ -342,7 +347,8 @@
|
|
342
347
|
this._re_signals[type] = [];
|
343
348
|
}
|
344
349
|
if(!re.is(method)) throw 'Method is null'
|
345
|
-
|
350
|
+
//save context
|
351
|
+
this._re_signals[type].push({c:context || this, f:method});
|
346
352
|
|
347
353
|
}
|
348
354
|
|
@@ -382,7 +388,7 @@
|
|
382
388
|
var i = this._re_signals[type];
|
383
389
|
for(var k in i){
|
384
390
|
|
385
|
-
if(i
|
391
|
+
if(i[k].f == method){
|
386
392
|
i.splice(k, 1);
|
387
393
|
}
|
388
394
|
|
@@ -403,13 +409,10 @@
|
|
403
409
|
|
404
410
|
/*
|
405
411
|
Signal dispatches events to entities.
|
406
|
-
Modified V0.3
|
407
|
-
|
408
412
|
|
409
413
|
-dispatch signals
|
410
414
|
this.trigger('click');
|
411
|
-
this.trigger('click
|
412
|
-
this.trigger('click', {data:0});
|
415
|
+
this.trigger('click', 0);
|
413
416
|
|
414
417
|
*/
|
415
418
|
p.trigger = function(type){
|
@@ -424,8 +427,8 @@
|
|
424
427
|
if(!b) break;
|
425
428
|
if(!b[i]) continue;
|
426
429
|
|
427
|
-
//return false remove
|
428
|
-
if(b[i].apply(
|
430
|
+
//return false remove
|
431
|
+
if(b[i].f.apply(b[i].c, Array.prototype.slice.call(arguments, 1)) === false){
|
429
432
|
b.splice(i, 1);
|
430
433
|
}
|
431
434
|
|
@@ -443,8 +446,9 @@
|
|
443
446
|
}
|
444
447
|
|
445
448
|
}else {
|
449
|
+
var k = 'function';
|
446
450
|
//defines property
|
447
|
-
if(re.is(this[obj],
|
451
|
+
if(re.is(this[obj], k) && !re.is(value, k)){
|
448
452
|
if(re.is(value, 'array')){
|
449
453
|
this[obj].apply(this, value);
|
450
454
|
} else {
|
@@ -469,7 +473,7 @@
|
|
469
473
|
} else {
|
470
474
|
//defines property
|
471
475
|
|
472
|
-
if(!
|
476
|
+
if(!re.is(this[obj])){
|
473
477
|
|
474
478
|
this[obj] = value;
|
475
479
|
|
@@ -480,22 +484,19 @@
|
|
480
484
|
}
|
481
485
|
|
482
486
|
p.dispose = function(){
|
483
|
-
|
484
|
-
re._e.splice(re._e.indexOf(this), 1);
|
487
|
+
var dis = 'dispose';
|
485
488
|
|
486
|
-
|
487
|
-
|
488
|
-
if(k._re_dispose){
|
489
|
-
k._re_dispose.call(this, k);
|
490
|
-
}
|
491
|
-
k.trigger('dispose', this);
|
492
|
-
}
|
489
|
+
//trigger dispose on all components
|
490
|
+
this.removeComp(this.comps());
|
493
491
|
|
494
|
-
this.trigger(
|
492
|
+
this.trigger(dis);
|
495
493
|
|
496
494
|
//remove all events
|
497
495
|
this.off();
|
498
496
|
|
497
|
+
//delete from statics array
|
498
|
+
re._e.splice(re._e.indexOf(this), 1);
|
499
|
+
|
499
500
|
return this;
|
500
501
|
}
|
501
502
|
|