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.
Files changed (66) hide show
  1. data/.gitignore +1 -1
  2. data/lib/entityjs/config.rb +4 -4
  3. data/lib/entityjs/dirc.rb +2 -2
  4. data/lib/entityjs/page.rb +7 -1
  5. data/lib/entityjs/version.rb +1 -1
  6. data/public/qunit/qunit.entity.js +27 -12
  7. data/spec/javascripts/src/core/comp_spec.js +11 -0
  8. data/spec/javascripts/src/core/entity_spec.js +88 -5
  9. data/spec/javascripts/src/core/query_spec.js +196 -15
  10. data/spec/javascripts/src/cycle/drawlist_spec.js +36 -0
  11. data/spec/javascripts/src/cycle/tween_spec.js +1 -1
  12. data/spec/javascripts/src/cycle/wait_spec.js +31 -0
  13. data/spec/javascripts/src/{cycle → display}/draw_spec.js +25 -9
  14. data/spec/javascripts/src/display/sprite_spec.js +18 -0
  15. data/spec/javascripts/src/display/text_spec.js +8 -0
  16. data/spec/javascripts/src/input/mouse_spec.js +24 -36
  17. data/spec/javascripts/src/math/bisect_spec.js +4 -4
  18. data/spec/javascripts/src/math/distance_spec.js +11 -0
  19. data/spec/javascripts/src/math/iso_spec.js +131 -0
  20. data/spec/javascripts/src/math/point_spec.js +3 -3
  21. data/spec/javascripts/src/{util → math}/random_spec.js +0 -0
  22. data/spec/javascripts/src/math/range_spec.js +9 -0
  23. data/spec/javascripts/src/math/tile_spec.js +22 -7
  24. data/spec/javascripts/src/pattern/automap_spec.js +2 -2
  25. data/spec/javascripts/src/pattern/flicker_spec.js +34 -22
  26. data/spec/javascripts/src/pattern/pathfind_spec.js +55 -0
  27. data/src/core/comp.js +16 -16
  28. data/src/core/entity.js +52 -51
  29. data/src/core/load.js +5 -5
  30. data/src/core/query.js +214 -74
  31. data/src/core/system.js +16 -6
  32. data/src/cycle/drawlist.js +79 -0
  33. data/src/cycle/tween.js +7 -20
  34. data/src/cycle/wait.js +10 -19
  35. data/src/{cycle → display}/draw.js +24 -34
  36. data/src/display/image.js +1 -1
  37. data/src/display/screen.js +3 -3
  38. data/src/display/sprite.js +3 -3
  39. data/src/display/text.js +3 -1
  40. data/src/input/mouse.js +35 -12
  41. data/src/math/bisect.js +11 -10
  42. data/src/math/distance.js +7 -0
  43. data/src/math/iso.js +147 -0
  44. data/src/math/point.js +1 -5
  45. data/src/math/random.js +21 -0
  46. data/src/math/range.js +14 -0
  47. data/src/math/tile.js +40 -27
  48. data/src/pattern/automap.js +12 -11
  49. data/src/pattern/flicker.js +87 -135
  50. data/src/pattern/pathfind.js +168 -0
  51. data/src/pattern/timestep.js +4 -1
  52. data/src/util/polyfill.js +1 -1
  53. data/templates/isometric/assets/images/isotiles.png +0 -0
  54. data/templates/isometric/config.yml +22 -0
  55. data/templates/isometric/readme.txt +79 -0
  56. data/templates/isometric/scripts/displays/cursor.js +34 -0
  57. data/templates/isometric/scripts/displays/isoimage.js +32 -0
  58. data/templates/isometric/scripts/init.js +7 -0
  59. data/templates/isometric/scripts/levels/level.js +55 -0
  60. data/templates/isometric/scripts/levels/level1.js +11 -0
  61. data/templates/isometric/scripts/scenes/home.js +10 -0
  62. data/templates/isometric/scripts/scenes/load.js +11 -0
  63. data/templates/isometric/tests/scenes/load_test.js +15 -0
  64. metadata +42 -21
  65. data/src/net/socket.js +0 -52
  66. data/src/util/random.js +0 -24
