entityjs 0.3.1 → 0.3.2

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 (148) hide show
  1. data/README.md +18 -14
  2. data/entityjs.gemspec +1 -0
  3. data/lib/entityjs/assets.rb +13 -163
  4. data/lib/entityjs/command.rb +5 -2
  5. data/lib/entityjs/commands/build.rb +63 -23
  6. data/lib/entityjs/commands/eunit.rb +44 -0
  7. data/lib/entityjs/commands/release.rb +1 -1
  8. data/lib/entityjs/commands/server.rb +19 -4
  9. data/lib/entityjs/compile.rb +152 -0
  10. data/lib/entityjs/config.rb +8 -0
  11. data/lib/entityjs/dirc.rb +70 -17
  12. data/lib/entityjs/page.rb +106 -0
  13. data/lib/entityjs/parsers/parse_coffee.rb +12 -0
  14. data/lib/entityjs/version.rb +1 -1
  15. data/lib/entityjs.rb +18 -4
  16. data/public/qunit/qunit.css +9 -3
  17. data/public/qunit/qunit.entity.js +113 -31
  18. data/public/qunit/qunit.js +296 -235
  19. data/public/qunit/qunit.mock.js +54 -2
  20. data/public/tests.html +0 -15
  21. data/spec/javascripts/src/cycle/tween_spec.js +59 -0
  22. data/spec/javascripts/src/display/screen_spec.js +0 -15
  23. data/spec/javascripts/src/display/text_spec.js +4 -0
  24. data/spec/javascripts/src/input/mouse_spec.js +18 -18
  25. data/spec/javascripts/src/input/preventdefault_spec.js +14 -0
  26. data/spec/javascripts/src/math/drag_spec.js +2 -2
  27. data/spec/javascripts/src/math/hit_spec.js +24 -0
  28. data/spec/javascripts/src/math/point_spec.js +3 -3
  29. data/spec/javascripts/src/math/tile_spec.js +1 -1
  30. data/spec/javascripts/src/media/sound_spec.js +1 -1
  31. data/spec/javascripts/src/pattern/automap_spec.js +3 -3
  32. data/spec/javascripts/src/pattern/flicker_spec.js +2 -1
  33. data/spec/javascripts/src/util/random_spec.js +17 -0
  34. data/spec/javascripts/src/util/scene_spec.js +15 -0
  35. data/spec/lib/entityjs/assets_spec.rb +2 -201
  36. data/spec/lib/entityjs/commands/build_spec.rb +18 -5
  37. data/spec/lib/entityjs/commands/eunit_spec.rb +18 -0
  38. data/spec/lib/entityjs/commands/release_spec.rb +2 -0
  39. data/spec/lib/entityjs/compile_spec.rb +204 -0
  40. data/spec/lib/entityjs/dirc_spec.rb +8 -4
  41. data/spec/lib/entityjs/page_spec.rb +59 -0
  42. data/spec/support/factories.rb +0 -2
  43. data/src/core/entity.js +4 -18
  44. data/src/core/query.js +1 -1
  45. data/src/core/re.js +6 -6
  46. data/src/core/system.js +17 -12
  47. data/src/cycle/tween.js +93 -31
  48. data/src/display/align.js +11 -6
  49. data/src/display/circle.js +5 -4
  50. data/src/display/imgtext.js +33 -22
  51. data/src/display/screen.js +0 -8
  52. data/src/display/text.js +37 -4
  53. data/src/input/keyboard.js +15 -5
  54. data/src/input/mouse.js +15 -25
  55. data/src/input/preventdefault.js +11 -0
  56. data/src/math/body.js +35 -16
  57. data/src/math/drag.js +2 -2
  58. data/src/math/force.js +2 -2
  59. data/src/math/hit.js +15 -6
  60. data/src/math/hitmap.js +6 -6
  61. data/src/math/point.js +1 -1
  62. data/src/math/tile.js +22 -17
  63. data/src/media/sound.js +1 -1
  64. data/src/pattern/automap.js +16 -27
  65. data/src/pattern/flicker.js +9 -5
  66. data/src/util/random.js +4 -0
  67. data/src/util/scene.js +2 -6
  68. data/templates/arrow_keys/scripts/{display → displays}/arrow.js +0 -0
  69. data/templates/arrow_keys/scripts/{input → inputs}/controls.js +0 -0
  70. data/templates/arrow_keys/tests/{display → displays}/arrow_test.js +1 -1
  71. data/templates/arrow_keys/tests/{input → inputs}/controls_test.js +0 -0
  72. data/templates/arrow_keys/tests/scenes/load_test.js +2 -0
  73. data/templates/{blank → circle}/config.yml +0 -0
  74. data/templates/{blank → circle}/readme.txt +0 -0
  75. data/templates/circle/scripts/init.js +7 -0
  76. data/templates/circle/scripts/scenes/home.js +62 -0
  77. data/templates/circle/scripts/scenes/load.js +11 -0
  78. data/templates/circle/tests/scenes/home_test.js +29 -0
  79. data/templates/circle/tests/scenes/load_test.js +15 -0
  80. data/templates/platform/config.yml +2 -1
  81. data/templates/platform/readme.txt +15 -16
  82. data/templates/platform/scripts/{display → displays}/bit.js +0 -0
  83. data/templates/platform/scripts/{display → displays}/hero.js +0 -0
  84. data/templates/platform/scripts/{display → displays}/tile.js +0 -0
  85. data/templates/platform/scripts/{display → displays}/tsprite.js +0 -0
  86. data/templates/platform/{assets → scripts}/levels/level1.tmx +0 -0
  87. data/templates/platform/scripts/{util → utils}/counter.js +0 -0
  88. data/templates/platform/scripts/{util → utils}/level.js +0 -0
  89. data/templates/platform/tests/{display → displays}/bit_test.js +1 -1
  90. data/templates/platform/tests/displays/hero_test.js +73 -0
  91. data/templates/platform/tests/{display → displays}/tile_test.js +1 -1
  92. data/templates/platform/tests/displays/tsprite_test.js +8 -0
  93. data/templates/platform/tests/items/coin_test.js +10 -10
  94. data/templates/platform/tests/items/item_test.js +9 -9
  95. data/templates/platform/tests/items/spring_test.js +3 -3
  96. data/templates/platform/tests/scenes/load_test.js +2 -1
  97. data/templates/platform/tests/{util → utils}/counter_test.js +2 -2
  98. data/templates/platform/tests/{util → utils}/level_test.js +3 -0
  99. data/templates/pong/config.yml +22 -0
  100. data/templates/pong/readme.txt +3 -0
  101. data/templates/pong/scripts/controls/ai.js +30 -0
  102. data/templates/pong/scripts/controls/arena.js +33 -0
  103. data/templates/pong/scripts/controls/hitmap.js +54 -0
  104. data/templates/pong/scripts/controls/player.js +24 -0
  105. data/templates/pong/scripts/controls/twoarena.js +14 -0
  106. data/templates/pong/scripts/displays/ball.js +29 -0
  107. data/templates/pong/scripts/displays/counter.js +22 -0
  108. data/templates/pong/scripts/displays/paddle.js +22 -0
  109. data/templates/pong/scripts/init.js +9 -0
  110. data/templates/pong/scripts/scenes/game.js +61 -0
  111. data/templates/pong/scripts/scenes/home.js +55 -0
  112. data/templates/pong/scripts/scenes/over.js +29 -0
  113. data/templates/pong/tests/controls/ai_test.js +34 -0
  114. data/templates/pong/tests/controls/arena_test.js +20 -0
  115. data/templates/pong/tests/controls/hitmap_test.js +89 -0
  116. data/templates/pong/tests/controls/player_test.js +25 -0
  117. data/templates/pong/tests/controls/twoarena_test.js +7 -0
  118. data/templates/pong/tests/displays/ball_test.js +10 -0
  119. data/templates/pong/tests/displays/counter_test.js +13 -0
  120. data/templates/pong/tests/displays/paddle_test.js +17 -0
  121. data/templates/pong/tests/scenes/game_test.js +16 -0
  122. data/templates/pong/tests/scenes/home_test.js +30 -0
  123. data/templates/pong/tests/scenes/over_test.js +16 -0
  124. data/templates/tiltmaze/config.yml +25 -0
  125. data/templates/tiltmaze/readme.txt +79 -0
  126. data/templates/tiltmaze/scripts/displays/ball.js +78 -0
  127. data/templates/tiltmaze/scripts/displays/target.js +13 -0
  128. data/templates/tiltmaze/scripts/displays/tile.js +2 -0
  129. data/templates/tiltmaze/scripts/init.js +7 -0
  130. data/templates/tiltmaze/scripts/levels/level1.json +14 -0
  131. data/templates/tiltmaze/scripts/levels/level2.json +14 -0
  132. data/templates/tiltmaze/scripts/levels/level3.json +14 -0
  133. data/templates/tiltmaze/scripts/levels/level4.json +15 -0
  134. data/templates/tiltmaze/scripts/levels/level5.json +18 -0
  135. data/templates/tiltmaze/scripts/scenes/game.js +56 -0
  136. data/templates/tiltmaze/scripts/scenes/home.js +24 -0
  137. data/templates/tiltmaze/scripts/structs/level.js +82 -0
  138. data/templates/tiltmaze/scripts/tiles/walltile.js +147 -0
  139. data/templates/tiltmaze/tests/displays/ball_test.js +67 -0
  140. data/templates/tiltmaze/tests/displays/target_test.js +8 -0
  141. data/templates/tiltmaze/tests/factories.js +38 -0
  142. data/templates/tiltmaze/tests/scenes/game_test.js +59 -0
  143. data/templates/tiltmaze/tests/scenes/home_test.js +7 -0
  144. data/templates/tiltmaze/tests/structs/level_test.js +44 -0
  145. data/templates/tiltmaze/tests/tiles/walltile_test.js +36 -0
  146. metadata +106 -33
  147. data/templates/platform/tests/display/hero_test.js +0 -73
  148. data/templates/platform/tests/display/tsprite_test.js +0 -8
