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
@@ -17,27 +17,27 @@ describe('update', function(){
17
17
 
18
18
  is(k.updateFirst())
19
19
  var l = 0;
20
- eq(re._c.update.l[l], k)
20
+ eq(re.update.l[l], k)
21
21
  })
22
22
 
23
23
  it('update last', function(){
24
24
  is(k.updateLast())
25
- var l = re._c.update.l.length-1;
26
- eq(re._c.update.l[l], k)
25
+ var l = re.update.l.length-1;
26
+ eq(re.update.l[l], k)
27
27
  })
28
28
 
29
29
  it('update after', function(){
30
30
  is(k.updateAfter(last))
31
31
 
32
- var him = re._c.update.l.indexOf(last)
33
- eq(re._c.update.l[him+1], k)
32
+ var him = re.update.l.indexOf(last)
33
+ eq(re.update.l[him+1], k)
34
34
  })
35
35
 
36
36
  it('update before', function(){
37
37
  is(k.updateBefore(last))
38
38
 
39
- var him = re._c.update.l.indexOf(last)
40
- eq(re._c.update.l[him-1], k)
39
+ var him = re.update.l.indexOf(last)
40
+ eq(re.update.l[him-1], k)
41
41
 
42
42
  })
43
43
 
@@ -56,7 +56,7 @@ describe('update', function(){
56
56
  called2 = true
57
57
  })
58
58
 
59
- re.c('update').update(10)
59
+ re.update.update(10)
60
60
 
61
61
  ok(called2)
62
62
  ok(called)
@@ -8,12 +8,12 @@ describe('align', function(){
8
8
 
9
9
  it('align hor', function(){
10
10
  is(e.alignHor(10));
11
- eq(e.posX, re.sys.sizeX * 0.5 - e.sizeX * 0.5 + 10)
11
+ eq(e.posX, re.sys.sizeX * 0.5 - e.sizeX * 0.5 + 10 |0)
12
12
  });
13
13
 
14
14
  it('align ver', function(){
15
15
  is(e.alignVer(1));
16
- eq(e.posY, re.sys.sizeY * 0.5 - e.sizeY * 0.5 + 1)
16
+ eq(e.posY, re.sys.sizeY * 0.5 - e.sizeY * 0.5 + 1 |0)
17
17
 
18
18
  });
19
19
 
@@ -0,0 +1,17 @@
1
+ describe('displays/el', function(){
2
+
3
+ var e;
4
+
5
+ beforeEach(function(){
6
+ e = re.e('el:div');
7
+ })
8
+
9
+ it('should define valid dom', function(){
10
+ is(e.el, 'htmldivelement');
11
+ eq(e.posX(), 0)
12
+ eq(e.posY(), 0)
13
+ eq(e.sizeX(), 0)
14
+ eq(e.sizeY(), 0)
15
+ })
16
+
17
+ });
@@ -21,12 +21,12 @@ describe('keyboard', function(){
21
21
  });
22
22
 
23
23
  //manually call
24
- re.c('keyboard').event({type:type, keyCode:68})//d
24
+ re.keyboard.event({type:type, keyCode:68})//d
25
25
 
26
26
  eq(called, 'd')
27
27
  eq(called2, null)
28
28
 
29
- re.c('keyboard').event({type:type, keyCode:82})//r
29
+ re.keyboard.event({type:type, keyCode:82})//r
30
30
 
31
31
  eq(called, 'r')
32
32
  eq(called2, 'r')
@@ -48,12 +48,12 @@ describe('keyboard', function(){
48
48
  });
49
49
 
50
50
  //manually call
51
- re.c('keyboard').event({type:type, keyCode:68})//d
51
+ re.keyboard.event({type:type, keyCode:68})//d
52
52
 
53
53
  eq(called, 'd')
54
54
  eq(called2, null)
55
55
 
56
- re.c('keyboard').event({type:type, keyCode:82})//r
56
+ re.keyboard.event({type:type, keyCode:82})//r
57
57
 
58
58
  eq(called, 'r')
59
59
  eq(called2, 'r')
@@ -22,7 +22,7 @@ describe('mouse', function(){
22
22
  is(m)
23
23
  })
24
24
 
25
- re.c('mouse').event({type:type, offsetX:0, offsetY:0}, 'middle')
25
+ re.mouse.event({type:type, offsetX:0, offsetY:0}, 'middle')
26
26
 
27
27
  ok(called2)
28
28
  ok(called)
@@ -44,7 +44,7 @@ describe('mouse', function(){
44
44
  is(m)
45
45
  })
46
46
 
47
- re.c('mouse').event({type:type, offsetX:0, offsetY:0}, 'middle')
47
+ re.mouse.event({type:type, offsetX:0, offsetY:0}, 'middle')
48
48
 
49
49
  ok(called2)
50
50
  ok(called)
@@ -63,7 +63,7 @@ describe('mouse', function(){
63
63
  is(e)
64
64
  });
65
65
 
66
- re.c('mouse').event({type:type, offsetX:0, offsetY:0})
66
+ re.mouse.event({type:type, offsetX:0, offsetY:0})
67
67
 
68
68
  ok(called)
69
69
  });
