entityjs 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -57,6 +57,14 @@ module Entityjs
57
57
  @yml['width']
58
58
  end
59
59
 
60
+ def canvas_border
61
+ if @yml.nil?
62
+ return true
63
+ end
64
+
65
+ return @yml['canvas-border']
66
+ end
67
+
60
68
  def height
61
69
  if @yml.nil?
62
70
  return 400
data/lib/entityjs/dirc.rb CHANGED
@@ -29,11 +29,12 @@ module Entityjs
29
29
  end
30
30
 
31
31
  def self.find_tests_url(ignore=nil)
32
+ valids = Compile.valid_scripts.join(",")
32
33
  ignore ||= []
33
- tests = Dir["#{Dirc.game_root}/#{Config.tests_folder}/**/*.js"]
34
+ tests = Dir["#{Dirc.game_root}/#{Config.tests_folder}/**/*.{#{valids}}"].sort
34
35
 
35
36
  tests = tests.collect do |i|
36
- i[i.rindex('tests/')..-1]
37
+ i[i.rindex(Config.tests_folder+'/')..-1]
37
38
  end
38
39
 
39
40
  if ignore.any?
@@ -43,14 +44,45 @@ module Entityjs
43
44
  return tests
44
45
  end
45
46
 
47
+ #returns all game scripts with short paths
48
+ def self.find_scripts_short(ignore=nil, order=nil)
49
+ scripts = self.find_scripts_url(ignore, order)
50
+
51
+ scripts.collect do |i|
52
+
53
+ i.sub(Config.scripts_folder+'/', '')
54
+
55
+ end
56
+ end
57
+
46
58
  def self.find_scripts_url(ignore=nil, order=nil)
47
- ignore ||= []
48
- order ||= []
49
59
 
50
60
  scripts = self.find_scripts(ignore, order)
51
61
 
52
62
  #change filenames
53
- scripts = scripts.collect{|k| k[k.rindex('scripts/')..-1] }
63
+ scripts = scripts.collect{|k| k[k.rindex(Config.scripts_folder+'/')..-1] }
64
+
65
+ return scripts
66
+ end
67
+
68
+ def self.find_entity_src_url(ignore=nil)
69
+ srcs = self.find_entity_src(ignore)
70
+
71
+ #remove src directory and replace with entityjs
72
+ srcs = srcs.collect{|k| k[k.rindex('src/')..-1].gsub('src', 'entityjs') }
73
+
74
+ return srcs
75
+ end
76
+
77
+ def self.find_scripts(ignore=nil, order=nil)
78
+ ignore ||= []
79
+ order ||= []
80
+ valids = Compile.valid_scripts.join(",")
81
+
82
+ scripts = Dir["#{Dirc.game_root}/#{Config.scripts_folder}/**/*.{#{valids}}"].sort
83
+
84
+ #sort again by extension
85
+ scripts.sort! {|x,y| File.extname(x) <=> File.extname(y) }
54
86
 
55
87
  #ignore files
56
88
  if ignore.any?
@@ -74,29 +106,46 @@ module Entityjs
74
106
  return scripts
75
107
  end
76
108
 
77
- def self.find_entity_src_url(ignore=nil)
78
- ignore ||= []
79
- srcs = self.find_entity_src(ignore)
109
+ def self.find_eunit_src_url(ignore=nil)
110
+ srcs = self.find_eunit_src(ignore)
80
111
 
81
112
  #remove src directory and replace with entityjs
82
- srcs = srcs.collect{|k| k[k.rindex('src/')..-1].gsub('src', 'entityjs') }
83
-
84
- if ignore.any?
85
- srcs.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil? }
86
- end
113
+ srcs = srcs.collect{|k| k[k.rindex('qunit/')..-1] }
87
114
 
88
115
  return srcs
116
+
89
117
  end
90
118
 
91
- def self.find_scripts(ignore=nil, order=nil)
119
+ def self.find_eunit_src(ignore=nil)
120
+ ignore ||= []
121
+ ents = Dir[Entityjs::eunit_folder+"/**/*.js"].sort
122
+
123
+ #make sure qunit is at the top
124
+
125
+ i = ents.index{|i| i.match(/qunit\.js$/) }
126
+
127
+ if i.nil?
128
+ puts 'Error cannot find qunit.js!'
129
+ return ents
130
+ end
92
131
 
93
- return Dir["#{Dirc.game_root}/#{Config.scripts_folder}/**/*.js"].sort
132
+ #remove
133
+ k = ents.delete_at(i)
94
134
 
135
+ #push at front
136
+ ents.unshift(k)
137
+
138
+ if ignore.any?
139
+ ents.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil? }
140
+ end
141
+
142
+ return ents
95
143
  end
96
144
 
97
145
  def self.find_entity_src(ignore=nil)