@@ -0,0 +1,82 @@
1
+ re.level = re.c('level')
2
+ .requires('automap')
3
+ .statics({
4
+ get:function(num){
5
+ //find entity with component
6
+ return re('level'+num+'.json')[0];
7
+ }
8
+ })
9
+ .defines({
10
+
11
+ setup:function(){
12
+
13
+ //default value for blanks in automap
14
+ this.automapDefault = re.e('walltile');
15
+
16
+ for(var y=0; y<this.map.length; y++){
17
+ for(var x=0; x<this.map[0].length; x++){
18
+
19
+ var tile = this.map[y][x];
20
+
21
+ if(!tile) continue;
22
+
23
+ //place tiles
24
+ var e = re.walltile.factory(tile)
25
+ .tile(x, y);
26
+
27
+ this.automap(x, y, e);
28
+
29
+ }
30
+ }
31
+
32
+ //place ball
33
+ this.ball = re.e('ball')
34
+ .tile(this.start[0], this.start[1])
35
+ .on('move:update', this.checkTargets);
36
+
37
+ this.ball.level = this;
38
+
39
+ re('target').dispose();
40
+
41
+ //place target
42
+ for(var i in this.targets){
43
+ var targ = this.targets[i];
44
+
45
+ re.e('target')
46
+ .tile(targ[0], targ[1]);
47
+
48
+ }
49
+
50
+ },
51
+
52
+ checkTargets:function(){
53
+
54
+ var ball = this;
55
+
56
+ re('target').each(function(){
57
+
58
+ if(ball.tileX() == this.tileX() && this.tileY() == ball.tileY()){
59
+ this.dispose();
60
+ }
61
+
62
+ });
63
+
64
+ if(re('target').length == 0){
65
+ re.scene('game').advance();
66
+ }
67
+ },
68
+
69
+ teardown:function(){
70
+ //remove tiles
71
+ re('walltile').dispose();
72
+
73
+ re('target').dispose();
74
+
75
+ //remove ball
76
+ re('ball').dispose();
77
+ }
78
+
79
+ })
80
+ .dispose(function(){
81
+ this.teardown();
82
+ });
@@ -0,0 +1,147 @@
1
+ re.walltile = re.c('walltile')
2
+ .statics({
3
+ factory:function(num){
4
+ var e = re.e('walltile');
5
+ switch(num){
6
+ case 1:
7
+ return e.attr({
8
+ topWall:true
9
+ });
10
+
11
+ case 2:
12
+ return e.attr({
13
+ rightWall:true
14
+ });
15
+
16
+ case 3:
17
+ return e.attr({
18
+ bottomWall:true
19
+ });
20
+
21
+ case 4:
22
+ return e.attr({
23
+ leftWall:true
24
+ });
25
+
26
+ case 5:
27
+ return e.attr({
28
+ topWall:true,
29
+ rightWall:true
30
+ });
31
+
32
+ case 6:
33
+ return e.attr({
34
+ bottomWall:true,
35
+ rightWall:true
36
+ });
37
+
38
+ case 7:
39
+ return e.attr({
40
+ leftWall:true,
41
+ bottomWall:true
42
+ });
43
+
44
+ case 8:
45
+ return e.attr({
46
+ topWall:true,
47
+ leftWall:true
48
+ });
49
+
50
+ case 10:
51
+ return e.attr({
52
+ leftWall:true,
53
+ bottomWall:true,
54
+ rightWall:true
55
+ });
56
+
57
+ case 11:
58
+ return e.attr({
59
+ rightWall:true,
60
+ topWall:true,
61
+ bottomWall:true
62
+ });
63
+
64
+ case 12:
65
+ return e.attr({
66
+ topWall:true,
67
+ rightWall:true,
68
+ leftWall:true
69
+ })
70
+
71
+ case 13:
72
+ return e.attr({
73
+ topWall:true,
74
+ leftWall:true,
75
+ bottomWall:true
76
+ })
77
+ }
78
+
79
+ return null;
80
+ }
81
+ })
82
+ .requires('tile draw')
83
+ .defines({
84
+
85
+ leftWall:false,
86
+ rightWall:false,
87
+ topWall:false,
88
+ bottomWall:false,
89
+
90
+ thick:3,
91
+
92
+ draw:function(c){
93
+
94
+ c.fillStyle = '#000';
95
+
96
+ //first wall
97
+ if(this.topWall){
98
+ c.fillRect(0, 0, this.sizeX, this.thick);
99
+ }
100
+
101
+ //bottom wall
102
+ if(this.bottomWall){
103
+ c.fillRect(0, this.sizeY - this.thick, this.sizeX, this.thick);
104
+ }
105
+
106
+ //left wall
107
+ if(this.leftWall){
108
+ c.fillRect(0, 0, this.thick, this.sizeY);
109
+ }
110
+
111
+ //right wall
112
+ if(this.rightWall){
113
+ c.fillRect(this.sizeX - this.thick, 0, this.thick, this.sizeY);
114
+ }
115
+
116
+ },
117
+
118
+ checkWall:function(x, y){
119
+ if(y == 1){
120
+ return this.topWall;
121
+ } else if(y == -1){
122
+ return this.bottomWall;
123
+ }
124
+
125
+ if(x == 1){
126
+ return this.leftWall;
127
+ } else if(x == -1){
128
+ return this.rightWall;
129
+ }
130
+
131
+ },
132
+
133
+ checkWallInside:function(x, y){
134
+ if(y == 1){
135
+ return this.bottomWall;
136
+ } else if(y == -1){
137
+ return this.topWall;
138
+ }
139
+
140
+ if(x == 1){
141
+ return this.rightWall;
142
+ } else if(x == -1){
143
+ return this.leftWall;
144
+ }
145
+ }
146
+
147
+ });
@@ -0,0 +1,67 @@
1
+ module('displays/ball', lazy('level box', function(){
2
+ ball = level.ball;
3
+ }));
4
+
5
+ test('move up correctly', function(){
6
+ stop();
7
+
8
+ ball.on('move:finish', function(){
9
+ eq(this.tileY(), 0);
10
+ start();
11
+ });
12
+
13
+ ball.tileY(2);
14
+
15
+ keypress('w', function(){
16
+ ball.update();
17
+ });
18
+
19
+ });
20
+
21
+ test('move down correctly', function(){
22
+ stop();
23
+
24
+ ball.on('move:finish', function(){
25
+ eq(this.tileY(), level.map.length-1);
26
+ start();
27
+ });
28
+
29
+ keypress('s', function(){
30
+ ball.update();
31
+ });
32
+
33
+ });
34
+
35
+ test('move right correctly', function(){
36
+ stop();
37
+
38
+ ball.on('move:finish', function(){
39
+ eq(this.tileX(), level.map[0].length-1);
40
+ start();
41
+ });
42
+
43
+ ball.tileX(0);
44
+
45
+ keypress('d', function(){
46
+ ball.update();
47
+ });
48
+
49
+ });
50
+
51
+ test('move left correctly', function(){
52
+ stop();
53
+
54
+ var width = level.map[0].length -1;
55
+
56
+ ball.on('move:finish', function(){
57
+ eq(this.tileX(), 0);
58
+ start();
59
+ });
60
+
61
+ ball.tileX(width);
62
+
63
+ keypress('a', function(){
64
+ ball.update();
65
+ });
66
+
67
+ });
@@ -0,0 +1,8 @@
1
+ module('displays/target', lazy('target'));
2
+
3
+ test('draws correctly', function(){
4
+
5
+ //uncomment stop to see it on canvas
6
+ //stop();
7
+ expect(0);
8
+ });
@@ -0,0 +1,38 @@
1
+ factory('level', function(){
2
+ this.targets = [];
3
+ this.map = [[]];
4
+ this.start = [0,0];
5
+
6
+ this.setup();
7
+ });
8
+
9
+ //fake level for ball testing
10
+ factory('level box', function(){
11
+ this.targets = [
12
+ [4, 4],
13
+ [3, 1]
14
+ ];
15
+
16
+ this.map = [
17
+ [8,1,1,1,5],
18
+ [4,0,0,0,2],
19
+ [4,0,0,0,2],
20
+ [4,0,0,0,2],
21
+ [7,3,3,3,6]
22
+ ];
23
+
24
+ this.start = [0,0];
25
+
26
+ this.setup();
27
+ });
28
+
29
+ factory('ball', function(){
30
+
31
+ //stub out level
32
+ this.level = {
33
+ automap:function(){
34
+ return null;
35
+ }
36
+ };
37
+
38
+ });
@@ -0,0 +1,59 @@
1
+ module('scenes/game', lazyScene('game'));
2
+
3
+ test('load level', function(){
4
+
5
+ is(game.currentLevel);
6
+
7
+ });
8
+
9
+ test('quit on keyup', function(){
10
+
11
+ expectCall(game, 'quit');
12
+
13
+ keyup('q');
14
+
15
+ })
16
+
17
+ test('restart on keyup', function(){
18
+
19
+ expectCall(game, 'restart');
20
+
21
+ keyup('r');
22
+
23
+ });
24
+
25
+ //uncomment the stop to test the level
26
+ test('test level1.json', function(){
27
+ //stop();
28
+ re.scene('game').enter(2);
29
+
30
+ expect(0);
31
+ });
32
+
33
+ test('test level2.json', function(){
34
+ //stop();
35
+ re.scene('game').enter(2);
36
+
37
+ expect(0);
38
+ });
39
+
40
+ test('test level3.json', function(){
41
+ //stop();
42
+ re.scene('game').enter(3);
43
+
44
+ expect(0);
45
+ });
46
+
47
+ test('test level4.json', function(){
48
+ //stop();
49
+ re.scene('game').enter(4);
50
+
51
+ expect(0);
52
+ });
53
+
54
+ test('test level5.json', function(){
55
+ //stop();
56
+ re.scene('game').enter(5);
57
+
58
+ expect(0);
59
+ });
@@ -0,0 +1,7 @@
1
+ module('scenes/home', lazyScene('home'));
2
+
3
+ test('entities should exist', function(){
4
+
5
+ expect(0);
6
+
7
+ });
@@ -0,0 +1,44 @@
1
+ module('structs/level', lazy('level box'));
2
+
3
+ test('defines ball', function(){
4
+
5
+ ball = level.ball;
6
+
7
+ is(ball);
8
+
9
+ eq(ball.level, level);
10
+
11
+ });
12
+
13
+ test('defines targets', function(){
14
+
15
+ //lazy smoke test
16
+ ok(re('target').length != 0);
17
+
18
+ });
19
+
20
+ test('collects targets advances to next level', function(){
21
+
22
+ //two targets are in the level
23
+ //collecting them should advance to the next one
24
+
25
+ expectCall(re.scene('game'), 'advance');
26
+
27
+ var ball = level.ball;
28
+
29
+ var first = re('target')[0];
30
+
31
+ //move to target
32
+ ball.tile(first);
33
+
34
+ ball.trigger('move:update');
35
+
36
+ eq(re('target').length, 1);
37
+
38
+ var last = re('target')[0];
39
+
40
+ ball.tile(last);
41
+
42
+ ball.trigger('move:update');
43
+
44
+ });
@@ -0,0 +1,36 @@
1
+ module('tiles/walltile', lazy('walltile'));
2
+
3
+ test('display correctly', function(){
4
+
5
+ //testing the visual
6
+ //use stop() to see it
7
+ walltile.topWall = true;
8
+ walltile.bottomWall = true;
9
+ walltile.leftWall = true;
10
+ walltile.rightWall = true;
11
+
12
+ expect(0);
13
+
14
+ });
15
+
16
+ //these are mostly smoke tests
17
+ //just making sure the methods don't crash
18
+ test('create factory wall tile', function(){
19
+
20
+ ok(re.walltile.factory(1).topWall);
21
+
22
+ });
23
+
24
+ test('checkWall', function(){
25
+ walltile.topWall = true;
26
+
27
+ ok(walltile.checkWall(0, 1));
28
+
29
+ });
30
+
31
+ test('checkWallInside', function(){
32
+ walltile.bottomWall = true;
33
+
34
+ ok(walltile.checkWallInside(0, 1));
35
+
36
+ });