@@ -75,12 +75,12 @@ describe('mouse', function(){
75
75
 
76
76
  e.on(type, function(x,y, e){
77
77
  called = true
78
+ is(e)
78
79
  is(x)
79
80
  is(y)
80
- is(e)
81
81
  });
82
82
 
83
- re.c('mouse').event({type:type, offsetX:0, offsetY:0})
83
+ re.mouse.event({type:type, offsetX:50, offsetY:100})
84
84
 
85
85
  ok(called)
86
86
  })
@@ -97,7 +97,7 @@ describe('mouse', function(){
97
97
  is(e)
98
98
  });
99
99
 
100
- re.c('mouse').event({type:type, offsetX:0, offsetY:0})
100
+ re.mouse.event({type:type, offsetX:0, offsetY:0})
101
101
 
102
102
  ok(called)
103
103
  })
@@ -114,8 +114,9 @@ describe('mouse', function(){
114
114
  is(e)
115
115
  });
116
116
 
117
- re.c('mouse').event({type:type, offsetX:0, offsetY:0})
117
+ re.mouse.event({type:type, offsetX:0, offsetY:0})
118
118
 
119
119
  ok(called)
120
120
  })
121
+
121
122
  });
@@ -46,5 +46,13 @@ describe('random', function(){
46
46
  }
47
47
 
48
48
  });
49
+
50
+ it('random prop from object', function(){
51
+ var obj = {ok:10, blah:2, t:3};
52
+
53
+ var prop = re.random(obj);
54
+
55
+ ok(prop == 'ok' || prop == 'blah' || prop == 't')
56
+ })
49
57
 
50
58
  });
@@ -0,0 +1,20 @@
1
+ describe('util/clone', function(){
2
+
3
+ it('should clone object', function(){
4
+ var k = {ok:10, blah:[]}
5
+
6
+ var b = re.clone(k);
7
+
8
+ eq(b.ok, k.ok)
9
+ eq(b.blah, k.blah)
10
+ })
11
+
12
+ it('should clone array', function(){
13
+ var k = [1,2];
14
+
15
+ var b = re.clone(k);
16
+
17
+ eq(b, k)
18
+ })
19
+
20
+ });
@@ -10,17 +10,12 @@ describe 'build' do
10
10
  teardown_mygame
11
11
  end
12
12
 
13
- it 'should run' do
14
- #turn this off, too much garbage made
15
- #Entityjs::Command.run('build', []).should == 0
16
- end
17
-
18
- it 'should run release1' do
13
+ it 'should build' do
19
14
 
20
15
  name = "release#{rand(999)}"
21
16
  Entityjs::Command.run('b', [name]).should == 0
22
17
 
23
- dir = Entityjs::Config.builds_folder+"/"+name
18
+ dir = Entityjs::Config.build_folder
24
19
 
25
20
  File.directory?(dir).should == true
26
21
 
@@ -44,7 +39,7 @@ describe 'build' do
44
39
  end
45
40
 
46
41
 
