gamebox 0.3.4 → 0.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/README.rdoc +38 -0
  2. data/Rakefile +1 -10
  3. data/TODO.txt +6 -6
  4. data/app_generators/gamebox_generator.rb +95 -0
  5. data/{lib/gamebox/templates/template_app → app_generators/templates}/.gitignore +0 -0
  6. data/app_generators/templates/Gemfile +7 -0
  7. data/app_generators/templates/NEXT_STEPS.txt +1 -0
  8. data/{lib/gamebox/templates/template_app/README → app_generators/templates/README.rdoc} +0 -0
  9. data/{lib/gamebox/templates/template_app → app_generators/templates}/Rakefile +0 -0
  10. data/{lib/gamebox/templates/template_app → app_generators/templates}/config/boot.rb +0 -0
  11. data/app_generators/templates/config/environment.rb +30 -0
  12. data/{lib/gamebox/templates/template_app → app_generators/templates}/config/game.yml +0 -0
  13. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/fonts/FONTS_GO_HERE +0 -0
  14. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/graphics/GRAPHICS_GO_HERE +0 -0
  15. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/music/MUSIC_GOES_HERE +0 -0
  16. data/{lib/gamebox/templates/template_app → app_generators/templates}/data/sounds/SOUND_FX_GO_HERE +0 -0
  17. data/{lib/gamebox/templates → app_generators/templates/script}/actor.erb +0 -0
  18. data/{lib/gamebox/templates → app_generators/templates/script}/actor_spec.erb +0 -0
  19. data/{lib/gamebox/templates → app_generators/templates/script}/actor_view.erb +0 -0
  20. data/{lib/gamebox/templates → app_generators/templates/script}/actor_view_spec.erb +0 -0
  21. data/app_generators/templates/script/generate +12 -0
  22. data/{lib/gamebox/templates/template_app → app_generators/templates}/spec/helper.rb +0 -0
  23. data/app_generators/templates/src/actors/player.rb +8 -0
  24. data/{lib/gamebox/templates/template_app → app_generators/templates}/src/app.rb +0 -0
  25. data/app_generators/templates/src/demo_stage.rb +7 -0
  26. data/bin/gamebox +8 -70
  27. data/component_generators/actor_generator.rb +17 -0
  28. data/docs/CODE_REVIEW +1 -1
  29. data/docs/REFACTOR_NOTES.txt +25 -0
  30. data/docs/getting_started.rdoc +1 -1
  31. data/gamebox.gemspec +7 -4
  32. data/lib/gamebox.rb +6 -3
  33. data/lib/gamebox/actors/collidable_debugger.rb +13 -15
  34. data/lib/gamebox/actors/curtain.rb +44 -43
  35. data/lib/gamebox/actors/emitter.rb +3 -42
  36. data/lib/gamebox/actors/fps.rb +13 -6
  37. data/lib/gamebox/actors/label.rb +42 -34
  38. data/lib/gamebox/actors/logo.rb +2 -4
  39. data/lib/gamebox/actors/score.rb +37 -27
  40. data/lib/gamebox/actors/svg_actor.rb +45 -32
  41. data/lib/gamebox/behaviors/animated.rb +39 -59
  42. data/lib/gamebox/behaviors/audible.rb +14 -14
  43. data/lib/gamebox/behaviors/collidable.rb +65 -36
  44. data/lib/gamebox/behaviors/collidable/aabb_collidable.rb +2 -3
  45. data/lib/gamebox/behaviors/collidable/collidable_shape.rb +6 -4
  46. data/lib/gamebox/behaviors/collidable/polygon_collidable.rb +1 -1
  47. data/lib/gamebox/behaviors/emitting.rb +48 -0
  48. data/lib/gamebox/behaviors/graphical.rb +22 -56
  49. data/lib/gamebox/behaviors/layered.rb +8 -21
  50. data/lib/gamebox/behaviors/physical.rb +202 -213
  51. data/lib/gamebox/behaviors/positioned.rb +16 -0
  52. data/lib/gamebox/behaviors/projectile.rb +15 -0
  53. data/lib/gamebox/behaviors/visible.rb +16 -0
  54. data/lib/gamebox/core/aabb_helpers.rb +61 -0
  55. data/lib/gamebox/core/aabb_node.rb +118 -0
  56. data/lib/gamebox/core/aabb_tree.rb +137 -0
  57. data/lib/gamebox/core/actor.rb +102 -0
  58. data/lib/gamebox/core/actor_factory.rb +56 -0
  59. data/lib/gamebox/core/actor_view.rb +63 -0
  60. data/lib/gamebox/core/actor_view_factory.rb +40 -0
  61. data/lib/gamebox/{arbiter.rb → core/arbiter.rb} +31 -34
  62. data/lib/gamebox/{backstage.rb → core/backstage.rb} +0 -0
  63. data/lib/gamebox/core/behavior.rb +64 -0
  64. data/lib/gamebox/core/behavior_factory.rb +56 -0
  65. data/lib/gamebox/{class_finder.rb → core/class_finder.rb} +0 -0
  66. data/lib/gamebox/{config_manager.rb → core/config_manager.rb} +1 -1
  67. data/lib/gamebox/core/configuration.rb +39 -0
  68. data/lib/gamebox/core/core.rb +30 -0
  69. data/lib/gamebox/core/deprecated.rb +15 -0
  70. data/lib/gamebox/{director.rb → core/director.rb} +6 -11
  71. data/lib/gamebox/core/font_style.rb +26 -0
  72. data/lib/gamebox/core/font_style_factory.rb +11 -0
  73. data/lib/gamebox/core/game.rb +19 -0
  74. data/lib/gamebox/{hooked_gosu_window.rb → core/hooked_gosu_window.rb} +12 -6
  75. data/lib/gamebox/{input_manager.rb → core/input_manager.rb} +106 -99
  76. data/lib/gamebox/core/physics.rb +22 -0
  77. data/lib/gamebox/{physical_stage.rb → core/physics_manager.rb} +36 -30
  78. data/lib/gamebox/{resource_manager.rb → core/resource_manager.rb} +19 -18
  79. data/lib/gamebox/{sound_manager.rb → core/sound_manager.rb} +9 -7
  80. data/lib/gamebox/{stage.rb → core/stage.rb} +42 -80
  81. data/lib/gamebox/{stage_manager.rb → core/stage_manager.rb} +46 -53
  82. data/lib/gamebox/{stagehand.rb → core/stagehand.rb} +0 -0
  83. data/lib/gamebox/{svg_document.rb → core/svg_document.rb} +0 -0
  84. data/lib/gamebox/core/timer_manager.rb +50 -0
  85. data/lib/gamebox/{viewport.rb → core/viewport.rb} +2 -3
  86. data/lib/gamebox/{wrapped_screen.rb → core/wrapped_screen.rb} +12 -19
  87. data/lib/gamebox/gamebox_application.rb +7 -15
  88. data/lib/gamebox/lib/evented_attributes.rb +51 -0
  89. data/lib/gamebox/{ftor.rb → lib/ftor.rb} +0 -0
  90. data/lib/gamebox/lib/min_max_helpers.rb +10 -0
  91. data/lib/gamebox/lib/rect.rb +112 -54
  92. data/lib/gamebox/lib/yoda.rb +46 -0
  93. data/lib/gamebox/spec/helper.rb +317 -12
  94. data/lib/gamebox/stagehands/spatial_tree_stagehand.rb +61 -0
  95. data/lib/gamebox/version.rb +8 -3
  96. data/lib/gamebox/views/graphical_actor_view.rb +22 -29
  97. data/script/perf_aabb.rb +56 -0
  98. data/script/perf_array_access.rb +16 -0
  99. data/script/perf_collisions.rb +37 -18
  100. data/script/perf_struct_vs_array.rb +7 -7
  101. data/spec/acceptance/animation_spec.rb +65 -0
  102. data/spec/acceptance/basic_actor_lifecycle_spec.rb +92 -0
  103. data/spec/acceptance/built_in_collision_handling_spec.rb +55 -0
  104. data/spec/acceptance/chipmunk_collision_handling_spec.rb +83 -0
  105. data/spec/acceptance/fps_actor_spec.rb +40 -0
  106. data/spec/acceptance/pausing_spec.rb +61 -0
  107. data/spec/acceptance/timer_usage_spec.rb +53 -0
  108. data/spec/actors/emitter_spec.rb +5 -0
  109. data/spec/{label_spec.rb → actors/label_spec.rb} +1 -1
  110. data/spec/behaviors/animated_spec.rb +85 -0
  111. data/spec/behaviors/collidable_spec.rb +134 -0
  112. data/spec/{physical_spec.rb → behaviors/physical_spec.rb} +2 -1
  113. data/spec/behaviors/positioned_spec.rb +6 -0
  114. data/spec/behaviors/projectile_spec.rb +6 -0
  115. data/spec/core/aabb_tree_spec.rb +109 -0
  116. data/spec/core/actor_factory_spec.rb +44 -0
  117. data/spec/core/actor_spec.rb +78 -0
  118. data/spec/core/actor_view_spec.rb +53 -0
  119. data/spec/{arbiter_spec.rb → core/arbiter_spec.rb} +29 -30
  120. data/spec/core/backstage_spec.rb +37 -0
  121. data/spec/core/behavior_factory_spec.rb +50 -0
  122. data/spec/core/behavior_spec.rb +8 -0
  123. data/spec/core/configuration_spec.rb +8 -0
  124. data/spec/core/core_spec.rb +13 -0
  125. data/spec/core/font_style_factory_spec.rb +17 -0
  126. data/spec/core/font_style_spec.rb +41 -0
  127. data/spec/core/hooked_gosu_window_spec.rb +75 -0
  128. data/spec/core/input_manager_spec.rb +285 -0
  129. data/spec/core/physics_manager_spec.rb +11 -0
  130. data/spec/core/resource_manager_spec.rb +12 -0
  131. data/spec/core/stage_manager_spec.rb +140 -0
  132. data/spec/core/stage_spec.rb +73 -0
  133. data/spec/core/timer_manager_spec.rb +89 -0
  134. data/spec/{viewport_spec.rb → core/viewport_spec.rb} +6 -3
  135. data/spec/core/wrapped_screen_spec.rb +26 -0
  136. data/spec/fixtures/game.yml +7 -0
  137. data/spec/fixtures/snelpling/idle/1.png +0 -0
  138. data/spec/fixtures/snelpling/jump/1.png +0 -0
  139. data/spec/fixtures/snelpling/jump/2.png +0 -0
  140. data/spec/fixtures/snelpling/jump/3.png +0 -0
  141. data/spec/helper.rb +8 -0
  142. data/spec/{class_finder_spec.rb → lib/class_finder_spec.rb} +2 -1
  143. data/spec/stagehands/spatial_tree_stagehand_spec.rb +19 -0
  144. data/spec/views/graphical_actor_view_spec.rb +116 -0
  145. metadata +343 -144
  146. data/README.txt +0 -34
  147. data/lib/gamebox/actor.rb +0 -179
  148. data/lib/gamebox/actor_factory.rb +0 -57
  149. data/lib/gamebox/actor_view.rb +0 -44
  150. data/lib/gamebox/actors/spatial_debugger.rb +0 -62
  151. data/lib/gamebox/behavior.rb +0 -70
  152. data/lib/gamebox/behaviors/timed.rb +0 -33
  153. data/lib/gamebox/behaviors/updatable.rb +0 -12
  154. data/lib/gamebox/console_app.rb +0 -41
  155. data/lib/gamebox/gamebox_generator.rb +0 -32
  156. data/lib/gamebox/generators/actor_generator.rb +0 -43
  157. data/lib/gamebox/generators/view_generator.rb +0 -42
  158. data/lib/gamebox/physical_director.rb +0 -17
  159. data/lib/gamebox/physics.rb +0 -32
  160. data/lib/gamebox/spatial_bucket.rb +0 -9
  161. data/lib/gamebox/spatial_hash.rb +0 -194
  162. data/lib/gamebox/spatial_stagehand.rb +0 -80
  163. data/lib/gamebox/templates/template_app/Gemfile +0 -6
  164. data/lib/gamebox/templates/template_app/config/environment.rb +0 -23
  165. data/lib/gamebox/templates/template_app/config/stage_config.yml +0 -2
  166. data/lib/gamebox/templates/template_app/script/generate +0 -7
  167. data/lib/gamebox/templates/template_app/src/demo_stage.rb +0 -11
  168. data/lib/gamebox/templates/template_app/src/game.rb +0 -19
  169. data/lib/gamebox/templates/template_app/src/my_actor.rb +0 -14
  170. data/script/perf_spatial_hash.rb +0 -64
  171. data/spec/actor_factory_spec.rb +0 -61
  172. data/spec/actor_spec.rb +0 -71
  173. data/spec/actor_view_spec.rb +0 -61
  174. data/spec/animated_spec.rb +0 -83
  175. data/spec/backstage_spec.rb +0 -45
  176. data/spec/behavior_spec.rb +0 -28
  177. data/spec/collidable_spec.rb +0 -135
  178. data/spec/emitter_spec.rb +0 -20
  179. data/spec/input_manager_spec.rb +0 -134
  180. data/spec/resource_manager_spec.rb +0 -13
  181. data/spec/spatial_hash_spec.rb +0 -119
  182. data/spec/spatial_stagehand_spec.rb +0 -93
  183. data/spec/stage_manager_spec.rb +0 -25
  184. data/spec/stage_spec.rb +0 -65
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+
4
+ describe PhysicsManager do
5
+ it 'needs tests'
6
+
7
+ describe "#add_collision_func" do
8
+ it 'pulls actors out of the collision shapes and yields them to the block'
9
+ it 'accepts two arrays of types and builds chipmunk handlers accordingly (see arbiter)'
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+
3
+ describe 'A new resource manager' do
4
+ let(:actor) { stub 'actor', actor_type: 'string' }
5
+ subject { ResourceManager.new :wrapped_screen => stub(:screen => :fake_gosu) }
6
+
7
+ it 'should load an actor image' do
8
+ subject.expects(:load_image).with("string.png").returns(:surf)
9
+ subject.load_actor_image(actor).should == :surf
10
+ end
11
+
12
+ end
@@ -0,0 +1,140 @@
1
+ require 'helper'
2
+
3
+ describe StageManager do
4
+ inject_mocks :input_manager, :config_manager, :backstage,
5
+ :this_object_context
6
+
7
+ class FooStage; end
8
+ class BarStage; end
9
+
10
+ let(:foo_stage) { stub('foo stage', when: nil, curtain_raising: nil, curtain_dropping: nil) }
11
+ let(:bar_stage) { stub('bar stage', when: nil, curtain_raising: nil, curtain_dropping: nil) }
12
+ let(:foo_stage_config) { {foo: {thing:1} } }
13
+ let(:bar_stage_config) { {bar: {thing:2} } }
14
+ let(:stages) { [foo_stage_config, bar_stage_config] }
15
+ let(:subcontext) { stub 'subcontext' }
16
+ before do
17
+ Gamebox.configuration.stages = stages
18
+ @input_manager.stubs(:clear_hooks)
19
+
20
+ # TODO sub context helper
21
+ subcontext.stubs(:[]).with('foo_stage').returns(foo_stage)
22
+ subcontext.stubs(:[]).with('bar_stage').returns(bar_stage)
23
+ subcontext.stubs(:[]=)
24
+ foo_stage.stubs(:configure).with(@backstage, {thing:1})
25
+ bar_stage.stubs(:configure).with(@backstage, {thing:2})
26
+ @this_object_context.stubs(:in_subcontext).yields(subcontext)
27
+ end
28
+
29
+ describe '#setup' do
30
+ it 'constructs' do
31
+ subject.should be
32
+ end
33
+
34
+ it 'sets up the stage config' do
35
+ subject.stage_names.should == [:foo, :bar]
36
+ subject.stage_opts.should == [{thing:1}, {thing:2}]
37
+ end
38
+ end
39
+
40
+ describe "#default_stage" do
41
+
42
+ it 'returns the first stage in the stage_config' do
43
+ subject.default_stage.should == :foo
44
+ end
45
+ end
46
+
47
+ describe "#switch_to_stage" do
48
+
49
+ it 'activates the new stage' do
50
+ subject.switch_to_stage :foo, :args
51
+ subject.current_stage.should == foo_stage
52
+ end
53
+
54
+ it 'raises the curtain on the new stage' do
55
+ foo_stage.expects(:curtain_raising).with(:args)
56
+ subject.switch_to_stage :foo, :args
57
+ end
58
+
59
+ it 'shuts down the current stage' do
60
+ foo_stage.expects(:curtain_dropping).with(:other_args)
61
+ @input_manager.expects(:clear_hooks).with(foo_stage)
62
+ subject.switch_to_stage :foo, :args
63
+ subject.switch_to_stage :bar, :other_args
64
+ end
65
+ end
66
+
67
+ describe '#prev_stage' do
68
+ it 'goes to prev stage' do
69
+ subject.switch_to_stage :bar
70
+ foo_stage.expects(:curtain_raising).with(:args)
71
+
72
+ subject.prev_stage :args
73
+ subject.current_stage.should == foo_stage
74
+ end
75
+
76
+ it 'exits on prev_stage of first stage' do
77
+ subject.switch_to_stage :foo
78
+ lambda { subject.prev_stage :args }.should raise_exception(SystemExit)
79
+ end
80
+ end
81
+
82
+ describe '#next_stage' do
83
+ it 'goes to next stage' do
84
+ subject.switch_to_stage :foo
85
+ bar_stage.expects(:curtain_raising).with(:args)
86
+
87
+ subject.next_stage :args
88
+ subject.current_stage.should == bar_stage
89
+ end
90
+
91
+ it 'exits on next_stage of last stage' do
92
+ subject.switch_to_stage :bar
93
+ lambda { subject.next_stage :args }.should raise_exception(SystemExit)
94
+ end
95
+ end
96
+
97
+ describe '#restart_stage' do
98
+ it 'restarts the current stage' do
99
+ subject.switch_to_stage :foo, :args
100
+
101
+ foo_stage.expects(:curtain_raising).with(:other_args)
102
+ subject.restart_stage :other_args
103
+ end
104
+ end
105
+
106
+ describe "#update" do
107
+ it 'can be called on nil stage' do
108
+ subject.update :target
109
+ end
110
+
111
+ it 'updates the current stage' do
112
+ subject.switch_to_stage :foo, :args
113
+ foo_stage.expects(:update).with(44)
114
+
115
+ subject.update 44
116
+ end
117
+ end
118
+
119
+ describe "#draw" do
120
+ it 'can be called on nil stage' do
121
+ subject.draw :target
122
+ end
123
+
124
+ it 'draws the current stage' do
125
+
126
+ subcontext.expects(:[]=).with(:stage, foo_stage)
127
+ subject.switch_to_stage :foo, :args
128
+ foo_stage.expects(:draw).with(:target)
129
+
130
+ subject.draw :target
131
+ end
132
+ end
133
+
134
+ describe 'callbacks' do
135
+ it 'registers next_stage'
136
+ it 'registers prev_stage'
137
+ it 'registers restart_stage'
138
+ it 'registers change_stage'
139
+ end
140
+ end
@@ -0,0 +1,73 @@
1
+ require 'helper'
2
+
3
+ describe Stage do
4
+ inject_mocks :input_manager, :actor_factory, :resource_manager,
5
+ :sound_manager, :config_manager, :director, :this_object_context,
6
+ :timer_manager
7
+ FakeDrawable = Struct.new :layer, :parallax
8
+
9
+ before do
10
+ @config_manager.stubs(:[]).with(:screen_resolution).returns([800,600])
11
+ @actor_factory.stubs(:director=)
12
+ @viewport = stub
13
+ Viewport.stubs(:new).with(800, 600).returns(@viewport)
14
+ @this_object_context.expects(:[]=).with(:viewport, @viewport)
15
+ subject.configure(:backstage, {})
16
+ end
17
+
18
+ it 'should construct' do
19
+ subject.should_not be_nil
20
+ end
21
+
22
+ it 'should have access to backstage' do
23
+ subject.backstage.should == :backstage
24
+ end
25
+
26
+ it 'should register drawables by parallax and layer'
27
+ it 'should unregister drawables by parallax and layer'
28
+ it 'should draw drawables by parallax and layers' do
29
+ a = FakeDrawable.new
30
+ b = FakeDrawable.new
31
+ c = FakeDrawable.new
32
+ d = FakeDrawable.new
33
+ e = FakeDrawable.new
34
+ f = FakeDrawable.new
35
+ x = FakeDrawable.new
36
+ y = FakeDrawable.new
37
+ z = FakeDrawable.new
38
+ subject.drawables = {
39
+ 2 => {3=> [a,b,c]},
40
+ 6 => {7=> [d,e,f]},
41
+ 9 => {13=> [x,y,z]},
42
+ }
43
+ subject.move_layer(2, 3, 6, 7).should == [d,e,f]
44
+ subject.drawables[6][7].should_not be_nil
45
+ subject.drawables[6][7].should == [a,b,c]
46
+ subject.drawables[2][3].should be_nil
47
+ end
48
+ it 'should move drawables layers' do
49
+
50
+ a = FakeDrawable.new
51
+ b = FakeDrawable.new
52
+ c = FakeDrawable.new
53
+ d = FakeDrawable.new
54
+ e = FakeDrawable.new
55
+ f = FakeDrawable.new
56
+ x = FakeDrawable.new
57
+ y = FakeDrawable.new
58
+ z = FakeDrawable.new
59
+ subject.drawables = {
60
+ 2 => {3=> [a,b,c]},
61
+ 6 => {7=> [d,e,f]},
62
+ 9 => {13=> [x,y,z]},
63
+ }
64
+ subject.move_layer(2, 3, 6, 7).should == [d,e,f]
65
+ subject.drawables[6][7].should_not be_nil
66
+ subject.drawables[6][7].should == [a,b,c]
67
+ subject.drawables[2][3].should be_nil
68
+ end
69
+
70
+ describe "#modal_actor" do
71
+ it 'pauses, shows actor, unpauses when that actor dies; ug, how to test this?'
72
+ end
73
+ end
@@ -0,0 +1,89 @@
1
+ require 'helper'
2
+
3
+ describe TimerManager do
4
+ describe "#add_timer" do
5
+ let(:block) { Proc.new do end }
6
+ it 'adds a timer by name' do
7
+ subject.add_timer 'foo', 45, &block
8
+ subject.timer('foo').should == {
9
+ count: 0, recurring: true,
10
+ interval_ms: 45, callback: block
11
+ }
12
+ end
13
+
14
+ it 'raises if a timer already exists by that name' do
15
+ subject.add_timer 'foo', 45, &block
16
+ lambda { subject.add_timer 'foo', 45, &block }.should raise_exception
17
+ end
18
+ end
19
+
20
+ describe "#remove_timer" do
21
+ let(:block) { Proc.new do end }
22
+ it 'removes a timer by name' do
23
+ subject.add_timer 'foo', 45, &block
24
+ subject.remove_timer 'foo'
25
+
26
+ subject.timer('foo').should_not be
27
+ end
28
+ end
29
+
30
+ describe "#update" do
31
+ it 'fires timers that need to be fired and roles up counts if not yet met' do
32
+ calls = 0
33
+ block = Proc.new do calls += 1 end
34
+ subject.add_timer 'foo', 45, &block
35
+
36
+ subject.update 45
37
+ calls.should == 0
38
+
39
+ subject.update 1
40
+ calls.should == 1
41
+
42
+ subject.update 90
43
+ calls.should == 2
44
+
45
+ subject.update 1
46
+ calls.should == 3
47
+ end
48
+
49
+ it 'removes fired non-recurring timmers' do
50
+ calls = 0
51
+ block = Proc.new do calls += 1 end
52
+ subject.add_timer 'foo', 45, false, &block
53
+
54
+ subject.update 46
55
+ calls.should == 1
56
+
57
+ subject.timer('foo').should_not be
58
+ end
59
+ end
60
+
61
+ describe "#pause" do
62
+ it 'pauses current timers' do
63
+ calls = 0
64
+ block = Proc.new do calls += 1 end
65
+ subject.add_timer 'foo', 45, false, &block
66
+
67
+ subject.pause
68
+ subject.update 50
69
+ calls.should == 0
70
+ end
71
+ end
72
+
73
+ describe "#unpause" do
74
+ it 'unpauses current timers' do
75
+ calls = 0
76
+ block = Proc.new do calls += 1 end
77
+ subject.add_timer 'foo', 45, false, &block
78
+
79
+ subject.pause
80
+ subject.update 50
81
+ calls.should == 0
82
+
83
+ subject.unpause
84
+ subject.update 50
85
+ calls.should == 1
86
+ end
87
+ end
88
+
89
+ end
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__),'helper')
2
-
1
+ require 'helper'
3
2
 
