entityjs 0.4.1 → 0.4.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 (111) hide show
  1. data/.gitignore +1 -0
  2. data/bin/entityjs +1 -1
  3. data/entityjs.gemspec +3 -2
  4. data/lib/entityjs.rb +13 -1
  5. data/lib/entityjs/command.rb +22 -16
  6. data/lib/entityjs/commands/build.rb +96 -48
  7. data/lib/entityjs/commands/eunit.rb +1 -1
  8. data/lib/entityjs/commands/html.rb +31 -0
  9. data/lib/entityjs/commands/min.rb +37 -0
  10. data/lib/entityjs/commands/new.rb +3 -0
  11. data/lib/entityjs/commands/server.rb +9 -3
  12. data/lib/entityjs/config.rb +163 -59
  13. data/lib/entityjs/dirc.rb +28 -0
  14. data/lib/entityjs/page.rb +73 -34
  15. data/lib/entityjs/version.rb +1 -1
  16. data/public/favicon.ico +0 -0
  17. data/public/play.html +33 -28
  18. data/public/qunit/qunit.entity.js +56 -6
  19. data/public/qunit/qunit.input.js +5 -5
  20. data/public/test.html +49 -0
  21. data/spec/javascripts/src/core/comp_spec.js +17 -6
  22. data/spec/javascripts/src/core/entity_spec.js +4 -5
  23. data/spec/javascripts/src/core/query_spec.js +25 -0
  24. data/spec/javascripts/src/core/re_spec.js +3 -3
  25. data/spec/javascripts/src/cycle/update_spec.js +8 -8
  26. data/spec/javascripts/src/display/align_spec.js +2 -2
  27. data/spec/javascripts/src/display/el_spec.js +17 -0
  28. data/spec/javascripts/src/input/keyboard_spec.js +4 -4
  29. data/spec/javascripts/src/input/mouse_spec.js +8 -7
  30. data/spec/javascripts/src/math/random_spec.js +8 -0
  31. data/spec/javascripts/src/util/clone_spec.js +20 -0
  32. data/spec/lib/entityjs/commands/build_spec.rb +3 -8
  33. data/spec/lib/entityjs/commands/html_spec.rb +27 -0
  34. data/spec/lib/entityjs/commands/min_spec.rb +30 -0
  35. data/spec/lib/entityjs/config_spec.rb +6 -0
  36. data/spec/lib/entityjs/page_spec.rb +4 -4
  37. data/src/core/comp.js +87 -31
  38. data/src/core/entity.js +38 -43
  39. data/src/core/load.js +2 -8
  40. data/src/core/query.js +17 -5
  41. data/src/core/re.js +1 -1
  42. data/src/core/system.js +8 -11
  43. data/src/cycle/drawlist.js +11 -11
  44. data/src/cycle/update.js +5 -5
  45. data/src/display/align.js +10 -3
  46. data/src/display/animate.js +26 -12
  47. data/src/display/el.js +99 -0
  48. data/src/input/keyboard.js +5 -5
  49. data/src/input/mouse.js +16 -11
  50. data/src/math/bisect.js +1 -1
  51. data/src/math/force.js +4 -4
  52. data/src/math/hitmap.js +2 -1
  53. data/src/math/iso.js +1 -1
  54. data/src/math/random.js +17 -2
  55. data/src/math/tile.js +1 -1
  56. data/src/media/sound.js +1 -1
  57. data/src/pattern/pathfind.js +2 -4
  58. data/src/save/storage.js +1 -1
  59. data/src/util/clone.js +12 -0
  60. data/src/util/scene.js +21 -16
  61. data/templates/circle/game.json +16 -0
  62. data/templates/circle/scripts/displays/circle.js +40 -0
  63. data/templates/circle/scripts/scenes/home.js +8 -17
  64. data/templates/circle/tests/scenes/home_test.js +3 -11
  65. data/templates/dom/game.json +6 -0
  66. data/templates/dom/scripts/els/btn.js +5 -0
  67. data/templates/dom/scripts/els/contain.js +5 -0
  68. data/templates/dom/scripts/els/header.js +5 -0
  69. data/templates/{animation → dom}/scripts/init.js +0 -0
  70. data/templates/dom/scripts/scenes/home.js +22 -0
  71. data/templates/{animation → dom}/scripts/scenes/load.js +0 -0
  72. data/templates/dom/tests/scenes/home_test.js +9 -0
  73. data/templates/{animation → dom}/tests/scenes/load_test.js +0 -0
  74. data/templates/isometric/game.json +16 -0
  75. data/templates/platform/game.json +18 -0
  76. data/templates/platform/scripts/displays/hero.js +1 -1
  77. data/templates/platform/scripts/items/coin.js +1 -1
  78. data/templates/platform/scripts/items/spring.js +1 -1
  79. data/templates/platform/tests/displays/hero_test.js +4 -4
  80. data/templates/platform/tests/factories.js +1 -1
  81. data/templates/platform/tests/items/coin_test.js +1 -1
  82. data/templates/pong/game.json +16 -0
  83. data/templates/tiltmaze/game.json +16 -0
  84. data/templates/tiltmaze/scripts/structs/level.js +1 -1
  85. data/templates/tiltmaze/scripts/tiles/walltile.js +1 -1
  86. metadata +45 -32
  87. data/.rspec +0 -2
  88. data/public/tests.html +0 -31
  89. data/src/cycle/worker.js +0 -9
  90. data/templates/animation/assets/images/hero.png +0 -0
  91. data/templates/animation/scripts/scenes/home.js +0 -41
  92. data/templates/animation/tests/init_test.js +0 -4
  93. data/templates/animation/tests/scenes/home_test.js +0 -15
  94. data/templates/arrow_keys/assets/images/arrow.png +0 -0
  95. data/templates/arrow_keys/config.yml +0 -22
  96. data/templates/arrow_keys/readme.txt +0 -9
  97. data/templates/arrow_keys/scripts/displays/arrow.js +0 -69
  98. data/templates/arrow_keys/scripts/init.js +0 -10
  99. data/templates/arrow_keys/scripts/inputs/controls.js +0 -35
  100. data/templates/arrow_keys/scripts/scenes/home.js +0 -20
  101. data/templates/arrow_keys/scripts/scenes/load.js +0 -57
  102. data/templates/arrow_keys/tests/displays/arrow_test.js +0 -29
  103. data/templates/arrow_keys/tests/init_test.js +0 -4
  104. data/templates/arrow_keys/tests/inputs/controls_test.js +0 -32
  105. data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
  106. data/templates/arrow_keys/tests/scenes/load_test.js +0 -18
  107. data/templates/circle/config.yml +0 -22
  108. data/templates/isometric/config.yml +0 -22
  109. data/templates/platform/config.yml +0 -23
  110. data/templates/pong/config.yml +0 -22
  111. data/templates/tiltmaze/config.yml +0 -25
