gosu_extensions 0.1.20 → 0.1.21
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/controls.rb +8 -5
- data/spec/lib/core/control_spec.rb +82 -0
- data/spec/lib/core/controls_spec.rb +65 -0
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.21
|
data/lib/core/controls.rb
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
#
|
3
3
|
class Controls
|
4
4
|
|
5
|
+
attr_reader :controls
|
6
|
+
|
7
|
+
# It's possible to give the controls a number of controls.
|
5
8
|
#
|
6
|
-
|
7
|
-
|
8
|
-
@controls = []
|
9
|
+
def initialize *controls
|
10
|
+
@controls = controls
|
9
11
|
end
|
10
12
|
|
11
13
|
# Add the given control to the controls, except if it is nil or has no mapping.
|
@@ -13,15 +15,16 @@ class Controls
|
|
13
15
|
def << control
|
14
16
|
return unless control && control.mapping?
|
15
17
|
@controls << control
|
18
|
+
@controls
|
16
19
|
end
|
17
20
|
|
18
21
|
# Remove the control(s) with the given controllable.
|
19
22
|
#
|
20
23
|
def remove_all_of controllable
|
21
|
-
@controls.reject { |control| control.controllable == controllable }
|
24
|
+
@controls.reject! { |control| control.controllable == controllable }
|
22
25
|
end
|
23
26
|
|
24
|
-
#
|
27
|
+
# Let each control handle input.
|
25
28
|
#
|
26
29
|
def handle
|
27
30
|
@controls.each &:handle
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Control do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@window = stub :window
|
7
|
+
@controllable = stub :controllable
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'handle' do
|
11
|
+
before(:each) do
|
12
|
+
@window.should_receive(:button_down?).any_number_of_times.with(:some_key).and_return true
|
13
|
+
@control = Control.new @window, @controllable, { :some_key => :some_command }
|
14
|
+
end
|
15
|
+
context 'controllable not destroyed' do
|
16
|
+
before(:each) do
|
17
|
+
@controllable.stub! :destroyed? => false
|
18
|
+
end
|
19
|
+
it 'should just return' do
|
20
|
+
@controllable.should_receive(:some_command).once.with
|
21
|
+
|
22
|
+
@control.handle
|
23
|
+
end
|
24
|
+
end
|
25
|
+
context 'controllable destroyed' do
|
26
|
+
before(:each) do
|
27
|
+
@controllable.stub! :destroyed? => true
|
28
|
+
end
|
29
|
+
it 'should just return' do
|
30
|
+
@controllable.should_receive(:some_command).never
|
31
|
+
|
32
|
+
@control.handle
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'mapping?' do
|
38
|
+
context 'no controllable mapping, no direct mapping' do
|
39
|
+
before(:each) do
|
40
|
+
@control = Control.new @window, @controllable
|
41
|
+
end
|
42
|
+
it 'should return false' do
|
43
|
+
@control.mapping?.should == false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context 'with controllable mapping, empty' do
|
47
|
+
before(:each) do
|
48
|
+
@controllable.stub! :controls_mapping => {}
|
49
|
+
@control = Control.new @window, @controllable
|
50
|
+
end
|
51
|
+
it 'should return false' do
|
52
|
+
@control.mapping?.should == false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
context 'with controllable mapping, non-empty' do
|
56
|
+
before(:each) do
|
57
|
+
@controllable.stub! :controls_mapping => { :non_empty => :mapping }
|
58
|
+
@control = Control.new @window, @controllable
|
59
|
+
end
|
60
|
+
it 'should return true' do
|
61
|
+
@control.mapping?.should == true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
context 'with direct mapping, empty' do
|
65
|
+
before(:each) do
|
66
|
+
@control = Control.new @window, @controllable, {}
|
67
|
+
end
|
68
|
+
it 'should return false' do
|
69
|
+
@control.mapping?.should == false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
context 'with direct mapping, non-empty' do
|
73
|
+
before(:each) do
|
74
|
+
@control = Control.new @window, @controllable, :non_empty => :mapping
|
75
|
+
end
|
76
|
+
it 'should return true' do
|
77
|
+
@control.mapping?.should == true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Controls do
|
4
|
+
|
5
|
+
describe 'handle' do
|
6
|
+
before(:each) do
|
7
|
+
@handler1 = stub :handler1
|
8
|
+
@handler2 = stub :handler2
|
9
|
+
@handler3 = stub :handler3
|
10
|
+
|
11
|
+
@controls = Controls.new @handler2, @handler1, @handler3
|
12
|
+
end
|
13
|
+
it 'should call each handle method' do
|
14
|
+
@handler1.should_receive(:handle).once.with
|
15
|
+
@handler2.should_receive(:handle).once.with
|
16
|
+
@handler3.should_receive(:handle).once.with
|
17
|
+
|
18
|
+
@controls.handle
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'remove_all_of' do
|
23
|
+
before(:each) do
|
24
|
+
@controllable = stub :controllable
|
25
|
+
@remove = stub :remove, :controllable => @controllable
|
26
|
+
@nonremove = stub :nonremove, :controllable => :some_other_controllable
|
27
|
+
|
28
|
+
@controls = Controls.new @remove, @nonremove, @remove, @nonremove, @nonremove, @nonremove
|
29
|
+
end
|
30
|
+
it 'should remove the right control' do
|
31
|
+
@controls.remove_all_of @controllable
|
32
|
+
|
33
|
+
@controls.controls.size.should == 4
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '<<' do
|
38
|
+
before(:each) do
|
39
|
+
@controls = Controls.new
|
40
|
+
@control = stub :control
|
41
|
+
end
|
42
|
+
it 'should not add nil' do
|
43
|
+
@control = nil
|
44
|
+
|
45
|
+
@controls << @control
|
46
|
+
|
47
|
+
@controls.controls.empty?.should == true
|
48
|
+
end
|
49
|
+
it 'should not add mapping? false' do
|
50
|
+
@control.stub! :mapping? => false
|
51
|
+
|
52
|
+
@controls << @control
|
53
|
+
|
54
|
+
@controls.controls.empty?.should == true
|
55
|
+
end
|
56
|
+
it 'should add non-nil, mapping? true' do
|
57
|
+
@control.stub! :mapping? => true
|
58
|
+
|
59
|
+
@controls << @control
|
60
|
+
|
61
|
+
@controls.controls.size.should == 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 21
|
9
|
+
version: 0.1.21
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -119,6 +119,8 @@ signing_key:
|
|
119
119
|
specification_version: 3
|
120
120
|
summary: Default extensions built onto the popular Gosu Framework. Uses Chipmunk for game physics. That's it for now. I'm working on them. Anyway, GAME ON!
|
121
121
|
test_files:
|
122
|
+
- spec/lib/core/control_spec.rb
|
123
|
+
- spec/lib/core/controls_spec.rb
|
122
124
|
- spec/lib/core/initializer_hooks_spec.rb
|
123
125
|
- spec/lib/core/it_is_a_spec.rb
|
124
126
|
- spec/lib/core/trait_spec.rb
|