4
3
  class Vec
5
4
  attr_accessor :x, :y
@@ -152,7 +151,11 @@ describe 'A new viewport' do
152
151
  subject.x_offset = -10
153
152
  subject.y_offset = -100
154
153
 
155
- subject.bounds.should == [10,100,810,700]
154
+ bounds = subject.bounds
155
+ bounds.left.should == 10
156
+ bounds.top.should == 100
157
+ bounds.width.should == 810
158
+ bounds.height.should == 700
156
159
  end
157
160
  end
158
161
 
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ describe WrappedScreen do
4
+ inject_mocks :config_manager
5
+
6
+ describe "#setup" do
7
+ before do
8
+ @config_manager.stubs(:[]).with(:screen_resolution).returns [800,555]
9
+ @config_manager.stubs(:[]).with(:fullscreen).returns false
10
+ @config_manager.stubs(:[]).with(:title).returns "Some Title!"
11
+ @config_manager.stubs(:[]).with(:needs_cursor).returns nil
12
+
13
+ @gosu_window = stub('gosu window')
14
+ HookedGosuWindow.stubs(:new).with(800, 555, false).returns @gosu_window
15
+ end
16
+
17
+ it 'creates a new Gosu Window with opts from config manager' do
18
+
19
+ @gosu_window.expects(:caption=).with("Some Title!")
20
+ @gosu_window.expects(:needs_cursor=).with(nil)
21
+
22
+ subject.screen.should == @gosu_window
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,7 @@
1
+ ---
2
+ :sound: true
3
+ :auto_quit: KbEscape
4
+ :fullscreen: false
5
+ :screen_resolution:
6
+ - 1024
7
+ - 768
File without changes
File without changes
File without changes
File without changes
data/spec/helper.rb CHANGED
@@ -1,3 +1,11 @@
1
+ if ENV["COVERAGE"]
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "/spec/"
5
+ add_filter "/lib/gamebox/lib/"
6
+ end
7
+ end
8
+
1
9
  here = File.dirname(__FILE__)