47
- it 'should build a throwthegame' do
42
+ it 'should build' do
48
43
  #compile given source
49
44
  sounds = "[]"
50
45
  images = "['blah.png']"
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Html' do
4
+
5
+ before(:all) do
6
+ setup_mygame
7
+ end
8
+
9
+ after(:all) do
10
+ teardown_mygame
11
+ end
12
+
13
+ it 'should generate html files' do
14
+ #remove files before hand
15
+ if File.exists?("play.html")
16
+ FileUtils.rm("play.html")
17
+ end
18
+
19
+ if File.exists?("test.html")
20
+ FileUtils.rm("test.html")
21
+ end
22
+ Entityjs::Html.generate().should == 0
23
+ File.exists?("play.html").should == true
24
+ File.exists?("test.html").should == true
25
+ end
26
+
27
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'min' do
4
+
5
+ before(:all) do
6
+ setup_mygame
7
+ end
8
+
9
+ after(:all) do
10
+ teardown_mygame
11
+ end
12
+
13
+ it 'should compile' do
14
+
15
+ Entityjs::Command.run('min', []).should == 0
16
+
17
+ Entityjs::Config.instance.stub(:build_path).and_return('build')
18
+
19
+ dir = Entityjs::Config.instance.build_path
20
+
21
+ File.directory?(dir).should == true
22
+
23
+ Dir.chdir(dir) do
24
+ File.file?('game.min.js').should == true
25
+ contents = IO.read('game.min.js')
26
+ contents.should match /re\.canvas/
27
+ end
28
+ end
29
+
30
+ end
@@ -15,5 +15,11 @@ describe 'config' do
15
15
  @config = Entityjs::Config.instance
16
16
 
17
17
  end
18
+
19
+ it 'should rewrite vars' do
20
+ data = 'var sdf = RE_WIDTH'
21
+
22
+ Entityjs::Config.instance.preprocess(data).should_not match(/RE_WIDTH/)
23
+ end
18
24
 
19
25
  end
@@ -11,14 +11,14 @@ describe 'Page' do
11
11
  end
12
12
 
13
13
  it 'should render play' do
14
- html = Entityjs::Page.render_play
14
+ html = Entityjs::Page.render_play_page
15
15
 
16
16
  html.should be_instance_of String
17
17
  end
18
18
 
19
- it 'should render tests' do
19
+ it 'should render test' do
20
20
 
21
- test = Entityjs::Page.render_tests
21
+ test = Entityjs::Page.render_test_page
22
22
 
23
23
  test.should be_instance_of String
24
24
  end
@@ -37,7 +37,7 @@ describe 'Page' do
37
37
 
38
38
  it 'should be script' do
39
39
  js = 'var test = 10;'
40
- IO.stub(:read).and_return(js)
40
+ Entityjs::Compile.stub(:script_to_js).and_return(js)
41
41
 
42
42
  script = Entityjs::Page.render_script('blah.js')
43
43
 
@@ -1,22 +1,3 @@
1
- /*
2
- Quick way to convert sentences to arrays.
3
- */
4
- var __z = function(n, r){
5
- this._checkFinal();
6
-
7
- if(!this[n]){
8
- this[n] = [];
9
- }
10
-
11
- if(re.is(r, 'string')){
12
- this[n] = this[n].concat(r.split(' '));
13
- } else {
14
- this[n] = this[n].concat(r);
15
- }
16
-
17
- return this;
18
- };
19
-
20
1
  /*
21
2
  If component exists, the component will NOT be overwritten.
22
3
 
@@ -34,11 +15,21 @@
34
15
  re.c.init = function(name){
35
16
 
36
17
  this.name = name;
37
- this._re_signals = {};
38
- this._re_inherits = {};
18
+ this._re_listens = {};
19
+ this._re_defaults = {};
39
20
  this._re_defines = {};
40
21
  this._re_events = {};
41
- this._re_final = false;
22
+ this._re_final = 0;
23
+
24
+ //defines the special re.[comp]()
25
+ if(!re[this.name]){
26
+ var that = this;
27
+
28
+ re[this.name] = function(){
29
+ return that._re_method.apply(that, arguments);
30
+ };
31
+
32
+ }
42
33
  };
43
34
 
44
35
  /*
@@ -54,7 +45,25 @@
54
45
  */