146
+ ignore ||= []
98
147
 
99
- ents = Dir[Entityjs::root+"/src/**/*.js"]
148
+ ents = Dir[Entityjs::source_folder+"/**/*.js"]
100
149
 
101
150
  #sort by name
102
151
  ents.sort!
@@ -114,6 +163,10 @@ module Entityjs
114
163
 
115
164
  ents.unshift(k)
116
165
 
166
+ if ignore.any?
167
+ ents.delete_if {|i| !i.match(/#{ignore.join('|')}/).nil? }
168
+ end
169
+
117
170
  return ents
118
171
  end
119
172
 
@@ -133,7 +186,7 @@ module Entityjs
133
186
 
134
187
  def self.create_dir(name, move=false)
135
188
 
136
- if !Dir.exists? name
189
+ if !File.directory? name
137
190
  Dir.mkdir(name)
138
191
  end
139
192
 
@@ -0,0 +1,106 @@
1
+ #The Page class renders html pages for the server
2
+ module Entityjs
3
+
4
+ class Page
5
+
6
+ def self.processor_ext
7
+ return '.js'
8
+ end
9
+
10
+ def self.render_play
11
+ self.set_vars("play.html")
12
+ end
13
+
14
+ def self.render_tests
15
+ self.set_vars('tests.html', true)
16
+ end
17
+
18
+ def self.render_entityjs_src(path)
19
+ path = Entityjs::root+'/src/'+path
20
+
21
+ return IO.read(path)
22
+ end
23
+
24
+ def self.render_test(path)
25
+ file = path.sub(/#{self.processor_ext}$/i, '');
26
+
27
+ return Compile.test_to_js(file)
28
+ end
29
+
30
+ def self.render_script(path)
31
+ file = path.sub(/#{self.processor_ext}$/i, '');
32
+ return Compile.script_to_js(file)
33
+ end
34
+
35
+ def self.render_eunit(path)
36
+ IO.read(Entityjs::root+"/public/qunit/#{path}")
37
+ end
38
+
39
+ protected
40
+ #defines varaibles on the template htmls for view on webpage
41
+ def self.set_vars(path, tests=false)
42
+ contents = IO.read("#{Entityjs::root}/public/#{path}")
43
+
44
+ #reload config for changes
45
+ Config.instance.reload
46
+
47
+ #set width, height and canvas id
48
+ contents = contents.sub("$WIDTH", Config.instance.width.to_s)
49
+ contents = contents.sub("$HEIGHT", Config.instance.height.to_s)
50
+ contents = contents.sub("$CANVAS_ID", Config.instance.canvas_id)
51
+
52
+ if !Config.instance.canvas_border
53
+ contents = contents.sub('border:1px #333 solid;', '')
54
+ end
55
+
56
+ #set javascript srcs
57
+ contents.sub("$JS", self.compile_js_html(tests))
58
+ end
59
+
60
+ #compiles html js tags for render on webpage
61
+ def self.compile_js_html(tests=false)
62
+ js = %Q(
63
+ <script type=\"text/javascript\">
64
+ window.addEventListener\(\"load\", function(){
65
+ #{Build.js_config}
66
+ re.version = \"#{VERSION}\";
67
+ }\);
68
+ </script>
69
+ )
70
+ ent = Dirc.find_entity_src_url(Config.instance.entity_ignore)
71
+ srcs = Dirc.find_scripts_url(Config.instance.scripts_ignore, Config.instance.scripts_order)
72
+
73
+ if tests
74
+ tests_src = Dirc.find_tests_url(Config.instance.tests_ignore)
75
+ ent += Dirc.find_eunit_src_url
76
+ else
77
+ tests_src = []
78
+ end
79
+
80
+ merg = ent | srcs | tests_src
81
+
82
+ last = ''
83
+
84
+ merg.each do |s|
85
+
86
+ #output a divider for each js root
87
+ first_folder = s.split('/').shift
88
+ if last != first_folder
89
+ js += "\n\n\t<!-- #{first_folder} -->\n"
90
+ last = first_folder
91
+ end
92
+
93
+ #add processor extension to non-js files so the server processes it into js
94
+ if s.match(/\.js$/).nil?
95
+ s += self.processor_ext
96
+ end
97
+
98
+ js += "\t<script src=\"#{s}\" type=\"text/javascript\"></script>\n"
99
+ end
100
+
101
+ return js
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,12 @@
1
+ module Entityjs
2
+
3
+ class ParseCoffee
4
+
5
+ def self.parse(data, ops={})
6
+ ops[:no_wrap] ||= true
7
+ return CoffeeScript.compile(data, ops)
8
+ end
9
+
10
+ end
11
+
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Entityjs
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/entityjs.rb CHANGED
@@ -14,6 +14,14 @@ rescue LoadError
14
14
  exit
15
15
  end
16
16
 
17
+ begin
18
+ require "coffee-script"
19
+ rescue LoadError
20
+ puts "Could not load 'coffee-script'"
21
+ puts "run 'gem install coffee-script'"
22
+ exit
23
+ end
24
+
17
25
  begin
18
26
  require "uglifier"
19
27
  rescue LoadError
@@ -30,16 +38,22 @@ rescue LoadError
30
38
  exit
31
39
  end
32
40
 
33
- require "entityjs/version"
34
-
35
41
  module Entityjs
36
42
 
37
43
  def self.root
38
44
  @root = File.expand_path('../..',__FILE__)
39
45
  end
40
46
 
47
+ def self.source_folder
48
+ Entityjs::root+'/src'
49
+ end
50
+
51
+ def self.eunit_folder
52
+ Entityjs::root+'/public/qunit'
53
+ end
54
+
41
55
  def self.default_template
42
- 'blank'
56
+ 'circle'
43
57
  end
44
58
 
45
59
  def self.template_path(name=nil)
@@ -47,7 +61,7 @@ module Entityjs
47
61
  name = self.default_template
48
62
  end
49
63
  path = "#{Entityjs::root}/templates/#{name}"
50
- if Dir.exists? path
64
+ if File.directory? path
51
65
  return Dir.glob(path+'/*')
52
66
  else
53
67
  return nil
@@ -1,9 +1,9 @@
1
1
  /**
2
- * QUnit v1.3.0pre - A JavaScript Unit Testing Framework
2
+ * QUnit v1.5.0pre - A JavaScript Unit Testing Framework
3
3
  *
4
4
  * http://docs.jquery.com/QUnit
5
5
  *
6
- * Copyright (c) 2011 John Resig, Jörn Zaefferer
6
+ * Copyright (c) 2012 John Resig, Jörn Zaefferer
7
7
  * Dual licensed under the MIT (MIT-LICENSE.txt)
8
8
  * or GPL (GPL-LICENSE.txt) licenses.
9
9
  */
@@ -54,6 +54,10 @@
54
54
  color: #fff;
55
55
  }
56
56
 
57
+ #qunit-header label {
58
+ display: inline-block;
59
+ }
60
+
57
61
  #qunit-banner {
58
62
  height: 5px;
59
63
  }