2
10
  gamebox_root = File.expand_path(File.join(here, '..', 'lib'))
3
11
 
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__),'helper')
1
+ require 'helper'
2
+
2
3
  describe ClassFinder do
3
4
  describe "::find" do
4
5
  it "finds inflected classname" do
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ describe SpatialTreeStagehand do
4
+ subject { SpatialTreeStagehand.new :stage, {} }
5
+ let(:tree) { stub('tree') }
6
+
7
+ before do
8
+ AABBTree.stubs(:new).returns tree
9
+ end
10
+
11
+ describe "#items" do
12
+ it "returns all the items" do
13
+ tree.stubs(:items).returns(key: :value)
14
+ subject.items.should == [:key]
15
+ end
16
+ end
17
+
18
+
19
+ end
@@ -0,0 +1,116 @@
1
+ require 'helper'
2
+
3
+ describe :graphical_actor_view do
4
+ # TODO this subjet construction is WAY off now
5
+ let!(:subcontext) do
6
+ it = nil
7
+ Conject.default_object_context.in_subcontext{|ctx|it = ctx};
8
+ _mocks = create_mocks *(Actor.object_definition.component_names + ActorView.object_definition.component_names - [:actor])
9
+ _mocks[:this_object_context] = it
10
+ _mocks.each do |k,v|
11
+ it[k] = v
12
+ end
13
+ it
14
+ end
15
+ subject { subcontext[:actor_view_factory].build actor, {} }
16
+ let(:actor) do
17
+ subcontext[:actor].tap do |a|
18
+ a.has_attribute :view, :graphical_actor_view
19
+ a.has_attribute :x, 2
20
+ a.has_attribute :y, 3
21
+ a.has_attribute :image, image
22
+ a.has_attribute :tiled
23
+ a.has_attribute :num_x_tiles
24
+ a.has_attribute :num_y_tiles
25
+ end
26
+ end
27
+
28
+ let(:image) { stub('image', width: 10, height: 20, draw:nil) }
29
+
30
+ before do
31
+ # inject mocks hack
32
+ @actor = actor
33
+ @stage.stub_everything
34
+ end
35
+
36
+ describe "#draw" do
37
+ context "no image" do
38
+ it 'does nothing if actor has no image' do
39
+ subject.draw(:target, 0, 0, 0)
40
+ end
41
+ end
42
+
43
+ context "with image" do
44
+ before do
45
+ Color.stubs(:new).returns :color
46
+ actor.stubs(:image).returns(image)
47
+ end
48
+
49
+ it 'creates the color with the correct alpha' do
50
+ Color.expects(:new).with(0xFF, 0xFF, 0xFF, 0xFF).returns(:full_color)
51
+ subject.draw(:target, 0, 0, 0)
52
+ end
53
+
54
+ it 'handles rotation correctly for physical actors' do
55
+ actor.stubs(:is?).with(:physical).returns(true)
56
+ actor.stubs(:rotation).returns(1.3)
57
+
58
+ image.expects(:draw_rot).with(2, 3, 1, 1.3, 0.5, 0.5, 1, 1, :color)
59
+ subject.draw(:target, 0, 0, 1)
60
+ end
61
+
62
+ it 'translates using the offsets passed in' do
63
+ actor.stubs(:is?).with(:physical).returns(true)
64
+ actor.stubs(:rotation).returns(1.3)
65
+
66
+ image.expects(:draw_rot).with(4, 6, 1, 1.3, 0.5, 0.5, 1, 1, :color)
67
+ subject.draw(:target, 2, 3, 1)
68
+ end
69
+
70
+ it 'handles draw correctly for plain actors w/o rotation' do
71
+ image.expects(:draw).with(2, 3, 1, 1, 1, :color)
72
+ subject.draw(:target, 0, 0, 1)
73
+ end
74
+
75
+ it 'handles rotation correctly for plain actors w/ rotation' do
76
+ actor.stubs(:rotation).returns(1.3)
77
+ image.expects(:draw_rot).with(2, 3, 1, 1.3, 0.5, 0.5, 1, 1, :color)
78
+ subject.draw(:target, 0, 0, 1)
79
+ end
80
+
81
+ it 'handles nil rotation' do
82
+ actor.stubs(:rotation).returns(nil)
83
+ image.expects(:draw_rot).with(2, 3, 1, 0.0, 0.5, 0.5, 1, 1, :color)
84
+ subject.draw(:target, 0, 0, 1)
85
+ end
86
+
87
+ it 'scales the image correctly' do
88
+ actor.stubs(:rotation).returns(nil)
89
+ actor.stubs(:x_scale).returns(2)
90
+ actor.stubs(:y_scale).returns(3)
91
+
92
+ image.expects(:draw_rot).with(2, 3, 1, 0.0, 0.5, 0.5, 2, 3, :color)
93
+ subject.draw(:target, 0, 0, 1)
94
+ end
95
+
96
+ it 'draws correctly for tiled graphical actors' do
97
+ actor.stubs(:rotation).returns(0.0)
98
+ actor.stubs(:is?).with(:graphical).returns(true)
99
+ actor.stubs(:tiled).returns(true)
100
+ actor.stubs(:num_x_tiles).returns(2)
101
+ actor.stubs(:num_y_tiles).returns(3)
102
+
103
+ image.expects(:draw_rot).with(2, 3, 1, 0.0, 1, 1)
104
+ image.expects(:draw_rot).with(2, 23, 1, 0.0, 1, 1)
105
+ image.expects(:draw_rot).with(2, 43, 1, 0.0, 1, 1)
106
+ image.expects(:draw_rot).with(12, 3, 1, 0.0, 1, 1)
107
+ image.expects(:draw_rot).with(12, 23, 1, 0.0, 1, 1)
108
+ image.expects(:draw_rot).with(12, 43, 1, 0.0, 1, 1)
109
+
110
+ subject.draw(:target, 0, 0, 1)
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+ end