55
46
 
56
47
  re.c.init.prototype = {
57
-
48
+ /*
49
+ Quick way to convert sentences to arrays.
50
+ */
51
+ z:function(n, r){
52
+ this._checkFinal();
53
+
54
+ if(!this[n]){
55
+ this[n] = [];
56
+ }
57
+
58
+ if(re.is(r, 'string')){
59
+ this[n] = this[n].concat(r.split(' '));
60
+ } else {
61
+ this[n] = this[n].concat(r);
62
+ }
63
+
64
+ return this;
65
+ },
66
+
58
67
  _checkFinal:function(){
59
68
 
60
69
  if(this._re_final){
@@ -68,11 +77,11 @@ re.c.init.prototype = {
68
77
  if(!re.is(value)){
69
78
 
70
79
  for(var type in obj){
71
- this[type] = obj[type];
80
+ re[this.name][type] = obj[type];
72
81
  }
73
82
 
74
83
  } else {
75
- this[obj] = value;
84
+ re[this.name][obj] = value;
76
85
  }
77
86
 
78
87
  return this;
@@ -94,8 +103,55 @@ re.c.init.prototype = {
94
103
  return this;
95
104
  },
96
105
 
106
+ /*
107
+ Defines a more formal constructor for when references are needed.
108
+
109
+ re.c('control')
110
+ .factory(function(ref, val){
111
+ this.ref = ref;
112
+ this.val = val;
113
+ });
114
+
115
+ //new control entity
116
+ re.control(val1, val2);
117
+ re.c('control').factory
118
+
119
+ */
120
+ factory:function(f){
121
+ this._checkFinal();
122
+
123
+ this._re_factory = f;
124
+
125
+ return this;
126
+ },
127
+
128
+ _re_method:function(){
129
+ var e = re.e(this.name);
130
+
131
+ if(this._re_factory)
132
+ this._re_factory.apply(e, arguments);
133
+
134
+ return e;
135
+ },
136
+
137
+ /*
138
+ Overwrites the factory method for a custom use.
139
+
140
+ re.c('monster')
141
+ .method(function(){
142
+ return re('monster');
143
+ });
144
+
145
+ re.monster(); //calls method
146
+
147
+ */
148
+ method:function(f){
149
+ this._re_method = f;
150
+ return this;
151
+ },
152
+
97
153
  requires:function(r){
98
- return __z.call(this, '_re_requires', r);
154
+ return this.z('_re_requires', r);
99
155
  },
100
156
 
101
157
  /*
@@ -105,7 +161,7 @@ re.c.init.prototype = {
105
161
  This prevents incompatible components from colliding.
106
162
  */
107
163
  asserts:function(r){
108
- return __z.call(this, '_re_asserts', r);
164
+ return this.z('_re_asserts', r);
109
165
  },
110
166
 
111
167
  /*
@@ -123,7 +179,7 @@ re.c.init.prototype = {
123
179
 
124
180
  */
125
181
  interfaces:function(r){
126
- return __z.call(this, '_re_implements', r);
182
+ return this.z('_re_interfaces', r);
127
183
  },
128
184
 
129
185
  /*
@@ -202,12 +258,12 @@ re.c.init.prototype = {
202
258
  if(arguments.length == 1){
203
259
 
204
260
  for(var k in d){
205
- this._re_inherits[k] = d[k];
261
+ this._re_defaults[k] = d[k];
206
262
  }
207
263
 
208
264
  } else {
209
265
 
210
- this._re_inherits[d] = value;
266
+ this._re_defaults[d] = value;
211
267
 
212
268
  }
213
269
 
@@ -294,7 +350,7 @@ re.c.init.prototype = {
294
350
  lock:function(){
295
351
  this._checkFinal();
296
352
 
297
- this._re_final = true;
353
+ this._re_final = 1;
298
354
 
299
355
  return this;
300
356
  },