metro 0.0.5 → 0.0.6
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/lib/metro/models/generic.rb +9 -0
- data/lib/metro/models/image.rb +7 -0
- data/lib/metro/models/label.rb +2 -1
- data/lib/metro/models/{select.rb → menu.rb} +36 -9
- data/lib/metro/models/model.rb +2 -2
- data/lib/metro/scene.rb +10 -0
- data/lib/metro/scene_actor.rb +9 -4
- data/lib/metro/version.rb +1 -1
- metadata +3 -3
data/lib/metro/models/generic.rb
CHANGED
@@ -7,6 +7,15 @@ module Metro
|
|
7
7
|
#
|
8
8
|
class Generic < Model
|
9
9
|
|
10
|
+
def draw
|
11
|
+
raise cannot_draw_message
|
12
|
+
end
|
13
|
+
|
14
|
+
def cannot_draw_message
|
15
|
+
[ "Unable to draw #{name} in #{scene}",
|
16
|
+
"The actor named '#{name}' could not find a suitable model so it could not be drawn in the scene #{scene}" ].join("\n")
|
17
|
+
end
|
18
|
+
|
10
19
|
end
|
11
20
|
end
|
12
21
|
end
|
data/lib/metro/models/image.rb
CHANGED
@@ -11,6 +11,13 @@ module Metro
|
|
11
11
|
|
12
12
|
attr_accessor :angle, :center_x, :center_y, :x_factor, :y_factor
|
13
13
|
|
14
|
+
def after_initialize
|
15
|
+
@angle = 0
|
16
|
+
@center_x = @center_y = 0.5
|
17
|
+
@x_factor = @y_factor = 1
|
18
|
+
@z_order = 0
|
19
|
+
end
|
20
|
+
|
14
21
|
def image
|
15
22
|
@image ||= Gosu::Image.new(window,asset_path(path))
|
16
23
|
end
|
data/lib/metro/models/label.rb
CHANGED
@@ -2,25 +2,25 @@ module Metro
|
|
2
2
|
module Models
|
3
3
|
|
4
4
|
#
|
5
|
-
# Draws a a menu of options.
|
6
|
-
# element select. A select model also inserts itself into the scene as an event
|
5
|
+
# Draws a a menu of options. A menu model inserts itself into the scene as an event
|
7
6
|
# target as it needs to maintain the state of the menu. When an option is selected
|
8
7
|
# an event is fired based on the name of the option.
|
9
8
|
#
|
10
|
-
# @note Only one '
|
9
|
+
# @note Only one 'menu' can be defined for a given scene.
|
11
10
|
#
|
12
|
-
class
|
13
|
-
|
11
|
+
class Menu < Model
|
12
|
+
attr_reader :selected_index, :menu_options
|
14
13
|
|
15
|
-
def
|
14
|
+
def after_initialize
|
16
15
|
@selected_index = 0
|
17
16
|
end
|
18
17
|
|
19
18
|
def window=(value)
|
20
19
|
@window = value
|
20
|
+
@menu_options = options.map {|option| Option.new option }
|
21
21
|
events
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def events
|
25
25
|
relay = EventRelay.new(self,window)
|
26
26
|
|
@@ -32,7 +32,7 @@ module Metro
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def selection
|
35
|
-
scene_method =
|
35
|
+
scene_method = option_at_index(selected_index).method
|
36
36
|
scene.send scene_method
|
37
37
|
end
|
38
38
|
|
@@ -61,17 +61,44 @@ module Metro
|
|
61
61
|
highlight_color.alpha = value.floor
|
62
62
|
end
|
63
63
|
|
64
|
+
def option_at_index(index)
|
65
|
+
menu_options[index]
|
66
|
+
end
|
67
|
+
|
64
68
|
def draw
|
65
69
|
options.each_with_index do |option,index|
|
66
70
|
|
71
|
+
option_name = option_at_index(index).name
|
72
|
+
|
67
73
|
draw_color = color
|
68
74
|
draw_color = highlight_color if index == selected_index
|
69
75
|
|
70
76
|
y_position = y + padding * index
|
71
|
-
font.draw
|
77
|
+
font.draw option_name, x, y_position, Metro::Game::UI, 1.0, 1.0, draw_color
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
81
|
+
class Option
|
82
|
+
|
83
|
+
attr_reader :data
|
84
|
+
|
85
|
+
attr_accessor :name, :method
|
86
|
+
|
87
|
+
def initialize(data)
|
88
|
+
@data = data
|
89
|
+
|
90
|
+
if data.is_a?(Hash)
|
91
|
+
@name = data.keys.first
|
92
|
+
@method = data.values.first
|
93
|
+
else
|
94
|
+
@name = data
|
95
|
+
@method = data.to_s.downcase.gsub(/\s/,'_').gsub(/^[^a-zA-Z]*/,'').gsub(/[^a-zA-Z0-9\s_]/,'')
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
75
102
|
end
|
76
103
|
end
|
77
104
|
end
|
data/lib/metro/models/model.rb
CHANGED
@@ -100,7 +100,7 @@ module Metro
|
|
100
100
|
|
101
101
|
options.each do |raw_key,value|
|
102
102
|
|
103
|
-
key = raw_key.dup
|
103
|
+
key = raw_key.to_s.dup
|
104
104
|
key.gsub!(/-/,'_')
|
105
105
|
key.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
106
106
|
key.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
@@ -184,5 +184,5 @@ end
|
|
184
184
|
|
185
185
|
require_relative 'generic'
|
186
186
|
require_relative 'label'
|
187
|
-
require_relative '
|
187
|
+
require_relative 'menu'
|
188
188
|
require_relative 'image'
|
data/lib/metro/scene.rb
CHANGED
@@ -254,6 +254,16 @@ module Metro
|
|
254
254
|
@updaters << updater
|
255
255
|
end
|
256
256
|
|
257
|
+
#
|
258
|
+
# A simplier syntax to enqueue an animation. At the moment this animation is going
|
259
|
+
# to be an implicit animation.
|
260
|
+
#
|
261
|
+
def animate(options,&block)
|
262
|
+
animation = Metro::ImplicitAnimation.new options.merge(context: self)
|
263
|
+
animation.on_complete(&block) if block
|
264
|
+
enqueue animation
|
265
|
+
end
|
266
|
+
|
257
267
|
#
|
258
268
|
# The `base_update` method is called by the Game Window. This is to allow for any
|
259
269
|
# special update needs to be handled before calling the traditional `update` method
|
data/lib/metro/scene_actor.rb
CHANGED
@@ -10,17 +10,22 @@ module Metro
|
|
10
10
|
|
11
11
|
def create(contents = {})
|
12
12
|
contents = {} unless contents
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
actor_class = class_for_actor(model_name(contents))
|
14
|
+
instance = actor_class.new
|
15
|
+
instance._load options.merge(contents)
|
16
|
+
instance
|
16
17
|
end
|
17
18
|
|
18
19
|
def load_from_previous_scene?
|
19
20
|
options[:from] == :previous_scene
|
20
21
|
end
|
21
22
|
|
23
|
+
def model_name(contents = {})
|
24
|
+
contents['model'] || contents[:model] || options['model'] || options[:model] || name
|
25
|
+
end
|
26
|
+
|
22
27
|
def class_for_actor(model_name)
|
23
|
-
Model.model(model_name
|
28
|
+
Model.model(model_name)
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
data/lib/metro/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gosu
|
@@ -52,8 +52,8 @@ files:
|
|
52
52
|
- lib/metro/models/generic.rb
|
53
53
|
- lib/metro/models/image.rb
|
54
54
|
- lib/metro/models/label.rb
|
55
|
+
- lib/metro/models/menu.rb
|
55
56
|
- lib/metro/models/model.rb
|
56
|
-
- lib/metro/models/select.rb
|
57
57
|
- lib/metro/scene.rb
|
58
58
|
- lib/metro/scene_actor.rb
|
59
59
|
- lib/metro/scene_view/json_view.rb
|