metro 0.1.5 → 0.1.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/README.md +19 -0
- data/changelog.md +8 -0
- data/lib/assets/missing_animation.png +0 -0
- data/lib/commands/generate_model.rb +2 -2
- data/lib/commands/generate_scene.rb +12 -2
- data/lib/commands/generate_view.rb +1 -1
- data/lib/gosu_ext/color.rb +1 -1
- data/lib/gosu_ext/image.rb +5 -0
- data/lib/metro.rb +18 -5
- data/lib/metro/animation/animation.rb +31 -0
- data/lib/metro/asset_path.rb +9 -0
- data/lib/metro/events/event_dictionary.rb +53 -0
- data/lib/metro/events/event_factory.rb +5 -3
- data/lib/metro/events/has_events.rb +5 -6
- data/lib/metro/game.rb +1 -1
- data/lib/metro/models/dimensions.rb +21 -0
- data/lib/metro/models/model.rb +149 -52
- data/lib/metro/models/model_factory.rb +4 -5
- data/lib/metro/models/{generic.rb → models/generic.rb} +0 -0
- data/lib/metro/models/{grid_drawer.rb → models/grid_drawer.rb} +4 -9
- data/lib/metro/models/{image.rb → models/image.rb} +11 -14
- data/lib/metro/models/models/label.rb +44 -0
- data/lib/metro/models/{menu.rb → models/menu.rb} +23 -18
- data/lib/metro/models/{rectangle.rb → models/rectangle.rb} +6 -5
- data/lib/metro/models/point.rb +23 -0
- data/lib/metro/models/properties/angle.rb +43 -0
- data/lib/metro/models/properties/animation.rb +143 -0
- data/lib/metro/models/properties/color.rb +113 -0
- data/lib/metro/models/properties/dimensions.rb +66 -0
- data/lib/metro/models/properties/font.rb +155 -0
- data/lib/metro/models/properties/image.rb +101 -0
- data/lib/metro/models/properties/numeric.rb +29 -0
- data/lib/metro/models/properties/position.rb +84 -0
- data/lib/metro/models/properties/property.rb +111 -0
- data/lib/metro/models/properties/scale.rb +89 -0
- data/lib/metro/models/properties/text.rb +66 -0
- data/lib/metro/models/properties/velocity.rb +80 -0
- data/lib/metro/models/scale.rb +21 -0
- data/lib/metro/scene.rb +19 -1
- data/lib/metro/scenes.rb +91 -31
- data/lib/metro/transitions/scene_transitions.rb +8 -0
- data/lib/metro/version.rb +1 -1
- data/lib/metro/views/view.rb +9 -1
- data/lib/templates/game/metro.tt +1 -1
- data/lib/templates/game/models/game_model.rb +3 -0
- data/lib/templates/game/scenes/brand_scene.rb +1 -1
- data/lib/templates/game/scenes/brand_to_title_scene.rb +1 -1
- data/lib/templates/game/scenes/game_scene.rb +19 -0
- data/lib/templates/game/scenes/title_scene.rb +1 -1
- data/lib/templates/game/views/brand_to_title.yaml +2 -2
- data/lib/templates/game/views/title.yaml +3 -3
- data/lib/templates/{model.rb.erb → model.rb.tt} +1 -1
- data/lib/templates/{scene.rb.erb → scene.rb.tt} +1 -1
- data/lib/templates/view.yaml.tt +6 -0
- data/spec/metro/models/models/label_spec.rb +110 -0
- data/spec/metro/models/properties/color_spec.rb +85 -0
- data/spec/metro/models/properties/font_spec.rb +129 -0
- data/spec/metro/models/properties/numeric_property_spec.rb +46 -0
- data/spec/metro/models/properties/position_property_spec.rb +90 -0
- data/spec/metro/scenes_spec.rb +77 -0
- metadata +50 -16
- data/lib/metro/models/label.rb +0 -63
- data/lib/templates/view.yaml.erb +0 -32
@@ -33,4 +33,12 @@ module Metro
|
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# The Scene Transition should act as a filter and allow for
|
39
|
+
# common or custom scenes to be inserted between the scene
|
40
|
+
# that was about to be displayed.
|
41
|
+
#
|
42
|
+
Scenes.register_post_filter SceneTransitions
|
43
|
+
|
36
44
|
end
|
data/lib/metro/version.rb
CHANGED
data/lib/metro/views/view.rb
CHANGED
@@ -26,7 +26,15 @@ module Metro
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
#
|
30
|
+
# Set the content of the view.
|
31
|
+
#
|
32
|
+
# @param [Hash] value the hash content that will represent this view
|
33
|
+
#
|
34
|
+
def content=(value)
|
35
|
+
value.default = {}
|
36
|
+
@content = value
|
37
|
+
end
|
30
38
|
|
31
39
|
#
|
32
40
|
# A Scene view path is based on the view name.
|
data/lib/templates/game/metro.tt
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
class GameScene < Metro::Scene
|
2
|
+
|
3
|
+
#
|
4
|
+
# The game scene is a place where you can define actors and
|
5
|
+
# events here that will be present within all the subclassed
|
6
|
+
# scenes.
|
7
|
+
|
8
|
+
#
|
9
|
+
# @example Setting up the ability for all subclassed scenes
|
10
|
+
# to be reloaded with the 'Ctrl+R' event
|
11
|
+
#
|
12
|
+
event :on_up, KbR do |event|
|
13
|
+
if event.control?
|
14
|
+
Metro.reload!
|
15
|
+
transition_to self.class.scene_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
title:
|
2
2
|
model: metro::models::label
|
3
|
-
text: "#{
|
4
|
-
|
3
|
+
text: "#{Game.name}"
|
4
|
+
font_size: 40
|
5
5
|
y: 100
|
6
6
|
color: rgba(255,255,255,1.0)
|
7
7
|
menu:
|
@@ -9,4 +9,4 @@ menu:
|
|
9
9
|
x: 260
|
10
10
|
y: 200
|
11
11
|
color: rgb(127,127,127)
|
12
|
-
highlight-color: rgb(255,255,255)
|
12
|
+
highlight-color: rgb(255,255,255)
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Models::Label do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
label = described_class.new
|
7
|
+
label.window = mock('window')
|
8
|
+
label
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
# Reset the position of the label to the default
|
13
|
+
subject.position = nil
|
14
|
+
subject.scale = Metro::Scale.one
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:expected_position) { Metro::Point.zero }
|
18
|
+
its(:position) { should eq expected_position }
|
19
|
+
|
20
|
+
its(:x) { should eq expected_position.x }
|
21
|
+
its(:y) { should eq expected_position.y }
|
22
|
+
its(:z) { should eq expected_position.z }
|
23
|
+
its(:z_order) { should eq expected_position.z_order }
|
24
|
+
|
25
|
+
context "when setting the position" do
|
26
|
+
|
27
|
+
it "should be set succesfully" do
|
28
|
+
subject.position = "10,10"
|
29
|
+
subject.position.should eq Metro::Point.at(10,10)
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when setting the x property" do
|
33
|
+
let(:expected_x) { 11 }
|
34
|
+
let(:expected_y) { 0 }
|
35
|
+
|
36
|
+
it "should update successfully" do
|
37
|
+
subject.x = expected_x
|
38
|
+
subject.x.should eq expected_x
|
39
|
+
subject.position.x.should eq expected_x
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not effect the paired y property" do
|
43
|
+
subject.x = expected_x
|
44
|
+
subject.y.should eq expected_y
|
45
|
+
subject.position.y.should eq expected_y
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when setting the y property" do
|
50
|
+
before do
|
51
|
+
subject.position = "#{expected_x},#{expected_y}"
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:expected_x) { 320 }
|
55
|
+
let(:expected_y) { 66 }
|
56
|
+
|
57
|
+
it "should update successfully" do
|
58
|
+
subject.y = expected_y
|
59
|
+
subject.y.should eq expected_y
|
60
|
+
subject.position.y.should eq expected_y
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should not effect the paired x property" do
|
64
|
+
subject.y = expected_y
|
65
|
+
subject.x.should eq expected_x
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
let(:expected_color) { Gosu::Color.new "rgb(255,255,255)" }
|
72
|
+
let(:expected_alpha) { 255 }
|
73
|
+
|
74
|
+
its(:color) { should eq expected_color }
|
75
|
+
its(:alpha) { should eq expected_alpha }
|
76
|
+
|
77
|
+
|
78
|
+
describe "font" do
|
79
|
+
before do
|
80
|
+
Metro::Model::FontProperty.stub(:create_font).and_return(font)
|
81
|
+
end
|
82
|
+
|
83
|
+
let(:font) { mock('font', name: expected_font_name, size: expected_font_size) }
|
84
|
+
|
85
|
+
let(:expected_font) { font }
|
86
|
+
its(:font) { should eq expected_font }
|
87
|
+
|
88
|
+
let(:expected_font_name) { 'mock_font_name' }
|
89
|
+
its(:font_name) { should eq expected_font_name }
|
90
|
+
|
91
|
+
let(:expected_font_size) { 12.0 }
|
92
|
+
its(:font_size) { should eq expected_font_size }
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
let(:expected_scale) { Metro::Scale.one }
|
97
|
+
|
98
|
+
its(:scale) { should eq expected_scale }
|
99
|
+
its(:x_factor) { should eq expected_scale.x_factor }
|
100
|
+
its(:y_factor) { should eq expected_scale.y_factor }
|
101
|
+
|
102
|
+
context "when setting the scale" do
|
103
|
+
it "should set" do
|
104
|
+
subject.x_factor = 2.0
|
105
|
+
# subject.x_factor.should eq 2.0
|
106
|
+
subject.scale.x_factor.should eq 2.0
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Model::ColorProperty do
|
4
|
+
|
5
|
+
subject { described_class.new model }
|
6
|
+
let(:model) { mock("model", window: window) }
|
7
|
+
let(:window) { mock('window') }
|
8
|
+
|
9
|
+
describe "#get" do
|
10
|
+
let(:expected_color) { mock('color') }
|
11
|
+
|
12
|
+
context "when the value is nil" do
|
13
|
+
context "when no default value has been specified" do
|
14
|
+
let(:default_color_string) { "rgba(255,255,255,1.0)" }
|
15
|
+
|
16
|
+
|
17
|
+
it "should return the default value" do
|
18
|
+
subject.stub(:create_color).with(default_color_string) { expected_color }
|
19
|
+
subject.get(nil).should eq expected_color
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when a default value has been specified" do
|
24
|
+
subject do
|
25
|
+
described_class.new model, default: expected_color_string
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:expected_color_string) { "rgba(255,255,127,0.5)" }
|
29
|
+
|
30
|
+
it "should return the specified default value" do
|
31
|
+
subject.stub(:create_color).with(expected_color_string) { expected_color }
|
32
|
+
subject.get(nil).should eq expected_color
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when the value is a string" do
|
38
|
+
|
39
|
+
let(:color_string) { "#666666" }
|
40
|
+
|
41
|
+
it "should return the color" do
|
42
|
+
subject.stub(:create_color).with(color_string) { expected_color }
|
43
|
+
subject.get(color_string).should eq expected_color
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#set" do
|
50
|
+
let(:expected_color) { mock('color') }
|
51
|
+
|
52
|
+
context "when the value is nil" do
|
53
|
+
|
54
|
+
context "when no default value has been specified" do
|
55
|
+
let(:expected_color_string) { "rgba(255,255,255,1.0)" }
|
56
|
+
|
57
|
+
it "should return a string representation of the default color" do
|
58
|
+
subject.set(nil).should eq expected_color_string
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when a default value has been specified" do
|
63
|
+
subject do
|
64
|
+
described_class.new model, default: expected_color_string
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:expected_color_string) { "rgba(0,127,11,0.4)" }
|
68
|
+
|
69
|
+
it "should return a string representation of the specified default color" do
|
70
|
+
subject.set(nil).should eq expected_color_string
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when the value is a color" do
|
76
|
+
let(:color) { Gosu::Color.new expected_color_string }
|
77
|
+
let(:expected_color_string) { "rgba(45,12,12,1.0)" }
|
78
|
+
|
79
|
+
it "should return a string representation of the color" do
|
80
|
+
subject.set(color).should eq expected_color_string
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Model::FontProperty do
|
4
|
+
|
5
|
+
subject { described_class.new model }
|
6
|
+
let(:model) { mock("model", window: window) }
|
7
|
+
let(:window) { mock('window') }
|
8
|
+
|
9
|
+
describe "#get" do
|
10
|
+
context "when the value is nil" do
|
11
|
+
context "when no default value has been specified" do
|
12
|
+
let(:expected_font_name) { Gosu::default_font_name }
|
13
|
+
let(:expected_font_size) { 40 }
|
14
|
+
let(:expected_font) { stub('font') }
|
15
|
+
|
16
|
+
it "should return the default value" do
|
17
|
+
described_class.stub(:create_font).with(window,expected_font_name,expected_font_size) { expected_font }
|
18
|
+
subject.get(nil).should eq expected_font
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when a default value has been specified" do
|
23
|
+
subject do
|
24
|
+
described_class.new model, default: { name: expected_font_name, size: expected_font_size }
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:expected_font_name) { 'Times New Roman' }
|
28
|
+
let(:expected_font_size) { 60 }
|
29
|
+
let(:expected_font) { stub('font') }
|
30
|
+
|
31
|
+
it "should return the specified default value" do
|
32
|
+
described_class.stub(:create_font).with(window,expected_font_name,expected_font_size) { expected_font }
|
33
|
+
subject.get(nil).should eq expected_font
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when the value is a hash" do
|
39
|
+
let(:expected_font_name) { 'Helvetica' }
|
40
|
+
let(:expected_font_size) { 80 }
|
41
|
+
let(:expected_font) { stub('font') }
|
42
|
+
|
43
|
+
let(:font_hash) { { name: expected_font_name, size: expected_font_size } }
|
44
|
+
|
45
|
+
|
46
|
+
it "should return the font value" do
|
47
|
+
described_class.stub(:create_font).with(window,expected_font_name,expected_font_size) { expected_font }
|
48
|
+
subject.get(font_hash).should eq expected_font
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when the same font is requested" do
|
53
|
+
let(:expected_font_name) { Gosu::default_font_name }
|
54
|
+
let(:expected_font_size) { 40 }
|
55
|
+
let(:expected_font) { stub('font') }
|
56
|
+
|
57
|
+
it "should not be created a second time (pullled from memory)" do
|
58
|
+
described_class.should_receive(:create_font).once.and_return(expected_font)
|
59
|
+
subject.get(nil)
|
60
|
+
subject.get(nil)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#set" do
|
68
|
+
context "when the value is nil" do
|
69
|
+
context "when no default value has been specified" do
|
70
|
+
let(:expected_font_name) { Gosu::default_font_name }
|
71
|
+
let(:expected_font_size) { 40 }
|
72
|
+
let(:expected_font) { stub('font') }
|
73
|
+
|
74
|
+
let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
|
75
|
+
|
76
|
+
|
77
|
+
it "should return a hash of the default value" do
|
78
|
+
described_class.stub(:create_font).with(window,expected_font_name,expected_font_size) { expected_font }
|
79
|
+
subject.set(nil).should eq expected_result
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when a default value has been specified" do
|
84
|
+
subject do
|
85
|
+
described_class.new model, default: { name: expected_font_name, size: expected_font_size }
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:expected_font_name) { 'Times New Roman' }
|
89
|
+
let(:expected_font_size) { 60 }
|
90
|
+
|
91
|
+
let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
|
92
|
+
|
93
|
+
it "should return the specified default value" do
|
94
|
+
subject.set(nil).should eq expected_result
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when the value is a font" do
|
100
|
+
|
101
|
+
let(:gosu_font) do
|
102
|
+
font = stub('font', name: expected_font_name, height: expected_font_size)
|
103
|
+
font.stub(:class) { Gosu::Font }
|
104
|
+
font
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:expected_font_name) { 'Comic Sans' }
|
108
|
+
let(:expected_font_size) { 45 }
|
109
|
+
|
110
|
+
let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
|
111
|
+
|
112
|
+
it "should return a hash of the font" do
|
113
|
+
subject.set(gosu_font).should eq expected_result
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "when the value is a hash" do
|
118
|
+
|
119
|
+
let(:expected_font_name) { 'Wingdings' }
|
120
|
+
let(:expected_font_size) { 33 }
|
121
|
+
let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
|
122
|
+
|
123
|
+
it "should return the hash representation of the font" do
|
124
|
+
subject.set(expected_result).should eq expected_result
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|