gosu_extensions 0.1.24 → 0.1.25
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/core/wave.rb +18 -6
- data/lib/traits/attachable.rb +1 -1
- data/lib/traits/pod.rb +25 -21
- data/spec/lib/traits/attachable_spec.rb +4 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.25
|
data/lib/core/wave.rb
CHANGED
@@ -4,11 +4,23 @@ class Wave
|
|
4
4
|
|
5
5
|
attr_reader :generated_type, :execution_amount, :positioning_function
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class << self
|
8
|
+
def uniform_random
|
9
|
+
lambda { |window, instance| instance.warp_to *window.uniform_random_position }
|
10
|
+
end
|
11
|
+
def top_border offset = 0
|
12
|
+
lambda { |window, instance| instance.warp_to rand(window.width), -offset }
|
13
|
+
end
|
14
|
+
def right_border offset = 0
|
15
|
+
lambda { |window, instance| instance.warp_to window.width+offset, rand(window.height) }
|
16
|
+
end
|
17
|
+
def bottom_border offset = 0
|
18
|
+
lambda { |window, instance| instance.warp_to rand(window.width), window.height+offset }
|
19
|
+
end
|
20
|
+
def left_border offset = 0
|
21
|
+
lambda { |window, instance| instance.warp_to -offset, rand(window.height) }
|
22
|
+
end
|
23
|
+
end
|
12
24
|
|
13
25
|
#
|
14
26
|
#
|
@@ -17,7 +29,7 @@ class Wave
|
|
17
29
|
def initialize generated_type, execution_amount = 1, &positioning_function
|
18
30
|
@generated_type = generated_type
|
19
31
|
@execution_amount = execution_amount
|
20
|
-
@positioning_function = positioning_function ||
|
32
|
+
@positioning_function = positioning_function || Wave.uniform_random
|
21
33
|
end
|
22
34
|
|
23
35
|
#
|
data/lib/traits/attachable.rb
CHANGED
data/lib/traits/pod.rb
CHANGED
@@ -15,25 +15,17 @@ module Pod extend Trait
|
|
15
15
|
MANUAL
|
16
16
|
|
17
17
|
def self.included target_class
|
18
|
-
target_class.extend
|
18
|
+
target_class.extend ClassMethods
|
19
19
|
target_class.holds_attachments
|
20
|
+
target_class.send :include, InstanceMethods
|
20
21
|
end
|
21
22
|
|
22
|
-
# TODO is_a Rack
|
23
23
|
#
|
24
|
-
# TODO Maybe
|
25
|
-
# is_a Rack.
|
26
|
-
# with(Cannon, 10, 10).
|
27
|
-
# with(Cannon, 20, 10)
|
28
24
|
#
|
29
|
-
module
|
25
|
+
module ClassMethods
|
30
26
|
|
31
27
|
def holds_attachments
|
32
|
-
include InstanceMethods
|
33
|
-
alias_method_chain :move, :attachments
|
34
|
-
|
35
28
|
class_inheritable_accessor :prototype_attachments
|
36
|
-
extend ClassMethods
|
37
29
|
hook = lambda do
|
38
30
|
self.class.prototype_attachments.each do |type, x, y|
|
39
31
|
attach type.new(self.window), x, y
|
@@ -42,10 +34,6 @@ module Pod extend Trait
|
|
42
34
|
InitializerHooks.append self, &hook
|
43
35
|
end
|
44
36
|
|
45
|
-
end
|
46
|
-
|
47
|
-
module ClassMethods
|
48
|
-
|
49
37
|
# Example:
|
50
38
|
# class MotherShip
|
51
39
|
# is_a Pod
|
@@ -62,17 +50,26 @@ module Pod extend Trait
|
|
62
50
|
|
63
51
|
module InstanceMethods
|
64
52
|
|
65
|
-
|
53
|
+
def materialize attachment
|
54
|
+
attachment.extend Attachable # This is where Ruby shines.
|
55
|
+
window.register attachment
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
#
|
60
|
+
def attachments
|
61
|
+
@attachments || @attachments = []
|
62
|
+
end
|
66
63
|
|
67
64
|
#
|
68
65
|
#
|
69
66
|
def attach attachment, x, y
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
# TODO Move to better place.
|
68
|
+
self.class.alias_method_chain :move, :attachments unless respond_to?(:move_without_attachments)
|
69
|
+
#
|
70
|
+
materialize attachment
|
74
71
|
attachment.relative_position = CP::Vec2.new x, y
|
75
|
-
|
72
|
+
attachments << attachment
|
76
73
|
end
|
77
74
|
|
78
75
|
#
|
@@ -89,12 +86,19 @@ module Pod extend Trait
|
|
89
86
|
end
|
90
87
|
end
|
91
88
|
|
89
|
+
#
|
90
|
+
#
|
91
|
+
def relative_position attachment
|
92
|
+
self.position + attachment.relative_position.rotate(self.rotation_vector)
|
93
|
+
end
|
94
|
+
|
92
95
|
#
|
93
96
|
#
|
94
97
|
def move_with_attachments
|
95
98
|
move_attachments
|
96
99
|
move_without_attachments
|
97
100
|
end
|
101
|
+
# alias_method_chain :move, :attachments
|
98
102
|
|
99
103
|
end
|
100
104
|
|
@@ -8,11 +8,12 @@ describe Attachable do
|
|
8
8
|
|
9
9
|
describe "move_relative" do
|
10
10
|
before(:each) do
|
11
|
-
@attachable.stub! :
|
12
|
-
|
11
|
+
@attachable.stub! :position= => nil, :rotation= => nil
|
12
|
+
|
13
|
+
@pod = stub :pod, :relative_position => :relative_position, :rotation => :some_rotation
|
13
14
|
end
|
14
15
|
it "should set the position to the pod's position plus the relative position" do
|
15
|
-
@attachable.should_receive(:position=).once.with
|
16
|
+
@attachable.should_receive(:position=).once.with :relative_position
|
16
17
|
|
17
18
|
@attachable.move_relative @pod
|
18
19
|
end
|