metro 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/changelog.md +9 -0
- data/lib/commands/thor.rb +2 -0
- data/lib/core_ext/numeric.rb +3 -3
- data/lib/metro/animation/has_animations.rb +19 -3
- data/lib/metro/events/event_relay.rb +8 -36
- data/lib/metro/events/has_events.rb +5 -5
- data/lib/metro/models/draws.rb +5 -5
- data/lib/metro/models/properties/animation_property.rb +3 -3
- data/lib/metro/models/properties/dimensions_property.rb +2 -2
- data/lib/metro/models/properties/scale_property.rb +26 -28
- data/lib/metro/models/properties/text_property.rb +11 -2
- data/lib/metro/scene.rb +4 -4
- data/lib/metro/version.rb +1 -1
- data/lib/metro/views/no_view.rb +1 -1
- data/lib/metro/views/parsers.rb +17 -1
- data/lib/metro/views/view.rb +1 -1
- data/lib/metro/views/writers.rb +15 -0
- metadata +7 -6
data/changelog.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Metro
|
2
2
|
|
3
|
+
## 0.3.0 / 2012-11-25
|
4
|
+
|
5
|
+
* FIX lots of typos in the documentation
|
6
|
+
* Removed `up_action_missing` and `down_ation_missing` event handling
|
7
|
+
* Notification events now have block support for 0, 1 and 2 parameters
|
8
|
+
* FIX Registration of custom defined custom view parsers
|
9
|
+
* FIX Grid Layer layout for Edit Mode
|
10
|
+
|
11
|
+
|
3
12
|
## 0.2.7 / 2012/11-20
|
4
13
|
|
5
14
|
* FIX to the new game template
|
data/lib/commands/thor.rb
CHANGED
data/lib/core_ext/numeric.rb
CHANGED
@@ -2,14 +2,14 @@ class Numeric
|
|
2
2
|
|
3
3
|
#
|
4
4
|
# Set the tick interval which is used in conversion of seconds to
|
5
|
-
# ticks.
|
5
|
+
# ticks.
|
6
6
|
#
|
7
7
|
def self.tick_interval=(value)
|
8
8
|
@tick_interval = value.to_f
|
9
9
|
end
|
10
10
|
|
11
11
|
#
|
12
|
-
# @return the game tick interval.
|
12
|
+
# @return the game tick interval. By default the tick interval is 16.66666
|
13
13
|
#
|
14
14
|
def self.tick_interval
|
15
15
|
@tick_interval.to_f == 0 ? 16.666666 : @tick_interval.to_f
|
@@ -22,7 +22,7 @@ class Numeric
|
|
22
22
|
# game ticks. This is to allow for a number of seconds to be expressed
|
23
23
|
# in situations where game ticks are used (e.g. animations).
|
24
24
|
#
|
25
|
-
# @example Expressing an animation that takes place over 3 seconds (180 ticks)
|
25
|
+
# @example Expressing an animation that takes place over 3 seconds (~180 ticks)
|
26
26
|
#
|
27
27
|
# class ExampleScene < Metro::Scene
|
28
28
|
# draws :title
|
@@ -8,8 +8,24 @@ module Metro
|
|
8
8
|
end
|
9
9
|
|
10
10
|
#
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# Define an animation from within another animation block, an event block
|
12
|
+
# or a method.
|
13
|
+
#
|
14
|
+
# @example Defining an animation that fades out the hero when they have
|
15
|
+
# died.
|
16
|
+
#
|
17
|
+
# class HellScene
|
18
|
+
# draws :hero
|
19
|
+
#
|
20
|
+
# def update
|
21
|
+
# if hero.dead?
|
22
|
+
# animate :hero, to: { alpha: 0 }, interval: 60.ticks do
|
23
|
+
# transition_to :game_over
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# end
|
13
29
|
#
|
14
30
|
def animate(actor_or_actor_name,options,&block)
|
15
31
|
options[:actor] = actor(actor_or_actor_name)
|
@@ -29,7 +45,7 @@ module Metro
|
|
29
45
|
# @example Defining an animation that fades in and moves a logo when it is
|
30
46
|
# done, transition to the title scene.
|
31
47
|
#
|
32
|
-
# animate :logo, to: { y: 80, alpha: 50 }, interval: 120 do
|
48
|
+
# animate :logo, to: { y: 80, alpha: 50 }, interval: 120.ticks do
|
33
49
|
# transition_to :title
|
34
50
|
# end
|
35
51
|
#
|
@@ -18,29 +18,6 @@ module Metro
|
|
18
18
|
# @see #on_down
|
19
19
|
# @see #on_hold
|
20
20
|
#
|
21
|
-
# A target can also receive events when 'button_up' and 'button_down' events
|
22
|
-
# have been fired but did not map to any specified actions. This is similar to
|
23
|
-
# Ruby's {#method_missing}.
|
24
|
-
#
|
25
|
-
# To receive unampped 'button_up' events define a method
|
26
|
-
# named `up_action_missing(id)` within your target.
|
27
|
-
#
|
28
|
-
# To receive unampped 'button_down' events define a method
|
29
|
-
# named `down_action_missing(id)` within your target.
|
30
|
-
#
|
31
|
-
# @example Scene that receives all the 'button_up' and 'button_down' events that
|
32
|
-
# are not mapped to actions.
|
33
|
-
#
|
34
|
-
# class ExampleScene
|
35
|
-
# def up_action_missing(id)
|
36
|
-
# puts "No up action found for #{id}"
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# def down_action_missing(id)
|
40
|
-
# puts "No down action found for #{id}"
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
21
|
class EventRelay
|
45
22
|
|
46
23
|
#
|
@@ -276,22 +253,20 @@ module Metro
|
|
276
253
|
execute_block_for_target(&action) if window and window.button_down?(key)
|
277
254
|
end
|
278
255
|
end
|
279
|
-
|
256
|
+
|
280
257
|
def execute_block_for_target(&block)
|
281
258
|
event_data = EventData.new(window)
|
282
259
|
target.instance_exec(event_data,&block)
|
283
260
|
end
|
284
261
|
|
285
|
-
# @return a block of code that is mapped for the 'button_up' id
|
286
|
-
# to the action missing method.
|
262
|
+
# @return a block of code that is mapped for the 'button_up' id
|
287
263
|
def up_action(id)
|
288
|
-
up_actions[id] || lambda {|
|
264
|
+
up_actions[id] || lambda {|no_op| }
|
289
265
|
end
|
290
266
|
|
291
|
-
# @return a block of code that is mapped for the 'button_down' id
|
292
|
-
# to the action missing method.
|
267
|
+
# @return a block of code that is mapped for the 'button_down' id
|
293
268
|
def down_action(id)
|
294
|
-
down_actions[id] || lambda {|
|
269
|
+
down_actions[id] || lambda {|no_op| }
|
295
270
|
end
|
296
271
|
|
297
272
|
#
|
@@ -311,14 +286,11 @@ module Metro
|
|
311
286
|
# of the target. If there are two parameters we will simply execute the action and
|
312
287
|
# pass it both the target and the sender.
|
313
288
|
#
|
314
|
-
# @TODO: Allow for the blocks to be specified with one parameter: source (and executed
|
315
|
-
# within the context of the target)
|
316
|
-
#
|
317
|
-
# @TODO: Allow for the blocks to be specified with three parameters: source, target, event
|
318
|
-
#
|
319
289
|
def _fire_event_for_notification(event,sender,action)
|
320
290
|
if action.arity == 2
|
321
|
-
|
291
|
+
target.instance_exec(sender,event,&action)
|
292
|
+
elsif action.arity == 1
|
293
|
+
target.instance_exec(sender,&action)
|
322
294
|
else
|
323
295
|
target.instance_eval(&action)
|
324
296
|
end
|
@@ -25,15 +25,15 @@ module Metro
|
|
25
25
|
# @example Registering for button held events
|
26
26
|
#
|
27
27
|
# class ExampleScene
|
28
|
-
# event :on_hold KbLeft,
|
28
|
+
# event :on_hold KbLeft, GpLeft do
|
29
29
|
# player.turn_left
|
30
30
|
# end
|
31
31
|
#
|
32
|
-
# event :on_hold, KbRight,
|
32
|
+
# event :on_hold, KbRight, GpRight do
|
33
33
|
# player.turn_right
|
34
34
|
# end
|
35
35
|
#
|
36
|
-
# event :on_hold, KbUp,
|
36
|
+
# event :on_hold, KbUp, GpButton0, do: :calculate_accleration
|
37
37
|
#
|
38
38
|
# def calculate_acceleration
|
39
39
|
# long_complicated_calculated_result = 0
|
@@ -66,7 +66,7 @@ module Metro
|
|
66
66
|
# @example Registering for a button down event to call a method named 'previous_option'
|
67
67
|
#
|
68
68
|
# class ExampleScene
|
69
|
-
# event :on_down,
|
69
|
+
# event :on_down, GpLeft, GpUp, do: :previous_option
|
70
70
|
#
|
71
71
|
# def previous_option
|
72
72
|
# @selected_index = @selected_index - 1
|
@@ -81,7 +81,7 @@ module Metro
|
|
81
81
|
# @example Registering for a button down event with a block of code to execute
|
82
82
|
#
|
83
83
|
# class ExampleScene
|
84
|
-
# event :on_down,
|
84
|
+
# event :on_down, GpLeft, GpUp do
|
85
85
|
# @selected_index = @selected_index - 1
|
86
86
|
# @selected_index = options.length - 1 if @selected_index <= -1
|
87
87
|
# end
|
data/lib/metro/models/draws.rb
CHANGED
@@ -18,11 +18,11 @@ module Metro
|
|
18
18
|
# @example Defining a title label within a scene
|
19
19
|
#
|
20
20
|
# class ExampleScene
|
21
|
-
# draw :title, text: Title Screen',
|
22
|
-
#
|
23
|
-
# position:
|
24
|
-
# scale:
|
25
|
-
# color:
|
21
|
+
# draw :title, text: 'Title Screen',
|
22
|
+
# model: 'metro::ui::label'
|
23
|
+
# position: '20,20,0',
|
24
|
+
# scale: '3,3',
|
25
|
+
# color: 'rgba(255,255,255,1.0)'
|
26
26
|
#
|
27
27
|
# def show
|
28
28
|
# puts "Where is my title? #{title.x},#{title.y}"
|
@@ -2,8 +2,8 @@ module Metro
|
|
2
2
|
class Model
|
3
3
|
|
4
4
|
#
|
5
|
-
#
|
6
|
-
# and some metadata.
|
5
|
+
# An animation property manages an Animation, which is an array of
|
6
|
+
# Gosu::Images and some metadata.
|
7
7
|
#
|
8
8
|
# @see Animation
|
9
9
|
#
|
@@ -75,7 +75,7 @@ module Metro
|
|
75
75
|
end
|
76
76
|
|
77
77
|
private
|
78
|
-
|
78
|
+
|
79
79
|
def create_animation(properties)
|
80
80
|
self.class.animation_for properties
|
81
81
|
end
|
@@ -20,13 +20,13 @@ module Metro
|
|
20
20
|
# @example Defining a dimensions providing a default
|
21
21
|
#
|
22
22
|
# class Hero < Metro::Model
|
23
|
-
# property :dimensions, default: Dimensions.of
|
23
|
+
# property :dimensions, default: Dimensions.of(100.0, 100.0)
|
24
24
|
# end
|
25
25
|
#
|
26
26
|
# @example Using a dimensions property with a different property name
|
27
27
|
#
|
28
28
|
# class Hero < Metro::Model
|
29
|
-
# property :box, type: dimensions, default: Dimensions.of
|
29
|
+
# property :box, type: dimensions, default: Dimensions.of(100.0, 100.0)
|
30
30
|
# # box_width, box_height
|
31
31
|
# end
|
32
32
|
#
|
@@ -2,58 +2,56 @@ module Metro
|
|
2
2
|
class Model
|
3
3
|
|
4
4
|
#
|
5
|
-
# A scale property maintains an x and y scaling factor.
|
5
|
+
# A scale property maintains an x and y scaling factor.
|
6
6
|
#
|
7
|
-
# A
|
8
|
-
# more direct interface. Changing these values will
|
7
|
+
# A scale property also defines a `x_factor` property and a `y_factor`
|
8
|
+
# property which allows a more direct interface. Changing these values will
|
9
|
+
# update the scale the next time that it is used.
|
9
10
|
#
|
10
|
-
# A
|
11
|
-
# a
|
12
|
-
# Property will attempt to use a font that already exists that meets that criteria.
|
11
|
+
# A scale is stored in the properties as a string representation and is
|
12
|
+
# converted into a Scale when it is retrieved within the system.
|
13
13
|
#
|
14
|
-
#
|
15
|
-
# creation of similar fonts.
|
16
|
-
#
|
17
|
-
# @example Defining a font property
|
14
|
+
# @example Defining a scale property
|
18
15
|
#
|
19
16
|
# class Scoreboard < Metro::Model
|
20
17
|
# property :font
|
18
|
+
# property :color
|
19
|
+
# property :scale
|
21
20
|
#
|
22
21
|
# def draw
|
23
|
-
#
|
22
|
+
# image.draw text, x, y, z_order, x_factor, y_factor, color
|
24
23
|
# end
|
25
24
|
#
|
26
25
|
# end
|
27
26
|
#
|
28
|
-
# @example Defining a
|
29
|
-
#
|
30
|
-
# class Hero < Metro::Model
|
31
|
-
# property :font, default: { name: 'Comic Sans', size: 80 }
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# @example Using the `font_size` and `font_name` properties
|
27
|
+
# @example Defining a scale property providing a default
|
35
28
|
#
|
36
29
|
# class Hero < Metro::Model
|
37
|
-
# property :
|
38
|
-
#
|
39
|
-
# def dignified
|
40
|
-
# self.font_size = 45
|
41
|
-
# self.font_name = 'Helvetica'
|
42
|
-
# end
|
30
|
+
# property :image, path: 'hero.jpg'
|
31
|
+
# property :scale, default: "1.0,1.0"
|
43
32
|
# end
|
44
33
|
#
|
45
|
-
# @example Using a
|
34
|
+
# @example Using a scale property with a different property name
|
46
35
|
#
|
47
36
|
# class Hero < Metro::Model
|
48
|
-
# property :
|
37
|
+
# property :image, path: 'hero.jpg'
|
38
|
+
# property :enraged_scale, type: :scale, default: "4.0,4.0"
|
39
|
+
# property :angle
|
40
|
+
# property :color
|
49
41
|
#
|
50
42
|
# def draw
|
51
|
-
#
|
52
|
-
#
|
43
|
+
# image.draw_rot x, y, z_order, angle.to_f, 0.5, 0.5,
|
44
|
+
# enraged_scale_factor_x, enraged_scale_factor_y, color
|
53
45
|
# end
|
54
46
|
# end
|
55
47
|
#
|
56
48
|
class ScaleProperty < Property
|
49
|
+
void drawRot(double x, double y, ZPos z,
|
50
|
+
double angle, double centerX = 0.5, double centerY = 0.5,
|
51
|
+
double factorX = 1, double factorY = 1,
|
52
|
+
Color c = Color::WHITE,
|
53
|
+
AlphaMode mode = amDefault) const;
|
54
|
+
|
57
55
|
|
58
56
|
define_property :x_factor
|
59
57
|
|
@@ -11,6 +11,10 @@ module Metro
|
|
11
11
|
# @example Defining a text property
|
12
12
|
#
|
13
13
|
# class Scoreboard < Metro::Model
|
14
|
+
# property :font
|
15
|
+
# property :position
|
16
|
+
# property :color
|
17
|
+
# property :scale
|
14
18
|
# property :text
|
15
19
|
#
|
16
20
|
# def draw
|
@@ -22,16 +26,21 @@ module Metro
|
|
22
26
|
# @example Defining with a default and text that will be instance evaluated.
|
23
27
|
#
|
24
28
|
# class ScoreBoard < Metro::Model
|
25
|
-
# property :
|
29
|
+
# property :score
|
30
|
+
# property :text, default: 'Score is #{score}'
|
26
31
|
# end
|
27
32
|
#
|
28
33
|
# @example Using a text property with a different property name
|
29
34
|
#
|
30
35
|
# class Hero < Metro::Model
|
36
|
+
# proeprty :font
|
37
|
+
# property :position
|
38
|
+
# property :color
|
39
|
+
# property :scale
|
31
40
|
# property :description, type: :text
|
32
41
|
#
|
33
42
|
# def draw
|
34
|
-
#
|
43
|
+
# font.draw description, x, y, z_order, x_factor, y_factor, color
|
35
44
|
# end
|
36
45
|
# end
|
37
46
|
#
|
data/lib/metro/scene.rb
CHANGED
@@ -61,8 +61,8 @@ module Metro
|
|
61
61
|
def draw ; end
|
62
62
|
|
63
63
|
#
|
64
|
-
# Before a scene is
|
65
|
-
# to allow for the scene to complete any
|
64
|
+
# Before a scene is transitioned away from to a new scene, this method is called
|
65
|
+
# to allow for the scene to complete any tasks, stop any actions, or pass any
|
66
66
|
# information from the existing scene to the scene that is about to replace it.
|
67
67
|
#
|
68
68
|
# @note This method should be implemented in the Scene subclass.
|
@@ -73,8 +73,8 @@ module Metro
|
|
73
73
|
def prepare_transition_to(new_scene) ; end
|
74
74
|
|
75
75
|
#
|
76
|
-
# Before a scene is
|
77
|
-
# allows for the new scene to
|
76
|
+
# Before a scene is transitioned to it is called with the previous scene. This
|
77
|
+
# allows for the new scene to retrieve any data from the previous scene to assist
|
78
78
|
# with the layout of the current scene.
|
79
79
|
#
|
80
80
|
# @note This method should be implemented in the Scene subclass.
|
data/lib/metro/version.rb
CHANGED
data/lib/metro/views/no_view.rb
CHANGED
@@ -7,7 +7,7 @@ module Metro
|
|
7
7
|
# A NoView is a last resort view which means this is will always will exist.
|
8
8
|
#
|
9
9
|
# @param [String] view_path the name of the view to find
|
10
|
-
# @return a true
|
10
|
+
# @return a true all the time as this is the last resort format.
|
11
11
|
#
|
12
12
|
def self.exists?(view_path)
|
13
13
|
true
|
data/lib/metro/views/parsers.rb
CHANGED
@@ -8,18 +8,34 @@ module Metro
|
|
8
8
|
module Parsers
|
9
9
|
extend self
|
10
10
|
|
11
|
+
#
|
12
|
+
# Register a view parser.
|
13
|
+
#
|
14
|
+
# A parser is any class or instance that responds to #exists?(view_path),
|
15
|
+
# #parse(view_path) and #format.
|
16
|
+
#
|
17
|
+
# @param [Parser] parser the parser to add to the list of available parsers.
|
18
|
+
#
|
11
19
|
def register(parser)
|
12
20
|
parsers.push parser
|
13
21
|
end
|
14
22
|
|
23
|
+
#
|
24
|
+
# @return [Array<Parsers>] an array of all the registered view parsers. The
|
25
|
+
# last parser is the NoView parser.
|
26
|
+
#
|
15
27
|
def parsers
|
16
28
|
@parsers ||= []
|
17
29
|
end
|
30
|
+
|
31
|
+
def parsers_with_no_view_fallback
|
32
|
+
parsers + [ NoView ]
|
33
|
+
end
|
34
|
+
|
18
35
|
end
|
19
36
|
|
20
37
|
Parsers.register YAMLView
|
21
38
|
Parsers.register JSONView
|
22
|
-
Parsers.register NoView
|
23
39
|
|
24
40
|
end
|
25
41
|
end
|
data/lib/metro/views/view.rb
CHANGED
data/lib/metro/views/writers.rb
CHANGED
@@ -7,14 +7,29 @@ module Metro
|
|
7
7
|
module Writers
|
8
8
|
extend self
|
9
9
|
|
10
|
+
#
|
11
|
+
# Register a view writer
|
12
|
+
#
|
13
|
+
# A writer is any class or instance that responds to #write(view_path,content),
|
14
|
+
# and #format.
|
15
|
+
#
|
16
|
+
# @param [Writer] writer the writer to add to the list of available writers..
|
17
|
+
#
|
10
18
|
def register(writer)
|
11
19
|
writers.push writer
|
12
20
|
end
|
13
21
|
|
22
|
+
#
|
23
|
+
# @return [Array<Writers>] an array of all the registered view writers.
|
24
|
+
#
|
14
25
|
def writers
|
15
26
|
@writers ||= []
|
16
27
|
end
|
17
28
|
|
29
|
+
#
|
30
|
+
# The default view writer, this is the one that will be used if no view
|
31
|
+
# can be found by the writers.
|
32
|
+
#
|
18
33
|
attr_accessor :default_writer
|
19
34
|
|
20
35
|
end
|
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.
|
4
|
+
version: 0.3.0
|
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-11-
|
12
|
+
date: 2012-11-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gosu
|
@@ -250,10 +250,11 @@ licenses: []
|
|
250
250
|
post_install_message: ! " ______ ___ _____\n ___ |/ /_____ __ /_______________\n
|
251
251
|
\ __ /|_/ / _ _ \\_ __/__ ___/_ __ \\\n _ / / / / __// /_ _ / /
|
252
252
|
/_/ /\n /_/ /_/ \\___/ \\__/ /_/ \\____/\n\n Thank you for installing
|
253
|
-
metro 0.
|
254
|
-
\ Changes:\n \n * FIX
|
255
|
-
|
256
|
-
|
253
|
+
metro 0.3.0 / 2012-11-25.\n ---------------------------------------------------------------------\n
|
254
|
+
\ Changes:\n \n * FIX lots of typos in the documentation\n * Removed `up_action_missing`
|
255
|
+
and `down_ation_missing` event handling\n * Notification events now have block
|
256
|
+
support for 0, 1 and 2 parameters\n * FIX Registration of custom defined custom
|
257
|
+
view parsers\n * FIX Grid Layer layout for Edit Mode\n \n \n\n ---------------------------------------------------------------------\n"
|
257
258
|
rdoc_options: []
|
258
259
|
require_paths:
|
259
260
|
- lib
|