metro 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/README.md +19 -0
  2. data/changelog.md +8 -0
  3. data/lib/assets/missing_animation.png +0 -0
  4. data/lib/commands/generate_model.rb +2 -2
  5. data/lib/commands/generate_scene.rb +12 -2
  6. data/lib/commands/generate_view.rb +1 -1
  7. data/lib/gosu_ext/color.rb +1 -1
  8. data/lib/gosu_ext/image.rb +5 -0
  9. data/lib/metro.rb +18 -5
  10. data/lib/metro/animation/animation.rb +31 -0
  11. data/lib/metro/asset_path.rb +9 -0
  12. data/lib/metro/events/event_dictionary.rb +53 -0
  13. data/lib/metro/events/event_factory.rb +5 -3
  14. data/lib/metro/events/has_events.rb +5 -6
  15. data/lib/metro/game.rb +1 -1
  16. data/lib/metro/models/dimensions.rb +21 -0
  17. data/lib/metro/models/model.rb +149 -52
  18. data/lib/metro/models/model_factory.rb +4 -5
  19. data/lib/metro/models/{generic.rb → models/generic.rb} +0 -0
  20. data/lib/metro/models/{grid_drawer.rb → models/grid_drawer.rb} +4 -9
  21. data/lib/metro/models/{image.rb → models/image.rb} +11 -14
  22. data/lib/metro/models/models/label.rb +44 -0
  23. data/lib/metro/models/{menu.rb → models/menu.rb} +23 -18
  24. data/lib/metro/models/{rectangle.rb → models/rectangle.rb} +6 -5
  25. data/lib/metro/models/point.rb +23 -0
  26. data/lib/metro/models/properties/angle.rb +43 -0
  27. data/lib/metro/models/properties/animation.rb +143 -0
  28. data/lib/metro/models/properties/color.rb +113 -0
  29. data/lib/metro/models/properties/dimensions.rb +66 -0
  30. data/lib/metro/models/properties/font.rb +155 -0
  31. data/lib/metro/models/properties/image.rb +101 -0
  32. data/lib/metro/models/properties/numeric.rb +29 -0
  33. data/lib/metro/models/properties/position.rb +84 -0
  34. data/lib/metro/models/properties/property.rb +111 -0
  35. data/lib/metro/models/properties/scale.rb +89 -0
  36. data/lib/metro/models/properties/text.rb +66 -0
  37. data/lib/metro/models/properties/velocity.rb +80 -0
  38. data/lib/metro/models/scale.rb +21 -0
  39. data/lib/metro/scene.rb +19 -1
  40. data/lib/metro/scenes.rb +91 -31
  41. data/lib/metro/transitions/scene_transitions.rb +8 -0
  42. data/lib/metro/version.rb +1 -1
  43. data/lib/metro/views/view.rb +9 -1
  44. data/lib/templates/game/metro.tt +1 -1
  45. data/lib/templates/game/models/game_model.rb +3 -0
  46. data/lib/templates/game/scenes/brand_scene.rb +1 -1
  47. data/lib/templates/game/scenes/brand_to_title_scene.rb +1 -1
  48. data/lib/templates/game/scenes/game_scene.rb +19 -0
  49. data/lib/templates/game/scenes/title_scene.rb +1 -1
  50. data/lib/templates/game/views/brand_to_title.yaml +2 -2
  51. data/lib/templates/game/views/title.yaml +3 -3
  52. data/lib/templates/{model.rb.erb → model.rb.tt} +1 -1
  53. data/lib/templates/{scene.rb.erb → scene.rb.tt} +1 -1
  54. data/lib/templates/view.yaml.tt +6 -0
  55. data/spec/metro/models/models/label_spec.rb +110 -0
  56. data/spec/metro/models/properties/color_spec.rb +85 -0
  57. data/spec/metro/models/properties/font_spec.rb +129 -0
  58. data/spec/metro/models/properties/numeric_property_spec.rb +46 -0
  59. data/spec/metro/models/properties/position_property_spec.rb +90 -0
  60. data/spec/metro/scenes_spec.rb +77 -0
  61. metadata +50 -16
  62. data/lib/metro/models/label.rb +0 -63
  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
@@ -1,5 +1,5 @@
1
1
  module Metro
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  WEBSITE = "https://github.com/burtlo/metro"
4
4
  CONTACT_EMAILS = ["franklin.webber@gmail.com"]
5
5
 
@@ -26,7 +26,15 @@ module Metro
26
26
  end
27
27
  end
28
28
 
29
- attr_writer :content
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.
@@ -58,7 +58,7 @@ end
58
58
  #
59
59
  # Enable debug mode for the game. Which could
60
60
  # allow different logic. When this is set the
61
- # Metro::Game.debug? method will return a true
61
+ # Game.debug? method will return a true
62
62
  # value.
63
63
  #
64
64
  # debug true
@@ -0,0 +1,3 @@
1
+ class GameModel < Metro::Model
2
+
3
+ end
@@ -1,4 +1,4 @@
1
- class BrandScene < Metro::Scene
1
+ class BrandScene < GameScene
2
2
 
3
3
  draws :brand
4
4
 
@@ -1,4 +1,4 @@
1
- class BrandToTitleScene < Metro::Scene
1
+ class BrandToTitleScene < GameScene
2
2
 
3
3
  draws :title
4
4
 
@@ -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,4 +1,4 @@
1
- class TitleScene < Metro::Scene
1
+ class TitleScene < GameScene
2
2
 
3
3
  draw :title
4
4
 
@@ -1,7 +1,7 @@
1
1
  title:
2
2
  model: metro::models::label
3
- text: "#{Metro::Game.name}"
4
- size: 40
3
+ text: "#{Game.name}"
4
+ font_size: 40
5
5
  y: 100
6
6
  color: rgba(255,255,255,0.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  title:
2
2
  model: metro::models::label
3
- text: "#{Metro::Game.name}"
4
- size: 40
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)
@@ -1,4 +1,4 @@
1
- class <%= model_name %> < Metro::Model
1
+ class <%= model_name %> < GameModel
2
2
 
3
3
  #
4
4
  # Example Event Handling Definitions
@@ -1,4 +1,4 @@
1
- class <%= scene_class_name %> < Metro::Scene
1
+ class <%= scene_class_name %> < GameScene
2
2
  # By default the Scene Name is based on the class name
3
3
  # but that can be overriden with the scene_name class method
4
4
  # scene_name "credits"
@@ -0,0 +1,6 @@
1
+ # title:
2
+ # model: metro::models::label
3
+ # x: 30
4
+ # y: 50
5
+ # z-order: 4
6
+ # color: "rgba(255,255,0,0.0)"
@@ -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