@@ -1,3 +1,3 @@
1
1
  module Entityjs
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
Binary file
@@ -4,19 +4,30 @@
4
4
  <head>
5
5
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
6
6
 
7
- <title>EntityJS Play Game</title>
8
-
9
- $JS
7
+ <title>RE_TITLE</title>
8
+ <link rel="Shortcut Icon" href="/favicon.ico">
10
9
 
10
+ RE_JS
11
+
12
+ RE_CSS
13
+
11
14
  <style type="text/css">
12
15
  /*
13
16
  Styling for play.html
14
17
  */
15
- canvas {
18
+ .RE_CANVAS-CONTAINER {
16
19
  margin-left: auto;
17
20
  margin-right: auto;
18
- display: block;
19
- border:1px #333 solid;
21
+ width: RE_WIDTHpx;
22
+ position:relative;
23
+ }
24
+
25
+ /*
26
+ For el comp
27
+ */
28
+ .el {
29
+ z-index:100;
30
+ position:absolute;
20
31
  }
21
32
 
22
33
  body {
@@ -33,28 +44,20 @@
33
44
  background-color:#ffffff;
34
45
 
35
46
  }
36
- h1, h2, h3 {
37
- font-weight:700;
38
- }
39
-
40
- h1 {
41
- font-size:30px;
42
- margin:10px 0 20px 5px;
43
- color:#D94E4E;
44
- }
45
- a, a:visited {
47
+
48
+ .links a, .links a:visited {
46
49
  color:#5b9463;
47
50
  }
48
51
 
49
- a:hover {
52
+ .links a:hover {
50
53
  color:#77b981;
51
54
  }
52
55
 
53
- a.highlight, a.highlight:visited {
56
+ .links a.highlight, .links a.highlight:visited {
54
57
  color:#D94E4E;
55
58
  }
56
59
 
57
- a.highlight:hover {
60
+ .links a.highlight:hover {
58
61
  color:#ec7979;
59
62
  }
60
63
 
@@ -62,16 +65,19 @@
62
65
  margin-top:25px;
63
66
  }
64
67
 
65
- ul li{
68
+ ul.links li{
66
69
  margin:5px;
67
70
  display:inline-block;
68
71
  }
69
- .links {
72
+
73
+ .float-right {
70
74
  float:right;
71
75
  }
72
- .game-links {
76
+
77
+ .float-left {
73
78
  float:left;
74
79
  }
80
+
75
81
  .clear {
76
82
 
77
83
  clear: both;
@@ -88,10 +94,9 @@
88
94
 
89
95
 
90
96
  <div id="content">
91
- <h1>Play</h1>
92
97
 
93
- <div class="canvas-container">
94
- <canvas id="$CANVAS_ID" width="$WIDTH" height="$HEIGHT">
98
+ <div class="RE_CANVAS-CONTAINER">
99
+ <canvas id="RE_CANVAS-ID" width="RE_WIDTH" height="RE_HEIGHT">
95
100
  <p>
96
101
  Requires a modern browser to play. Try downloading <a href="http://google.com/chrome">Chrome</a>.
97
102
  </p>
@@ -99,11 +104,11 @@
99
104
  </div>
100
105
 
101
106
  <div class="block">
102
- <ul class="game-links">
103
- <li><a href="/tests">Test Suite</a></li>
107
+ <ul class="links float-left">
108
+ <li><a href="/test">Test Suite</a></li>
104
109
  </ul>
105
110
 
106
- <ul class="links">
111
+ <ul class="links float-right">
107
112
  <li><a href="http://entityjs.com" class="highlight" target="_blank">EntityJS</a></li>
108
113
  <li><a href="http://entityjs.com/tutorials" target="_blank">Tutorials</a></li>
109
114
  <li><a href="http://entityjs.com/api" target="_blank">API</a></li>
@@ -16,11 +16,6 @@ ETest.prototype.run = function(){
16
16
  ok(this.check(), this.message);
17
17
  };
18
18
 
19
- /*
20
- Disable re.ready for testing
21
- */
22
- re.ready = function(){};
23
-
24
19
  /*
25
20
  Expects a trigger call from the given obj.
26
21
 
@@ -165,6 +160,14 @@ var customCoin = f('coin', function(){
165
160
  customCoin.value //10
166
161
  customCoin.getValue(); //10
167
162
 
163
+ //create custom enemy
164
+
165
+ test('blah', function(){
166
+
167
+ enemy = f('enemy', {health:100, attack:10});
168
+
169
+ });
170
+
168
171
  */
169
172
  var _factories = {};
170
173
  function factory(comps, func){
@@ -179,6 +182,9 @@ function factory(comps, func){
179
182
  //call defined factory
180
183
  if(_factories[comps]) _factories[comps].call(e);
181
184
 
185
+ //add custom attributes
186
+ if(typeof func == 'object') e.attr(func);
187
+
182
188
  //call custom method
183
189
  if(func) func.call(e);
184
190
  return e;
@@ -236,10 +242,25 @@ function lazy(comps, obj){
236
242
  }
237
243
  }
238
244
 
239
- function lazyScene(scene, args){
245
+ /*
246
+ Simple scene testing.
247
+
248
+ module('scenes/home', lazyScene('home', 'hello'));
249
+
250
+ //goes into home..
251
+ //re.scene('home').enter('hello');
252
+ test('shows title', function(){
253
+ eq(re('text').first().text(), 'hello');
254
+ });
255
+ //afterwards
256
+ //re.scene('home').exit();
257
+ */
258
+ function lazyScene(scene){
259
+ var args = Array.prototype.slice.call(arguments, 1);
240
260
  return {
241
261
  setup:function(){
242
262
  var s = window[scene] = re.scene(scene);
263
+
243
264
  s.enter.apply(s, args);
244
265
  },
245
266
  teardown:function(){
@@ -253,6 +274,15 @@ Some super lazy evaluations
253
274
  */
254
275
  var eq = equal;
255
276
  var not = function(arg, message){ok(!arg, message);}
277
+
278
+ /*
279
+ Object exists or is of type.
280
+
281
+ is({}, 'object');
282
+ is(null) //false
283
+ is(1)
284
+ is('sdsf', 'string') //true
285
+ */
256
286
  function is(obj, type){
257
287
  if(arguments.length == 1){
258
288
  ok(obj != null, "Expected to be present");
@@ -261,6 +291,26 @@ function is(obj, type){
261
291
  }
262
292
  }
263
293
 
294
+ /*
295
+ Between or equal to two numbers
296
+
297
+ between(10, 30, 90)
298
+ */
299
+ function between(test, low, high){
300
+ if(low > high){
301
+ var t = low;
302
+ low = high;
303
+ high = t;
304
+ }
305
+
306
+ ok(test >= low && test <= high, "Expected to be between "+low+"-"+high);
307
+ }
308
+
309
+ /*
310
+ Matches a regular expression
311
+
312
+ match('hello', /h/, 'i');
313
+ */
264
314
  function match(test, reg, i){
265
315
  if(typeof reg == 'string'){
266
316
  reg = new RegExp(reg, i)
@@ -3,7 +3,7 @@ EntityJS methods to simulate user inputs.
3
3
  */
4
4
 
5
5
  function _findKeyCode(code){
6
- var codes = re.c('keyboard').keyCodes;
6
+ var codes = re.keyboard.keyCodes;
7
7
 
8
8
  for(var i in codes){
9
9
  if(codes[i] == code){
@@ -25,7 +25,7 @@ function keydown(key, e){
25
25
  e.type = 'keydown';
26
26
  e.keyCode = _findKeyCode(key);
27
27
 
28
- re.c('keyboard').event(e);
28
+ re.keyboard.event(e);
29
29
  };
30
30
 
31
31
  /*
@@ -38,7 +38,7 @@ function keyup(key, e){
38
38
  e.type = 'keyup';
39
39
  e.keyCode = _findKeyCode(key);
40
40
 
41
- re.c('keyboard').event(e);
41
+ re.keyboard.event(e);
42
42
  };
43
43
 
44
44
  /*
@@ -88,9 +88,9 @@ function _mouseEvent(e, type, x, y, key){
88
88
  e.clientX = y + document.body.scrollTop + document.documentElement.scrollTop;
89
89
 
90
90
  if(key){
91
- re.c('mouse').press(e);
91
+ re.mouse.press(e);
92
92
  } else {
93
- re.c('mouse').event(e);
93
+ re.mouse.event(e);
94
94
  }
95
95
  }
96
96
 
@@ -0,0 +1,49 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Test RE_TITLE</title>
5
+
6
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
7
+ <link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
8
+
9
+ RE_JS
10
+
11
+ RE_CSS
12
+
13
+ <style type="text/css">
14
+ /*
15
+ Styling for play.html
16
+ */
17
+ .RE_CANVAS-CONTAINER {
18
+ margin-left: auto;
19
+ margin-right: auto;
20
+ width: RE_WIDTHpx;
21
+ position:relative;
22
+ }
23
+
24
+ /*
25
+ For el comp
26
+ */
27
+ .el {
28
+ z-index:100;
29
+ position:absolute;
30
+ }
31
+ </style>
32
+
33
+ </head>
34
+ <body>
35
+ <h1 id="qunit-header">Game Test Suite</h1>
36
+ <h2 id="qunit-banner"></h2>
37
+ <div id="qunit-testrunner-toolbar"></div>
38
+ <h2 id="qunit-userAgent"></h2>
39
+ <ol id="qunit-tests"></ol>
40
+
41
+ <div class="RE_CANVAS-CONTAINER">
42
+ <canvas width="RE_WIDTH" height="RE_HEIGHT" id="RE_CANVAS-ID">Browser does not support canvas element</canvas>
43
+ </div>
44
+
45
+ <div class="links">
46
+ <a href="/">Play Game</a>
47
+ </div>
48
+ </body>
49
+ </html>
@@ -16,9 +16,20 @@ describe('comp', function(){
16
16
  })
17
17
  .statics('yep', 'yep');
18
18
 
19
- eq(k.type, 10)
20
- eq(k.yep, 'yep')
19
+ eq(re[k.name].type, 10)
20
+ eq(re[k.name].yep, 'yep')
21
21
  })
22
+
23
+ it('should create a factory', function(){
24
+ var val = 10;
25
+
26
+ k.factory(function(ref){
27
+ this.ref = ref;
28
+ });
29
+
30
+ eq(re[k.name](val).ref, val);
31
+
32
+ });
22
33
 
23
34
  it('should add events', function(){
24
35
  k.events('mouseup', function(){})
@@ -53,7 +64,7 @@ describe('comp', function(){
53
64
  k
54
65
  .interfaces('bob');
55
66
 
56
- contains(k._re_implements, 'bob')
67
+ contains(k._re_interfaces, 'bob')
57
68
  })
58
69
 
59
70
  it('should alias', function(){
@@ -89,9 +100,9 @@ describe('comp', function(){
89
100
  })
90
101
  .defaults('ok3', 3);
91
102
 
92
- ok(k._re_inherits['ok3'] == 3)
93
- ok(k._re_inherits['ok2'] == 2)
94
- ok(k._re_inherits['ok'] == 1)
103
+ ok(k._re_defaults['ok3'] == 3)
104
+ ok(k._re_defaults['ok2'] == 2)
105
+ ok(k._re_defaults['ok'] == 1)
95
106
  })
96
107
 
97
108
  it('should namespaces', function(){
@@ -23,7 +23,7 @@ describe('entity', function(){
23
23
  it('should get', function(){
24
24
  e.blah = 10;
25
25
  e.bla = function(){
26
- return 10;
26
+ return this.blah;
27
27
  };
28
28
 
29
29
  eq(e.get('blah'), 10);
@@ -73,15 +73,14 @@ describe('entity', function(){
73
73
  it('should call init', function(){
74
74
  var called = false
75
75
  var v1, v2;
76
- c.init(function(comp, val1, val2){
76
+ c.init(function(val1, val2){
77
77
  called = true
78
78
  v1 = val1
79
79
  v2 = val2
80
80
  })
81
81
  var called2 = false
82
- c.on('init', function(y){
82
+ c.on('init', function(){
83
83
  called2 = true
84
- ok(y == e)
85
84
  })
86
85
  e.comp(c.name+':10:99')
87
86
 
@@ -295,7 +294,7 @@ describe('entity', function(){
295
294
  //remove all
296
295
  e.on('key', function(){});
297
296
  is(e.off());
298
- eq(e._re_signals, {});
297
+ eq(e._re_listens, {});
299
298
  })
300
299
 
301
300
  it('should change context of event', function(){
@@ -29,6 +29,31 @@ describe('query', function(){
29
29
  eq(re(g).length, 1)
30
30
  });
31
31
 
32
+ it('should query by value', function(){
33
+
34
+ var v = re.e().team = {num:1};
35
+ //todo in the future?
36
+ //a bit complicated
37
+ //eq(re('team.num=1').length, 1)
38
+
39
+ });
40
+
41
+ it('should reject elements', function(){
42
+ var k = re([1, 2, 3]);
43
+
44
+ var that = this;
45
+
46
+ is(k.reject(function(e, i, l){
47
+ is(i)
48
+ is(l)
49
+ eq(that, this)
50
+ return e == 1 || e == 3;
51
+ }, this));
52
+
53
+ eq(k[0], 2);
54
+
55
+ });
56
+
32
57
  it('should return empty query', function(){
33
58
  eq(re().length, 0);
34
59
  })
@@ -26,10 +26,10 @@ describe('re', function(){
26
26
  teardown_canvas()
27
27
  })
28
28
 
29
- it('should create element', function(){
30
- is(re.$new('canvas'))
29
+ it('should create canvas', function(){
30
+ is(re.$new('canvas'), 'htmlcanvaselement')
31
31
  })
32
-
32
+
33
33
  it('should re.is work', function(){
34
34
  ok(re.is({}))
35
35
  ok(re.is(1))