gosu_extensions 0.2.4 → 0.2.5
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.
- data/VERSION +1 -1
- data/lib/core/game_window.rb +2 -2
- data/lib/traits/controllable.rb +11 -1
- data/spec/lib/traits/controllable_spec.rb +13 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/lib/core/game_window.rb
CHANGED
@@ -276,8 +276,8 @@ class GameWindow < Gosu::Window
|
|
276
276
|
# Gosu::Button::KbS => :reverse,
|
277
277
|
# Gosu::Button::Kb1 => :revive
|
278
278
|
#
|
279
|
-
def add_controls_for object
|
280
|
-
@controls << Control.new(self, object)
|
279
|
+
def add_controls_for object, mapping = nil
|
280
|
+
@controls << Control.new(self, object, mapping)
|
281
281
|
end
|
282
282
|
|
283
283
|
# Main loop methods.
|
data/lib/traits/controllable.rb
CHANGED
@@ -26,10 +26,20 @@ module Controllable extend Trait
|
|
26
26
|
attr_accessor :controls_mapping
|
27
27
|
InitializerHooks.register self do
|
28
28
|
self.controls_mapping = mapping
|
29
|
-
self.
|
29
|
+
self.controls
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
|
+
# You can add controls dynamically.
|
36
|
+
#
|
37
|
+
# Provide a hash of mappings:
|
38
|
+
# player_one.controls Gosu::Button::KbA => Turnable::Left,
|
39
|
+
# Gosu::Button::KbD => Turnable::Right
|
40
|
+
#
|
41
|
+
def controls mapping = nil
|
42
|
+
self.window.add_controls_for self, mapping
|
43
|
+
end
|
44
|
+
|
35
45
|
end
|
@@ -6,6 +6,19 @@ describe Controllable do
|
|
6
6
|
@window = stub :window
|
7
7
|
end
|
8
8
|
|
9
|
+
describe "controls" do
|
10
|
+
before(:each) do
|
11
|
+
@controllable = test_class_with(Controllable).new @window
|
12
|
+
end
|
13
|
+
it "should return the mapping" do
|
14
|
+
mapping = stub :mapping
|
15
|
+
|
16
|
+
@window.should_receive(:add_controls_for).once.with @controllable, mapping
|
17
|
+
|
18
|
+
@controllable.controls mapping
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
9
22
|
describe "add_controls_for" do
|
10
23
|
before(:each) do
|
11
24
|
@controllable_class = test_class_with Controllable do
|