@@ -0,0 +1,36 @@
1
+ describe('cycle/drawlist', function(){
2
+
3
+ var drawlist;
4
+
5
+ beforeEach(function(){
6
+
7
+ drawlist = re.drawlist('test');
8
+
9
+ });
10
+
11
+ it('add', function(){
12
+ var blah = re.e('circle');
13
+ drawlist.add(blah);
14
+
15
+ ok(drawlist.list.include(blah))
16
+ })
17
+
18
+ it('remove', function(){
19
+
20
+ var blah = re.e('circle');
21
+ drawlist.add(blah);
22
+ drawlist.remove(blah);
23
+ not(drawlist.list.include(blah))
24
+ })
25
+
26
+ it('drawlist', function(){
27
+ //drawlist.drawlist();
28
+ //smoke test
29
+ })
30
+
31
+ it('sort', function(){
32
+ drawlist.sort();
33
+ //an other smoke test
34
+ })
35
+
36
+ });
@@ -47,7 +47,7 @@ describe('cycle/tween', function(){
47
47
 
48
48
  tween.tween_update(step)
49
49
 
50
- eq(tween.x, 23.240000000000002);
50
+ eq(tween.x, 21.62);
51
51
 
52
52
  for(var i=60; i--;)
53
53
  tween.tween_update(step);
@@ -0,0 +1,31 @@
1
+ describe('cycle/wait', function(){
2
+
3
+ var wait;
4
+
5
+ beforeEach(function(){
6
+ wait = re.e('wait');
7
+ });
8
+
9
+ it('should wait', function(){
10
+
11
+ var called= false;
12
+
13
+ runs(function(){
14
+
15
+ is(wait.wait(function(){
16
+ called = true;
17
+ console.log('ran')
18
+ }, 100));
19
+ console.log('hey')
20
+ });
21
+
22
+ waits(101);
23
+
24
+ runs(function(){
25
+ ok(called)
26
+ console.log('last')
27
+ });
28
+
29
+ });
30
+
31
+ });
@@ -1,16 +1,32 @@
1
1
  describe('draw', function(){
2
2
 
3
- var d;
3
+ var d, list;
4
4
 
5
5
  beforeEach(function(){
6
+ list = re.drawlist().list;
7
+
6
8
  re.c('shape')
7
- .requires('draw').defines('draw', function(){
9
+ .requires('draw')
10
+ .defines('draw', function(){
8
11
  })
9
12
 
10
13
  d = re.e('shape')
11
14
  })
12
15
 
13
16
 
17
+ it('should sort rect first', function(){
18
+
19
+ var rect = re.e('shape');
20
+ rect.depth = function(){
21
+ return -1000;
22
+ };
23
+
24
+ re.drawlist().sort();
25
+
26
+ eq(list[0], rect);
27
+
28
+ })
29
+
14
30
  it('create', function(){
15
31
  var called = false
16
32
  re.sys.start();
@@ -34,7 +50,7 @@ describe('draw', function(){
34
50
  is(re.e('shape ddd').drawFirst())
35
51
 
36
52
  var l = 0
37
- ok(re._c.draw.l[l].has('ddd'))
53
+ ok(list[l].has('ddd'))
38
54
  })
39
55
 
40
56
  it('drawLast', function(){
@@ -44,8 +60,8 @@ describe('draw', function(){
44
60
 
45
61
  is(k.drawLast())
46
62
 
47
- var l = re._c.draw.l.length-1
48
- ok(re._c.draw.l[l].has('db77'))
63
+ var l = list.length-1
64
+ ok(list[l].has('db77'))
49
65
 
50
66
  })
51
67
 
@@ -57,8 +73,8 @@ describe('draw', function(){
57
73
  is(k.drawBefore(b))
58
74
 
59
75
 
60
- var l = re._c.draw.l.indexOf(b)-1
61
- ok(re._c.draw.l[l].has('db777'))
76
+ var l = list.indexOf(b)-1
77
+ ok(list[l].has('db777'))
62
78
 
63
79
  })
64
80
 
@@ -68,8 +84,8 @@ describe('draw', function(){
68
84
  var b = re.e('shape b')
69
85
 
70
86
  is(k.drawAfter(b))
71
- var l = re._c.draw.l.indexOf(b)+1
72
- ok(re._c.draw.l[l].has('db777y'))
87
+ var l = list.indexOf(b)+1
88
+ ok(list[l].has('db777y'))
73
89
 
74
90
  })
75
91
 
@@ -20,6 +20,24 @@ describe('sprite', function(){
20
20
  eq(e.frame(), 1)
21
21
  });
22
22
 
23
+ it('should display second row', function(){
24
+
25
+ e.bisect = 2001;
26
+ e.sizeY = 80;
27
+ e.sizeX = 87;
28
+
29
+ e.frame(22);
30
+
31
+ eq(e.frameX, 22)
32
+ eq(e.frameY, 0)
33
+
34
+ //tricky part
35
+ e.frame(23);
36
+ eq(e.frameX, 0);
37
+ eq(e.frameY, 1);
38
+
39
+ })
40
+
23
41
  it('draw', function(){
24
42
  is(e.draw(re.sys.context))
25
43
 
@@ -23,6 +23,14 @@ describe('text', function(){
23
23
  not(f.visible())
24
24
  })
25
25
 
26
+ it('should join strings', function(){
27
+
28
+ f.text('blah',10,"nice");
29
+
30
+ eq(f.text(), 'blah 10 nice');
31
+
32
+ });
33
+
26
34
  it('should draw', function(){
27
35
  f.text('m\nlinesdfsdfsdfsdsdfsdfsdfsdfsdfsfsf')
28
36
  is(f.draw(re.sys.context))
@@ -10,13 +10,11 @@ describe('mouse', function(){
10
10
  var type = 'mousedown'
11
11
  var called, called2;
12
12
 
13
- e.on(type, function(m, e){
13
+ e.on(type, function(x,y, e){
14
14
  called = true
15
- is(m)
16
- is(m.screenX)
17
- is(m.screenY)
18
- is(m.posX)
19
- is(m.posY)
15
+ is(x)
16
+ is(y)
17
+ is(e)
20
18
  });
21
19
 
22
20
  e.on(type+':middle', function(m, e){
@@ -34,13 +32,11 @@ describe('mouse', function(){
34
32
  var type = 'mouseup'
35
33
  var called, called2;
36
34
 
37
- e.on(type, function(m, e){
35
+ e.on(type, function(x,y, e){
38
36
  called = true
39
- is(m)
40
- is(m.screenX)
41
- is(m.screenY)
42
- is(m.posX)
43
- is(m.posY)
37
+ is(x)
38
+ is(y)
39
+ is(e)
44
40
  });
45
41
 
46
42
  e.on(type+':middle', function(m, e){
@@ -60,13 +56,11 @@ describe('mouse', function(){
60
56
  var type = 'mousemove'
61
57
  var called;
62
58
 
63
- e.on(type, function(m, e){
59
+ e.on(type, function(x,y, e){
64
60
  called = true
65
- is(m)
66
- is(m.screenX)
67
- is(m.screenY)
68
- is(m.posX)
69
- is(m.posY)
61
+ is(x)
62
+ is(y)
63
+ is(e)
70
64
  });
71
65
 
72
66
  re.c('mouse').event({type:type, offsetX:0, offsetY:0})
@@ -79,13 +73,11 @@ describe('mouse', function(){
79
73
  var type = 'click'
80
74
  var called;
81
75
 
82
- e.on(type, function(m, e){
76
+ e.on(type, function(x,y, e){
83
77
  called = true
84
- is(m)
85
- is(m.screenX)
86
- is(m.screenY)
87
- is(m.posX)
88
- is(m.posY)
78
+ is(x)
79
+ is(y)
80
+ is(e)
89
81
  });
90
82
 
91
83
  re.c('mouse').event({type:type, offsetX:0, offsetY:0})
@@ -98,13 +90,11 @@ describe('mouse', function(){
98
90
  var type = 'dblclick'
99
91
  var called;
100
92
 
101
- e.on(type, function(m, e){
93
+ e.on(type, function(x,y, e){
102
94
  called = true
103
- is(m)
104
- is(m.screenX)
105
- is(m.screenY)
106
- is(m.posX)
107
- is(m.posY)
95
+ is(x)
96
+ is(y)
97
+ is(e)
108
98
  });
109
99
 
110
100
  re.c('mouse').event({type:type, offsetX:0, offsetY:0})
@@ -117,13 +107,11 @@ describe('mouse', function(){
117
107
  var type = 'contextmenu'
118
108
  var called;
119
109
 
120
- e.on(type, function(m, e){
110
+ e.on(type, function(x,y, e){
121
111
  called = true
122
- is(m)
123
- is(m.screenX)
124
- is(m.screenY)
125
- is(m.posX)
126
- is(m.posY)
112
+ is(x)
113
+ is(y)
114
+ is(e)
127
115
  });
128
116
 
129
117
  re.c('mouse').event({type:type, offsetX:0, offsetY:0})
@@ -10,21 +10,21 @@ describe('bisect', function(){
10
10
  });
11
11
 
12
12
  it('static biToX', function(){
13
- eq(re.bisect.biToX(1, 160, 60), 60)
13
+ eq(re.bisect.toX(1, 160, 60), 60)
14
14
  });
15
15
 
16
16
  it('static biToY', function(){
17
- eq(re.bisect.biToY(1, 160, 60), 0)
17
+ eq(re.bisect.toY(1, 160, 60), 0)
18
18
 
19
19
  });
20
20
 
21
21
  it('static biToTileX', function(){
22
- eq(re.bisect.biToTileX(1, 160, 60), 1)
22
+ eq(re.bisect.toTileX(1, 160, 60), 1)
23
23
 
24
24
  });
25
25
 
26
26
  it('static biToTileY', function(){
27
- eq(re.bisect.biToTileY(1, 160, 60), 0)
27
+ eq(re.bisect.toTileY(1, 160, 60), 0)
28
28
 
29
29
  });
30
30
 
@@ -0,0 +1,11 @@
1
+ describe('distance', function(){
2
+
3
+
4
+ it('distance', function(){
5
+
6
+ eq(re.distance(10, 10, 20, 40) | 0, 31)
7
+
8
+ });
9
+
10
+
11
+ })
@@ -0,0 +1,131 @@
1
+ describe('math/iso', function(){
2
+
3
+ var e;
4
+
5
+ beforeEach(function(){
6
+ re.iso.sizeX = 30;
7
+ re.iso.sizeY = 30;
8
+ re.iso.sizeZ = 30;
9
+
10
+ e = re.e('iso');
11
+
12
+ });
13
+
14
+ it('toPos', function(){
15
+ var e = re.iso.toPos(125, 82)
16
+
17
+ eq(e.posX, 90)
18
+ e = re.iso.toPos(125, 82)
19
+ eq(e.posY, 75)
20
+ })
21
+
22
+ it('toPosX', function(){
23
+
24
+ eq(re.iso.toIsoX(125, 82), 4)
25
+ eq(re.iso.toIsoY(125, 82), 1)
26
+ eq(re.iso.toPosX(125, 82), 90);
27
+
28
+ })
29
+
30
+ it('toPosY', function(){
31
+ eq(re.iso.toIsoX(65, 96), 3)
32
+ eq(re.iso.toIsoY(65, 96), 2)
33
+
34
+ eq(re.iso.toPosY(65, 96), 75);
35
+
36
+ })
37
+
38
+ it('toIso', function(){
39
+ var e = re.iso.toIso(-9, 90)
40
+
41
+ eq(e.isoX, 2)
42
+
43
+ e = re.iso.toIso(-5, 30)
44
+
45
+ eq(e.isoY, 1)
46
+ })
47
+
48
+ it('toIsoX', function(){
49
+
50
+ eq(re.iso.toIsoX(-9, 90), 2);
51
+ })
52
+
53
+ it('toIsoY', function(){
54
+
55
+ eq(re.iso.toIsoY(-5, 30), 1);
56
+ })
57
+
58
+ it('should add correctly', function(){
59
+
60
+ var oldX = e.isoX();
61
+ e.isoY(4);
62
+
63
+ for(var i=0; i<8; i++){
64
+ e.isoY(e.isoY() + 0.25)
65
+ }
66
+
67
+ eq(e.isoY(), 6);
68
+ eq(e.isoX(), oldX);
69
+
70
+ });
71
+
72
+ it('iso normal args', function(){
73
+
74
+ eq(e.iso(2, 2, 2), e);
75
+
76
+ eq(e.isoX(), 2)
77
+ eq(e.isoY(), 2)
78
+ eq(e.isoZ(), 2)
79
+
80
+ })
81
+
82
+ it('iso obj args', function(){
83
+
84
+ eq(e.iso({x:2, y:2, z:2}), e);
85
+
86
+ eq(e.isoX(), 2)
87
+ eq(e.isoY(), 2)
88
+ eq(e.isoZ(), 2)
89
+
90
+ })
91
+
92
+ it('iso copy other iso position', function(){
93
+
94
+ var iso = re.e('iso');
95
+ iso.iso(2, 2, 2);
96
+
97
+ eq(e.iso(iso), e);
98
+
99
+ eq(e.isoX(), 2)
100
+ eq(e.isoY(), 2)
101
+ eq(e.isoZ(), 2)
102
+
103
+ })
104
+
105
+ it('isoX', function(){
106
+ eq(e.isoX(4), e);
107
+
108
+ eq(e.isoX(), 4);
109
+
110
+ eq(e.posX, 120)
111
+ eq(e.posY, 60)
112
+
113
+ })
114
+
115
+ it('isoY', function(){
116
+ eq(e.isoY(1), e);
117
+
118
+ eq(e.isoY(), 1);
119
+
120
+ eq(e.posX, -30)
121
+ eq(e.posY, 15)
122
+ })
123
+
124
+ it('isoZ', function(){
125
+
126
+ eq(e.isoZ(1), e);
127
+
128
+ eq(e.isoZ(), 1);
129
+ })
130
+
131
+ });