metro-ld25 0.3.3

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.
Files changed (177) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +2 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +12 -0
  6. data/Guardfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +189 -0
  9. data/Rakefile +18 -0
  10. data/bin/metro +16 -0
  11. data/changelog.md +157 -0
  12. data/lib/assets/menu-movement.wav +0 -0
  13. data/lib/assets/menu-selection.wav +0 -0
  14. data/lib/assets/missing.ogg +0 -0
  15. data/lib/assets/missing.png +0 -0
  16. data/lib/assets/missing.wav +0 -0
  17. data/lib/assets/missing_animation.png +0 -0
  18. data/lib/commands/generate_game.rb +13 -0
  19. data/lib/commands/generate_model.rb +25 -0
  20. data/lib/commands/generate_scene.rb +36 -0
  21. data/lib/commands/generate_view.rb +21 -0
  22. data/lib/commands/thor.rb +83 -0
  23. data/lib/core_ext/class.rb +14 -0
  24. data/lib/core_ext/numeric.rb +59 -0
  25. data/lib/gosu_ext/color.rb +62 -0
  26. data/lib/gosu_ext/gosu_constants.rb +53 -0
  27. data/lib/locale/en.yml +35 -0
  28. data/lib/locale/locale.rb +1 -0
  29. data/lib/metro.rb +140 -0
  30. data/lib/metro/animation.rb +135 -0
  31. data/lib/metro/animation/after_interval_factory.rb +12 -0
  32. data/lib/metro/animation/animation_factory.rb +15 -0
  33. data/lib/metro/animation/easing/ease_in.rb +15 -0
  34. data/lib/metro/animation/easing/easing.rb +51 -0
  35. data/lib/metro/animation/easing/linear.rb +15 -0
  36. data/lib/metro/animation/has_animations.rb +70 -0
  37. data/lib/metro/animation/implicit_animation.rb +100 -0
  38. data/lib/metro/animation/on_update_operation.rb +96 -0
  39. data/lib/metro/animation/scene_animation.rb +16 -0
  40. data/lib/metro/asset_path.rb +97 -0
  41. data/lib/metro/events/control_definition.rb +11 -0
  42. data/lib/metro/events/controls.rb +42 -0
  43. data/lib/metro/events/event_data.rb +60 -0
  44. data/lib/metro/events/event_dictionary.rb +52 -0
  45. data/lib/metro/events/event_factory.rb +17 -0
  46. data/lib/metro/events/event_relay.rb +300 -0
  47. data/lib/metro/events/event_state_manager.rb +63 -0
  48. data/lib/metro/events/events.rb +3 -0
  49. data/lib/metro/events/has_events.rb +108 -0
  50. data/lib/metro/events/hit_list.rb +75 -0
  51. data/lib/metro/events/unknown_sender.rb +5 -0
  52. data/lib/metro/font.rb +69 -0
  53. data/lib/metro/game.rb +102 -0
  54. data/lib/metro/game/dsl.rb +68 -0
  55. data/lib/metro/image.rb +68 -0
  56. data/lib/metro/logging.rb +33 -0
  57. data/lib/metro/missing_scene.rb +21 -0
  58. data/lib/metro/models/audio/song.rb +33 -0
  59. data/lib/metro/models/draws.rb +86 -0
  60. data/lib/metro/models/key_value_coding.rb +38 -0
  61. data/lib/metro/models/model.rb +236 -0
  62. data/lib/metro/models/model_factory.rb +32 -0
  63. data/lib/metro/models/models.rb +62 -0
  64. data/lib/metro/models/properties/animation_property.rb +115 -0
  65. data/lib/metro/models/properties/array_property.rb +24 -0
  66. data/lib/metro/models/properties/boolean_property.rb +27 -0
  67. data/lib/metro/models/properties/color_property.rb +116 -0
  68. data/lib/metro/models/properties/dimensions_property.rb +84 -0
  69. data/lib/metro/models/properties/font_property.rb +130 -0
  70. data/lib/metro/models/properties/image_property.rb +96 -0
  71. data/lib/metro/models/properties/model_property.rb +84 -0
  72. data/lib/metro/models/properties/numeric_property.rb +29 -0
  73. data/lib/metro/models/properties/options_property/no_option.rb +29 -0
  74. data/lib/metro/models/properties/options_property/options.rb +94 -0
  75. data/lib/metro/models/properties/options_property/options_property.rb +125 -0
  76. data/lib/metro/models/properties/position_property.rb +90 -0
  77. data/lib/metro/models/properties/property.rb +221 -0
  78. data/lib/metro/models/properties/property_owner.rb +137 -0
  79. data/lib/metro/models/properties/sample_property.rb +84 -0
  80. data/lib/metro/models/properties/scale_property.rb +80 -0
  81. data/lib/metro/models/properties/song_property.rb +89 -0
  82. data/lib/metro/models/properties/text_property.rb +75 -0
  83. data/lib/metro/models/ui/animated_sprite.rb +85 -0
  84. data/lib/metro/models/ui/border.rb +95 -0
  85. data/lib/metro/models/ui/fps.rb +54 -0
  86. data/lib/metro/models/ui/generic.rb +66 -0
  87. data/lib/metro/models/ui/grid_drawer.rb +74 -0
  88. data/lib/metro/models/ui/image.rb +87 -0
  89. data/lib/metro/models/ui/label.rb +175 -0
  90. data/lib/metro/models/ui/menu.rb +214 -0
  91. data/lib/metro/models/ui/model_label.rb +65 -0
  92. data/lib/metro/models/ui/model_labeler.rb +79 -0
  93. data/lib/metro/models/ui/rectangle.rb +59 -0
  94. data/lib/metro/models/ui/sprite.rb +79 -0
  95. data/lib/metro/models/ui/tile_map.rb +162 -0
  96. data/lib/metro/models/ui/ui.rb +13 -0
  97. data/lib/metro/parameters/command_line_args_parser.rb +68 -0
  98. data/lib/metro/parameters/options.rb +25 -0
  99. data/lib/metro/parameters/parameters.rb +2 -0
  100. data/lib/metro/sample.rb +40 -0
  101. data/lib/metro/scene.rb +477 -0
  102. data/lib/metro/scenes.rb +154 -0
  103. data/lib/metro/song.rb +56 -0
  104. data/lib/metro/template_message.rb +60 -0
  105. data/lib/metro/transitions/edit_transition_scene.rb +100 -0
  106. data/lib/metro/transitions/fade_transition_scene.rb +66 -0
  107. data/lib/metro/transitions/scene_transitions.rb +44 -0
  108. data/lib/metro/transitions/transition_scene.rb +19 -0
  109. data/lib/metro/units/bounds.rb +8 -0
  110. data/lib/metro/units/calculation_validations.rb +74 -0
  111. data/lib/metro/units/dimensions.rb +60 -0
  112. data/lib/metro/units/point.rb +51 -0
  113. data/lib/metro/units/rectangle_bounds.rb +85 -0
  114. data/lib/metro/units/scale.rb +46 -0
  115. data/lib/metro/units/units.rb +6 -0
  116. data/lib/metro/version.rb +32 -0
  117. data/lib/metro/views/json_view.rb +60 -0
  118. data/lib/metro/views/no_view.rb +34 -0
  119. data/lib/metro/views/parsers.rb +42 -0
  120. data/lib/metro/views/scene_view.rb +107 -0
  121. data/lib/metro/views/view.rb +133 -0
  122. data/lib/metro/views/writers.rb +43 -0
  123. data/lib/metro/views/yaml_view.rb +94 -0
  124. data/lib/metro/window.rb +94 -0
  125. data/lib/setup_handlers/exit_if_dry_run.rb +26 -0
  126. data/lib/setup_handlers/game_execution.rb +65 -0
  127. data/lib/setup_handlers/load_game_configuration.rb +65 -0
  128. data/lib/setup_handlers/load_game_files.rb +101 -0
  129. data/lib/setup_handlers/move_to_game_directory.rb +25 -0
  130. data/lib/setup_handlers/reload_game_on_game_file_changes.rb +79 -0
  131. data/lib/templates/game/README.md.tt +52 -0
  132. data/lib/templates/game/assets/brand.jpg +0 -0
  133. data/lib/templates/game/assets/hero.png +0 -0
  134. data/lib/templates/game/lib/custom_easing.rb +32 -0
  135. data/lib/templates/game/metro.tt +63 -0
  136. data/lib/templates/game/models/hero.rb +62 -0
  137. data/lib/templates/game/scenes/brand_scene.rb +19 -0
  138. data/lib/templates/game/scenes/brand_to_title_scene.rb +13 -0
  139. data/lib/templates/game/scenes/first_scene.rb +28 -0
  140. data/lib/templates/game/scenes/game_scene.rb +43 -0
  141. data/lib/templates/game/scenes/title_scene.rb +15 -0
  142. data/lib/templates/game/views/brand.yaml +4 -0
  143. data/lib/templates/game/views/brand_to_title.yaml +8 -0
  144. data/lib/templates/game/views/first.yaml +26 -0
  145. data/lib/templates/game/views/title.yaml +11 -0
  146. data/lib/templates/message.erb +23 -0
  147. data/lib/templates/model.rb.tt +111 -0
  148. data/lib/templates/scene.rb.tt +140 -0
  149. data/lib/templates/view.yaml.tt +11 -0
  150. data/lib/tmxed_ext/tile_set.rb +34 -0
  151. data/metro.gemspec +56 -0
  152. data/spec/core_ext/numeric_spec.rb +78 -0
  153. data/spec/core_ext/string_spec.rb +33 -0
  154. data/spec/gosu_ext/color_spec.rb +80 -0
  155. data/spec/metro/events/event_state_manager_spec.rb +5 -0
  156. data/spec/metro/models/key_value_coding_spec.rb +61 -0
  157. data/spec/metro/models/properties/array_property_spec.rb +60 -0
  158. data/spec/metro/models/properties/color_property_spec.rb +85 -0
  159. data/spec/metro/models/properties/dimensions_spec.rb +29 -0
  160. data/spec/metro/models/properties/font_property_spec.rb +127 -0
  161. data/spec/metro/models/properties/numeric_property_spec.rb +46 -0
  162. data/spec/metro/models/properties/options_property/no_option_spec.rb +25 -0
  163. data/spec/metro/models/properties/options_property/options_property_spec.rb +133 -0
  164. data/spec/metro/models/properties/options_property/options_spec.rb +125 -0
  165. data/spec/metro/models/properties/position_property_spec.rb +90 -0
  166. data/spec/metro/models/ui/label_spec.rb +259 -0
  167. data/spec/metro/parameters/command_line_args_parser_spec.rb +42 -0
  168. data/spec/metro/scene_spec.rb +15 -0
  169. data/spec/metro/scene_views/json_view_spec.rb +27 -0
  170. data/spec/metro/scene_views/yaml_view_spec.rb +38 -0
  171. data/spec/metro/scenes_spec.rb +77 -0
  172. data/spec/metro/units/point_spec.rb +132 -0
  173. data/spec/metro/views/view_spec.rb +53 -0
  174. data/spec/setup_handlers/exit_if_dry_run_spec.rb +27 -0
  175. data/spec/setup_handlers/reload_game_on_game_file_changes_spec.rb +68 -0
  176. data/spec/spec_helper.rb +20 -0
  177. metadata +374 -0
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metro::Model::ArrayProperty do
4
+
5
+ subject { described_class.new model }
6
+ let(:model) { "model" }
7
+
8
+ describe "#get" do
9
+ context "when the value is nil" do
10
+
11
+ context "when no default value has been specified" do
12
+ let(:expected) { [] }
13
+
14
+ it "should return an empty array" do
15
+ subject.get(nil).should eq expected
16
+ end
17
+ end
18
+
19
+ context "when a default value has been specified" do
20
+ subject { described_class.new model, default: expected }
21
+ let(:expected) { [:default_1,:default_2] }
22
+
23
+ it "should return the specified default" do
24
+ subject.get(nil).should eq expected
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+
31
+ describe "#set" do
32
+ context "when the value is nil" do
33
+ let(:expected) { [] }
34
+
35
+ it "should return an empty array" do
36
+ subject.set(nil).should eq expected
37
+ end
38
+ end
39
+
40
+ context "when the value contains symbols" do
41
+ let(:input) { [ :a, :b, :c ] }
42
+ let(:expected) { input }
43
+
44
+ it "should not convert the items to strings" do
45
+ subject.set(input).should eq expected
46
+ end
47
+ end
48
+
49
+ context "when the value contains numbers" do
50
+ let(:input) { [ 1, 5.4, 0xABAB ] }
51
+ let(:expected) { input }
52
+
53
+ it "should not convert the items to strings" do
54
+ subject.set(input).should eq expected
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ 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,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metro::Model::DimensionsProperty do
4
+
5
+ subject { desribed_class.new model }
6
+ let(:model) { mock("model", window: window) }
7
+ let(:window) do
8
+ mock('window',dimensions: window_dimensions )
9
+ end
10
+
11
+ let(:window_dimensions) { Dimensions.of(1,1) }
12
+
13
+ context "when defined with a default block" do
14
+
15
+ subject do
16
+ described_class.new model do
17
+ window.dimensions
18
+ end
19
+ end
20
+
21
+ let(:expected_dimensions) { window_dimensions }
22
+
23
+ it "should calculate the correct default value" do
24
+ subject.get(nil).should eq expected_dimensions
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,127 @@
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
+ let(:expected_font) { stub('font') }
11
+ let(:expected_options) { { name: expected_font_name, size: expected_font_size, window: window } }
12
+
13
+ context "when the value is nil" do
14
+ context "when no default value has been specified" do
15
+ let(:expected_font_name) { Gosu::default_font_name }
16
+ let(:expected_font_size) { 40 }
17
+
18
+ it "should return the default value" do
19
+ described_class.stub(:font_for).with(expected_options) { expected_font }
20
+ subject.get(nil).should eq expected_font
21
+ end
22
+ end
23
+
24
+ context "when a default value has been specified" do
25
+ subject do
26
+ described_class.new model, default: { name: expected_font_name, size: expected_font_size }
27
+ end
28
+
29
+ let(:expected_font_name) { 'Times New Roman' }
30
+ let(:expected_font_size) { 60 }
31
+
32
+ it "should return the specified default value" do
33
+ described_class.stub(:font_for).with(expected_options) { expected_font }
34
+ subject.get(nil).should eq expected_font
35
+ end
36
+ end
37
+ end
38
+
39
+ context "when the value is a hash" do
40
+ let(:expected_font_name) { 'Helvetica' }
41
+ let(:expected_font_size) { 80 }
42
+
43
+ let(:font_hash) { { name: expected_font_name, size: expected_font_size } }
44
+
45
+ it "should return the font value" do
46
+ described_class.stub(:font_for).with(expected_options) { expected_font }
47
+ subject.get(font_hash).should eq expected_font
48
+ end
49
+ end
50
+
51
+ context "when the same font is requested" do
52
+ let(:expected_font_name) { Gosu::default_font_name }
53
+ let(:expected_font_size) { 40 }
54
+
55
+ it "should not be created a second time (pullled from memory)" do
56
+ described_class.should_receive(:font_for).twice { expected_font }
57
+ subject.get(nil)
58
+ subject.get(nil)
59
+ end
60
+ end
61
+
62
+
63
+ end
64
+
65
+ describe "#set" do
66
+ context "when the value is nil" do
67
+ context "when no default value has been specified" do
68
+ let(:expected_font_name) { Gosu::default_font_name }
69
+ let(:expected_font_size) { 40 }
70
+ let(:expected_font) { stub('font') }
71
+
72
+ let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
73
+ let(:expected_options) { { name: expected_font_name, size: expected_font_size, window: window } }
74
+
75
+ it "should return a hash of the default value" do
76
+ described_class.stub(:font_for).with(expected_options) { expected_font }
77
+ subject.set(nil).should eq expected_result
78
+ end
79
+ end
80
+
81
+ context "when a default value has been specified" do
82
+ subject do
83
+ described_class.new model, default: { name: expected_font_name, size: expected_font_size }
84
+ end
85
+
86
+ let(:expected_font_name) { 'Times New Roman' }
87
+ let(:expected_font_size) { 60 }
88
+
89
+ let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
90
+
91
+ it "should return the specified default value" do
92
+ subject.set(nil).should eq expected_result
93
+ end
94
+ end
95
+ end
96
+
97
+ context "when the value is a font" do
98
+
99
+ let(:gosu_font) do
100
+ font = stub('font', name: expected_font_name, height: expected_font_size)
101
+ font.stub(:class) { Metro::Font }
102
+ font
103
+ end
104
+
105
+ let(:expected_font_name) { 'Comic Sans' }
106
+ let(:expected_font_size) { 45 }
107
+
108
+ let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
109
+
110
+ it "should return a hash of the font" do
111
+ subject.set(gosu_font).should eq expected_result
112
+ end
113
+ end
114
+
115
+ context "when the value is a hash" do
116
+
117
+ let(:expected_font_name) { 'Wingdings' }
118
+ let(:expected_font_size) { 33 }
119
+ let(:expected_result) { { name: expected_font_name, size: expected_font_size } }
120
+
121
+ it "should return the hash representation of the font" do
122
+ subject.set(expected_result).should eq expected_result
123
+ end
124
+ end
125
+ end
126
+
127
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metro::Model::NumericProperty do
4
+
5
+ subject { described_class.new model }
6
+ let(:model) { "model" }
7
+
8
+ describe "#get" do
9
+ context "when the value is nil" do
10
+ context "when no default value has been specified" do
11
+
12
+ let(:expected_number) { 0.0 }
13
+
14
+ it "should return the default position" do
15
+ subject.get(nil).should eq expected_number
16
+ end
17
+ end
18
+
19
+ context "when a default value has been specified" do
20
+
21
+ subject { described_class.new model, default: expected_number }
22
+ let(:expected_number) { 1.0 }
23
+
24
+ it "should return the specified default position" do
25
+ subject.get(nil).should eq expected_number
26
+ end
27
+ end
28
+ end
29
+
30
+ context "when the value is a String" do
31
+
32
+ let(:number) { "4.3" }
33
+ let(:expected_number) { 4.3 }
34
+
35
+ it "should get the float value of the string" do
36
+ subject.get(number).should eq expected_number
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ describe "#set" do
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metro::Model::OptionsProperty::NoOption do
4
+
5
+ context "when attempting to an attribute like color of the no option" do
6
+
7
+ let(:log) { mock('log') }
8
+
9
+ it "should generate a warning message" do
10
+ log.should_receive(:warn).with(subject.warning_message)
11
+ subject.stub(:log) { log }
12
+ subject.color = :unknown
13
+ end
14
+ end
15
+
16
+ context "when queried for its action" do
17
+
18
+ let(:expected_action) { :missing_menu_action }
19
+
20
+ it "should return 'missing_menu_action'" do
21
+ subject.properties[:action].should eq expected_action
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metro::Model::OptionsProperty do
4
+
5
+ subject { described_class.new model }
6
+ let(:model) { mock("model", create: 'builds models for a living') }
7
+
8
+ describe "#get" do
9
+ context "when the value is nil" do
10
+ context "when no menu has been specified" do
11
+ it "should return empty options" do
12
+ subject.get(nil).count.should eq 0
13
+ end
14
+ end
15
+ end
16
+
17
+
18
+ context "when the value is an array of options names" do
19
+ before do
20
+ model.stub(:create) { |model_type,options| mock(model_type,options) }
21
+ end
22
+
23
+ let(:names) { [ 'Start Game', 'Options', 'Exit Game' ] }
24
+ let(:actions) { [ :start_game, :options, :exit_game ] }
25
+
26
+ let(:options) { subject.get(names) }
27
+
28
+ it "should return an option for each name" do
29
+ options.count.should eq names.count
30
+ end
31
+
32
+ it "should create labels with text with each name" do
33
+ options.map { |option| option.text }.should eq names
34
+ end
35
+
36
+ it "should create actions based on each name" do
37
+ options.map { |option| option.action }.should eq actions
38
+ end
39
+
40
+ it "should set the default selected as the first item" do
41
+ options.selected.should eq options.first
42
+ end
43
+ end
44
+
45
+
46
+ context "when the value is a hash which is a set of option names and the selected index" do
47
+ before do
48
+ model.stub(:create) { |model_type,options| mock(model_type,options) }
49
+ end
50
+
51
+ let(:names_and_selected_index) do
52
+ { 'selected' => selected_index, 'items' => names }
53
+ end
54
+
55
+ let(:names) { [ 'Start Game', 'Options', 'Exit Game' ] }
56
+ let(:actions) { [ :start_game, :options, :exit_game ] }
57
+ let(:selected_index) { 1 }
58
+
59
+ let(:label_model_class) { 'metro::ui::label' }
60
+
61
+
62
+ let(:options) { subject.get(names_and_selected_index) }
63
+
64
+ it "should return an option for each name" do
65
+ options.count.should eq names.count
66
+ end
67
+
68
+ it "should create labels for each name" do
69
+ options.each { |option| option.model.should eq label_model_class }
70
+ end
71
+
72
+ it "should create labels with text with each name" do
73
+ options.map { |option| option.text }.should eq names
74
+ end
75
+
76
+ it "should create actions based on each name" do
77
+ options.map { |option| option.action }.should eq actions
78
+ end
79
+
80
+ it "should set the default selected as the first item" do
81
+ options.selected.should eq options[selected_index]
82
+ end
83
+ end
84
+
85
+
86
+ context "when the value is hash that contains a set of options (with specific ui details) and the seelcted index" do
87
+ before do
88
+ model.stub(:create) { |model_type,options| mock(model_type,options) }
89
+ end
90
+
91
+ let(:names_and_selected_index) do
92
+ { 'selected' => selected_index, 'items' => details }
93
+ end
94
+
95
+ let(:details) do
96
+ [ { model: 'metro::ui::label', text: 'Start Game!', action: 'start_game' },
97
+ { model: 'metro::ui::image', text: 'Settings', action: 'open_settings' },
98
+ { model: 'metro::ui::label', text: 'Exit' } ]
99
+ end
100
+
101
+
102
+ let(:names) { [ 'Start Game!', 'Settings', 'Exit' ] }
103
+ let(:actions) { [ :start_game, :open_settings, :exit ] }
104
+ let(:models) { [ 'metro::ui::label', 'metro::ui::image', 'metro::ui::label' ] }
105
+
106
+ let(:selected_index) { 1 }
107
+
108
+ let(:options) { subject.get(names_and_selected_index) }
109
+
110
+ it "should return an option for each name" do
111
+ options.count.should eq names.count
112
+ end
113
+
114
+ it "should create labels for each name" do
115
+ options.map { |option| option.model }.should eq models
116
+ end
117
+
118
+ it "should create labels with text with each name" do
119
+ options.map { |option| option.text }.should eq names
120
+ end
121
+
122
+ it "should create actions based on each name" do
123
+ options.map { |option| option.action }.should eq actions
124
+ end
125
+
126
+ it "should set the default selected as the first item" do
127
+ options.selected.should eq options[selected_index]
128
+ end
129
+ end
130
+
131
+ end
132
+
133
+ end