@@ -223,4 +227,6 @@
223
227
  position: absolute;
224
228
  top: -10000px;
225
229
  left: -10000px;
226
- }
230
+ width: 1000px;
231
+ height: 1000px;
232
+ }
@@ -1,44 +1,108 @@
1
- EUnit = {
2
- stack:[],
3
-
4
- runStack:function(){
5
- for(var i in EUnit.stack){
6
- var k = EUnit.stack[i];
7
-
8
- ok(k.called, k.message);
9
- }
10
- },
11
-
12
- push:function(obj){
13
- this.stack.push(obj);
14
-
15
- return QUnit.config.queue.unshift(EUnit.runStack);
1
+ ETest = function(){
2
+ };
3
+
4
+ ETest.prototype.push = function(){
5
+ var that = this;
6
+ if(QUnit.config.blocking){
7
+ that.run();
8
+ } else {
9
+ QUnit.config.queue.unshift(function(){
10
+ that.run();
11
+ });
16
12
  }
17
13
  };
14
+
15
+ ETest.prototype.run = function(){
16
+ ok(this.check(), this.message);
17
+ };
18
+
19
+ /*
20
+ Disable re.ready for testing
21
+ */
22
+ re.ready = function(){};
23
+
24
+ window.addEventListener('load', function(){
25
+ re.sys.init(re.canvas).start();
26
+ }, true);
27
+
18
28
  /*
19
29
  Expects a trigger call from the given obj.
20
30
 
21
31
  var e = re.e('flicker');
22
32
 
23
- expectTrigger(e, 'flicker:end', function(){
33
+ expectTrigger(e, 'flicker:finish', function(){
24
34
  //if triggered this will be called
25
35
  });
26
36
 
37
+ var e = re.e('counter');
38
+
39
+ //expect given arguments
40
+ expectTrigger(e, 'maxed', [10]);
41
+
27
42
  */
28
43
  function expectTrigger(obj, trigger, func){
29
- var trig = {
30
- called:0,
31
- message:"Expected "+trigger+" to be triggered"
44
+ var trig = new ETest();
45
+ trig.called = 0;
46
+ trig.message = "Expected "+trigger+" to be triggered";
47
+
48
+ trig.check = function(){
49
+ return this.called;
32
50
  };
33
51
 
34
52
  trig.meth = function(){
35
53
  trig.called++;
36
- if(func) func.apply(obj, arguments);
54
+
55
+ if(typeof func == 'object'){
56
+
57
+ var args = Array.prototype.slice.call(arguments, 0);
58
+
59
+ ok(!(args>func || args<func), "trigger "+trigger+" should have same arguments");
60
+
61
+ } else if(typeof func == 'function'){
62
+ func.apply(obj, arguments);
63
+ }
37
64
  };
38
65
 
39
66
  obj.on(trigger, trig.meth);
40
67
 
41
- EUnit.push(trig);
68
+ trig.push();
69
+ };
70
+
71
+ function expectValueUp(obj, prop){
72
+ var trig = new ETest();
73
+ trig.message = "Expected "+prop+" to value up";
74
+ trig.old = obj[prop];
75
+
76
+ trig.check = function(){
77
+ return this.old < obj[prop];
78
+ };
79
+
80
+ trig.push();
81
+ };
82
+
83
+ function expectValueDown(obj, prop){
84
+ var trig = new ETest();
85
+ trig.message = "Expected "+prop+" to value down";
86
+ trig.old = obj[prop];
87
+
88
+ trig.check = function(){
89
+ return this.old > obj[prop];
90
+ };
91
+
92
+ trig.push();
93
+ };
94
+
95
+ /*
96
+
97
+ re.e('circle')
98
+ .attr('color', '#ff0000');
99
+
100
+ pixelEqual(10, 10, 255, 0, 0, 0);
101
+
102
+ */
103
+ function pixelEqual(x, y, r, g, b, a, message){
104
+ var actual = Array.prototype.slice.apply(re.sys.context.getImageData(x, y, 1, 1).data), expected = [r, g, b, a];
105
+ QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
42
106
  }
43
107
 
44
108
  /*
@@ -58,22 +122,22 @@ function expectFlicker(ent, flick){
58
122
  }
59
123
 
60
124
  /*
61
- Expects an entity or component to have a current listener attached.
125
+ Expects an entity or component to have a current event attached.
62
126
 
63
127
  var e = re.e();
64
128
 
65
- expectListener(e, 'update'); //false
129
+ expectEvent(e, 'update'); //false
66
130
 
67
131
  e.on('update', function(){
68
132
 
69
133
  });
70
134
 
71
- expectListener(e, 'update') //true
135
+ expectEvent(e, 'update') //true
72
136
 
73
137
  */
74
- function expectListener(ent, trigger, func){
138
+ function expectEvent(ent, trigger, func){
75
139
  if(arguments.length == 2){
76
- ok(ent.has('^'+trigger), "Expected entity to have listener "+trigger);
140
+ ok(ent.has('^'+trigger), "Expected entity to have event "+trigger);
77
141
  } else {
78
142
  var fin = false;
79
143
  for(var i in ent._re_signals[trigger]){
@@ -81,7 +145,7 @@ function expectListener(ent, trigger, func){
81
145
  if(fin) break;
82
146
  }
83
147
 
84
- ok(fin, "Expected entity to have listener "+trigger+" with function");
148
+ ok(fin, "Expected entity to have event "+trigger+" with function");
85
149
 
86
150
  }
87
151
  }
@@ -127,7 +191,7 @@ var f = factory;
127
191
  Generates a factory entity for easy use in the module()
128
192
 
129
193
  //light weight
130
- //a new coin in e will be created for every test()
194
+ //a new coin in coin will be created for every test()
131
195
  module('coin', lazy('coin'));
132
196
 
133
197
  //do something after coin creation
@@ -146,17 +210,23 @@ teardown:function(e){
146
210
  }));
147
211
 
148
212
  test('coin should have valid of 10', function(){
149
- equal(e.value, 10);
213
+ equal(coin.value, 10);
150
214
  })
151
215
 
152
216
  etc..
153
217
 
154
218
  */
155
- var e;
156
219
  function lazy(comps, obj){
220
+ var name;
221
+ if(typeof comps == 'string') comps = comps.split(' ');
222
+ name = comps[0];
223
+ var e;
224
+
157
225
  return {
158
226
  setup:function(){
159
- e = f(comps);
227
+
228
+ window[name] = e = f(comps.join(' '));
229
+
160
230
  if(typeof obj == 'function') obj(e);
161
231
  if(obj && obj.setup) obj.setup(e);
162
232
  },
@@ -167,6 +237,18 @@ function lazy(comps, obj){
167
237
  }
168
238
  }
169
239
 
240
+ function lazyScene(scene, args){
241
+ return {
242
+ setup:function(){
243
+ var s = window[scene] = re.scene(scene);
244
+ s.enter.apply(s, args);
245
+ },
246
+ teardown:function(){
247
+ re.scene().exit();
248
+ }
249
+ };
250
+ };
251
+
170
252
  /*
171
253
  Some super lazy evaluations
172
254
  */