metro-ld26 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +14 -0
  6. data/Guardfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +177 -0
  9. data/Rakefile +18 -0
  10. data/bin/metro +16 -0
  11. data/changelog.md +153 -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 +144 -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 +342 -0
  47. data/lib/metro/events/event_state_manager.rb +70 -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 +75 -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 +246 -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 +98 -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 +132 -0
  96. data/lib/metro/models/ui/tmx/isometric_position.rb +43 -0
  97. data/lib/metro/models/ui/tmx/orthogonal_position.rb +15 -0
  98. data/lib/metro/models/ui/tmx/tile_layer.rb +78 -0
  99. data/lib/metro/models/ui/ui.rb +13 -0
  100. data/lib/metro/parameters/command_line_args_parser.rb +68 -0
  101. data/lib/metro/parameters/options.rb +25 -0
  102. data/lib/metro/parameters/parameters.rb +2 -0
  103. data/lib/metro/sample.rb +40 -0
  104. data/lib/metro/scene.rb +478 -0
  105. data/lib/metro/scenes.rb +154 -0
  106. data/lib/metro/song.rb +56 -0
  107. data/lib/metro/template_message.rb +60 -0
  108. data/lib/metro/transitions/edit_transition_scene.rb +100 -0
  109. data/lib/metro/transitions/fade_transition_scene.rb +66 -0
  110. data/lib/metro/transitions/scene_transitions.rb +44 -0
  111. data/lib/metro/transitions/transition_scene.rb +19 -0
  112. data/lib/metro/units/bounds.rb +8 -0
  113. data/lib/metro/units/calculation_validations.rb +74 -0
  114. data/lib/metro/units/dimensions.rb +60 -0
  115. data/lib/metro/units/point.rb +51 -0
  116. data/lib/metro/units/rectangle_bounds.rb +148 -0
  117. data/lib/metro/units/scale.rb +46 -0
  118. data/lib/metro/units/units.rb +6 -0
  119. data/lib/metro/version.rb +32 -0
  120. data/lib/metro/views/json_view.rb +60 -0
  121. data/lib/metro/views/no_view.rb +34 -0
  122. data/lib/metro/views/parsers.rb +42 -0
  123. data/lib/metro/views/scene_view.rb +107 -0
  124. data/lib/metro/views/view.rb +133 -0
  125. data/lib/metro/views/writers.rb +43 -0
  126. data/lib/metro/views/yaml_view.rb +94 -0
  127. data/lib/metro/window.rb +95 -0
  128. data/lib/setup_handlers/exit_if_dry_run.rb +26 -0
  129. data/lib/setup_handlers/game_execution.rb +65 -0
  130. data/lib/setup_handlers/load_game_configuration.rb +65 -0
  131. data/lib/setup_handlers/load_game_files.rb +101 -0
  132. data/lib/setup_handlers/move_to_game_directory.rb +25 -0
  133. data/lib/setup_handlers/reload_game_on_game_file_changes.rb +79 -0
  134. data/lib/templates/game/README.md.tt +43 -0
  135. data/lib/templates/game/assets/brand.jpg +0 -0
  136. data/lib/templates/game/assets/hero.png +0 -0
  137. data/lib/templates/game/lib/custom_easing.rb +32 -0
  138. data/lib/templates/game/metro.tt +63 -0
  139. data/lib/templates/game/models/hero.rb +62 -0
  140. data/lib/templates/game/scenes/brand_scene.rb +19 -0
  141. data/lib/templates/game/scenes/brand_to_title_scene.rb +13 -0
  142. data/lib/templates/game/scenes/first_scene.rb +28 -0
  143. data/lib/templates/game/scenes/game_scene.rb +43 -0
  144. data/lib/templates/game/scenes/title_scene.rb +15 -0
  145. data/lib/templates/game/views/brand.yaml +4 -0
  146. data/lib/templates/game/views/brand_to_title.yaml +8 -0
  147. data/lib/templates/game/views/first.yaml +26 -0
  148. data/lib/templates/game/views/title.yaml +11 -0
  149. data/lib/templates/message.erb +23 -0
  150. data/lib/templates/model.rb.tt +111 -0
  151. data/lib/templates/scene.rb.tt +140 -0
  152. data/lib/templates/view.yaml.tt +11 -0
  153. data/lib/tmx_ext/object.rb +26 -0
  154. data/lib/tmx_ext/tile_set.rb +41 -0
  155. data/metro.gemspec +57 -0
  156. data/metro.png +0 -0
  157. data/spec/core_ext/numeric_spec.rb +78 -0
  158. data/spec/core_ext/string_spec.rb +33 -0
  159. data/spec/gosu_ext/color_spec.rb +80 -0
  160. data/spec/metro/image_spec.rb +33 -0
  161. data/spec/metro/models/key_value_coding_spec.rb +61 -0
  162. data/spec/metro/models/properties/array_property_spec.rb +60 -0
  163. data/spec/metro/models/properties/color_property_spec.rb +85 -0
  164. data/spec/metro/models/properties/dimensions_spec.rb +29 -0
  165. data/spec/metro/models/properties/font_property_spec.rb +127 -0
  166. data/spec/metro/models/properties/numeric_property_spec.rb +46 -0
  167. data/spec/metro/models/properties/options_property/no_option_spec.rb +25 -0
  168. data/spec/metro/models/properties/options_property/options_property_spec.rb +133 -0
  169. data/spec/metro/models/properties/options_property/options_spec.rb +125 -0
  170. data/spec/metro/models/properties/position_property_spec.rb +90 -0
  171. data/spec/metro/models/ui/label_spec.rb +259 -0
  172. data/spec/metro/parameters/command_line_args_parser_spec.rb +42 -0
  173. data/spec/metro/scene_spec.rb +15 -0
  174. data/spec/metro/scene_views/json_view_spec.rb +27 -0
  175. data/spec/metro/scene_views/yaml_view_spec.rb +38 -0
  176. data/spec/metro/scenes_spec.rb +77 -0
  177. data/spec/metro/units/point_spec.rb +132 -0
  178. data/spec/metro/units/rectangle_bounds_spec.rb +56 -0
  179. data/spec/metro/views/view_spec.rb +53 -0
  180. data/spec/setup_handlers/exit_if_dry_run_spec.rb +27 -0
  181. data/spec/setup_handlers/reload_game_on_game_file_changes_spec.rb +68 -0
  182. data/spec/spec_helper.rb +20 -0
  183. data/spec/tmx_ext/object_spec.rb +96 -0
  184. data/spec/tmx_ext/tile_set_spec.rb +24 -0
  185. metadata +379 -0
@@ -0,0 +1,140 @@
1
+ class <%= scene_class_name %> < GameScene
2
+ # By default the Scene Name is based on the class name
3
+ # but that can be overridden with the scene_name class method
4
+ # scene_name "credits"
5
+
6
+ draw :title
7
+
8
+ #
9
+ # DRAWING and ACTORS
10
+ #
11
+ # @example Explicitly drawing a text label in the scene
12
+ #
13
+ # draw :title, model: 'metro::ui::label',
14
+ # text: 'Title Screen',
15
+ # position: '20,20,0',
16
+ # font: { size: 60 },
17
+ # color: 'rgba(255,255,255,1.0)',
18
+ # align: 'center',
19
+ # vertical_align: 'center'
20
+ #
21
+ #
22
+ # The draw method can be simpler for models that have content defined
23
+ # for them in the view or the models themselves define the appropriate
24
+ # fields.
25
+ #
26
+ # @example defining multiple things to draw; their visual data would be
27
+ # stored within the respective view file
28
+ #
29
+ # draws :title, :hero, :enemy
30
+ #
31
+
32
+ #
33
+ # ANIMATIONS
34
+ #
35
+ # @example of the title being moved to a new y position and the alpha level
36
+ #
37
+ # animate :title, to: { y: 80, alpha: 50 }, interval: 120.ticks do
38
+ # puts "Done Animating!"
39
+ # end
40
+ #
41
+ # @example of using nested animations and after blocks to generate a fade in
42
+ # and fade out effect.
43
+ #
44
+ # after 2.seconds do
45
+ # animate :title, to: { alpha: 255 }, interval: 1.second do
46
+ # after 1.second do
47
+ # animate :title, to: { alpha: 0 }, interval: 1.second
48
+ # end
49
+ # end
50
+ # end
51
+ #
52
+ # @note the interval can be specified in game ticks ( 1.tick, 23.ticks ) or
53
+ # in seconds ( 1.second, 23.seconds ). 60 game times are roughly equivalent
54
+ # to 1 second, however you should not use Metro for monitoring a nuclear
55
+ # reactor.
56
+ #
57
+
58
+ #
59
+ # Example Event Handling Definitions
60
+ #
61
+ # @example Registering the keyboard down event to execute a block of code
62
+ #
63
+ # event :on_down, GpLeft, GpUp, do
64
+ # transition_to :next_scene
65
+ # end
66
+ #
67
+ # @example Registering the keyboard up key to execute the method `leave_scene`
68
+ #
69
+ # event :on_up, KbEscape, do: :leave_scene
70
+ #
71
+ # @example Registering for button held events that would move an actor named `player`
72
+ #
73
+ # event :on_hold, KbRight, GpRight do
74
+ # title.alpha = title.alpha - 1
75
+ # end
76
+ # Keystroke and Game Event Reference
77
+ #
78
+ # @see https://github.com/jlnr/gosu/blob/master/Gosu/ButtonsMac.hpp
79
+ # @see https://github.com/jlnr/gosu/blob/master/Gosu/ButtonsX.hpp
80
+ # @see https://github.com/jlnr/gosu/blob/master/Gosu/ButtonsWin.hpp
81
+ #
82
+ #
83
+ # @example Registering for an event called 'save_complete' event that anyone
84
+ # can generate and this scene block will execute this code.
85
+ #
86
+ # event :notification, :save_complete do
87
+ # puts "Save Complete!"
88
+ # end
89
+ #
90
+ # Within the scene or in the models you could use the method `notification`
91
+ # to generate the notification
92
+ #
93
+ # def update
94
+ # if player.x > 600 and player.y > 440
95
+ # notification :player_wins
96
+ # end
97
+ # end
98
+ #
99
+
100
+ #
101
+ # As Scene does a lot of work for you with regarding to setting up content, it is
102
+ # best not to override #initialize and instead define an #after_initialize method
103
+ # within the subclasses of Scene.
104
+ #
105
+ def after_initialize ; end
106
+
107
+ #
108
+ # This method is called right after the scene has been adopted by the window.
109
+ # This is a great place to make changes to the scene before the update methods
110
+ # or draw methods have ever been called.
111
+ #
112
+ def show ; end
113
+
114
+ #
115
+ # This is called every update interval while the scene is being shown in the
116
+ # window.
117
+ #
118
+ def update ; end
119
+
120
+ #
121
+ # This is called after every #update and when the OS wants the window to
122
+ # repaint itself.
123
+ #
124
+ def draw ; end
125
+
126
+ #
127
+ # Before a scene is transitioned away from to a new scene, this method is called
128
+ # to allow for the scene to complete any tasks, stop any actions, or pass any
129
+ # information from the existing scene to the scene that is about to replace it.
130
+ #
131
+ def prepare_transition_to(new_scene) ; end
132
+
133
+ #
134
+ # Before a scene is transitioned to it is called with the previous scene. This
135
+ # allows for the new scene to retrieve any data from the previous scene to assist
136
+ # with the layout of the current scene.
137
+ #
138
+ def prepare_transition_from(old_scene) ; end
139
+
140
+ end
@@ -0,0 +1,11 @@
1
+ # http://www.yaml.org/YAML_for_ruby.html
2
+ ---
3
+ title:
4
+ model: "metro::ui::label"
5
+ text: "Your Scene"
6
+ align: center
7
+ vertical_align: center
8
+ position: "190,200,4"
9
+ font:
10
+ size: 60
11
+ color: "rgba(255,255,0,1.0)"
@@ -0,0 +1,26 @@
1
+ module Tmx
2
+
3
+ class Object
4
+
5
+ # TODO: the mass and moment of interia should configurable through properties
6
+ def body
7
+ @body ||= CP::Body.new default_mass, default_moment_of_inertia
8
+ end
9
+
10
+ def shape
11
+ @shape ||= Tmx::ObjectShape.create_from_tmx_object(self)
12
+ end
13
+
14
+
15
+ def default_mass
16
+ Float::INFINITY
17
+ end
18
+
19
+ def default_moment_of_inertia
20
+ Float::INFINITY
21
+ end
22
+
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,41 @@
1
+ module Tmx
2
+
3
+ #
4
+ # Define additional functionaly or override existing functionaliy on
5
+ # the Tmx class to make it compatible with Metro.
6
+ #
7
+ class TileSet
8
+ attr_accessor :window
9
+
10
+ def images
11
+ @images ||= raw_image_tiles.map {|image| crop_image(image) }
12
+ end
13
+
14
+ private
15
+
16
+ def raw_image_tiles
17
+ Gosu::Image.load_tiles(window, image_path, full_image_width, full_image_height, false)
18
+ end
19
+
20
+ def crop_image(image)
21
+ Metro::Image.crop window, image, crop_bounds
22
+ end
23
+
24
+ def full_image_width
25
+ tilewidth + spacing
26
+ end
27
+
28
+ def full_image_height
29
+ tileheight + spacing
30
+ end
31
+
32
+ def crop_bounds
33
+ @crop_bounds ||= Metro::Units::RectangleBounds.new left: margin, top: margin,
34
+ right: full_image_width, bottom: full_image_height
35
+ end
36
+
37
+ def image_path
38
+ Metro::AssetPath.with(image).filepath
39
+ end
40
+ end
41
+ end
data/metro.gemspec ADDED
@@ -0,0 +1,57 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'metro/version'
5
+
6
+ Struct.new("Changes",:date,:changes)
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.name = "metro-ld26"
10
+ gem.version = Metro::VERSION
11
+ gem.authors = ["Franklin Webber"]
12
+ gem.email = Metro::CONTACT_EMAILS
13
+ gem.license = "MIT"
14
+ gem.summary = <<-EOS
15
+ Metro is a 2D Gaming framework built around gosu (game development library).
16
+ Metro makes it easy to create games by enforcing common conceptual structures
17
+ and conventions.
18
+ EOS
19
+ gem.description = <<-EOS
20
+ Metro is a 2D Gaming framework built around gosu (game development library).
21
+ Metro makes it easy to create games by enforcing common conceptual structures
22
+ and conventions.
23
+ EOS
24
+
25
+ gem.homepage = Metro::WEBSITE
26
+
27
+ gem.add_dependency 'gosu', '~> 0.7'
28
+ gem.add_dependency 'texplay', '~> 0.4'
29
+ gem.add_dependency 'tmx', '~> 0.1.2'
30
+ gem.add_dependency 'thor', '~> 0.16.0'
31
+ gem.add_dependency 'i18n', '~> 0.6.1'
32
+ gem.add_dependency 'active_support', '~> 3.0.0'
33
+ gem.add_dependency 'listen', '~> 0.6.0'
34
+ gem.add_development_dependency 'rspec', '~> 2.11'
35
+
36
+ gem.files = `git ls-files`.split($/)
37
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
38
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
39
+ gem.require_paths = ["lib"]
40
+
41
+ changes = Metro.changes_for_version(::Metro::VERSION)
42
+
43
+ gem.post_install_message = <<-EOM
44
+ ______ ___ _____
45
+ ___ |/ /_____ __ /_______________
46
+ __ /|_/ / _ _ \\_ __/__ ___/_ __ \\
47
+ _ / / / / __// /_ _ / / /_/ /
48
+ /_/ /_/ \\___/ \\__/ /_/ \\____/
49
+
50
+ Thank you for installing metro #{::Metro::VERSION} / #{changes.date}.
51
+ ---------------------------------------------------------------------
52
+ Changes:
53
+ #{changes.changes.map{|change| " #{change}"}.join("")}
54
+ ---------------------------------------------------------------------
55
+ EOM
56
+
57
+ end
data/metro.png ADDED
Binary file
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Numeric do
4
+
5
+ before :each do
6
+ Numeric.tick_interval = 16.666666
7
+ end
8
+
9
+ describe "#tick(s)" do
10
+ context "when using an Integer" do
11
+ subject { 60 }
12
+ let(:expected_value) { 60 }
13
+
14
+ its(:tick) { should eq expected_value }
15
+ its(:ticks) { should eq expected_value }
16
+ end
17
+
18
+ context "when using a Float" do
19
+ subject { 70.1 }
20
+ let(:expected_value) { 70.1 }
21
+
22
+ its(:tick) { should eq expected_value }
23
+ its(:ticks) { should eq expected_value }
24
+ end
25
+ end
26
+
27
+ describe "#second(s)" do
28
+
29
+ context "when using an Integer" do
30
+ context "when the tick interval has not been set" do
31
+ subject { 2 }
32
+ let(:expected_value) { 120 }
33
+
34
+ its(:second) { should eq expected_value }
35
+ its(:seconds) { should eq expected_value }
36
+ its(:sec) { should eq expected_value }
37
+ its(:secs) { should eq expected_value }
38
+ end
39
+
40
+ context "when the tick interval has been set to 33.3333" do
41
+ before :each do
42
+ Numeric.tick_interval = 33.333333
43
+ end
44
+
45
+ subject { 2 }
46
+ let(:expected_value) { 60 }
47
+
48
+ its(:second) { should eq expected_value }
49
+ its(:seconds) { should eq expected_value }
50
+ end
51
+ end
52
+
53
+ context "when using a Float" do
54
+ context "when the tick interval has not been set" do
55
+ subject { 2.5 }
56
+ let(:expected_value) { 150 }
57
+
58
+ its(:second) { should eq expected_value }
59
+ its(:seconds) { should eq expected_value }
60
+ its(:sec) { should eq expected_value }
61
+ its(:secs) { should eq expected_value }
62
+ end
63
+
64
+ context "when the tick interval has been set" do
65
+ before :each do
66
+ Numeric.tick_interval = 33.333333
67
+ end
68
+
69
+ subject { 3.5 }
70
+ let(:expected_value) { 105 }
71
+
72
+ its(:second) { should eq expected_value }
73
+ its(:seconds) { should eq expected_value }
74
+ end
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+
5
+ describe "#underscore" do
6
+ context "when given a regular string" do
7
+ subject { "String" }
8
+ let(:expected_value) { "string" }
9
+
10
+ its(:underscore) { should eq expected_value }
11
+ end
12
+
13
+ context "when given an already snake cased string" do
14
+ subject { "underscored" }
15
+ let(:expected_value) { "underscored" }
16
+
17
+ its(:underscore) { should eq expected_value }
18
+ end
19
+
20
+ context "when given a camelCased string" do
21
+ subject { "SnakeCased" }
22
+ let(:expected_value) { "snake_cased" }
23
+
24
+ its(:underscore) { should eq expected_value }
25
+ end
26
+
27
+ context "when given a partial camel_Cased string" do
28
+ subject { "snake_Cased" }
29
+ let(:expected_value) { "snake_cased" }
30
+ its(:underscore) { should eq expected_value }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gosu::Color do
4
+
5
+ shared_examples "a correctly defined color" do
6
+
7
+ let(:expected_red_value) { expected_color_values[0] }
8
+ let(:expected_green_value) { expected_color_values[1] }
9
+ let(:expected_blue_value) { expected_color_values[2] }
10
+ let(:expected_alpha_value) { expected_color_values[3] }
11
+
12
+ it "should have the correct red color" do
13
+ subject.red.should eq expected_red_value
14
+ end
15
+
16
+ it "should have the correct green color" do
17
+ subject.green.should eq expected_green_value
18
+ end
19
+
20
+ it "should have the correct blue color" do
21
+ subject.blue.should eq expected_blue_value
22
+ end
23
+
24
+ it "should have the correct alpha value" do
25
+ subject.alpha.should eq expected_alpha_value
26
+ end
27
+ end
28
+
29
+ shared_examples "a color defined as white" do
30
+ let(:expected_color_values) { [ 255, 255, 255, 255 ] }
31
+ it_behaves_like "a correctly defined color"
32
+ end
33
+
34
+ describe "#initialize" do
35
+
36
+ context "when defined with an existing Gosu Color" do
37
+ subject { described_class.new color }
38
+ let(:color) { described_class.new 123, 123, 123, 0 }
39
+ let(:expected_color_values) { [ 123, 123, 0, 123 ] }
40
+ it_behaves_like "a correctly defined color"
41
+ end
42
+
43
+ context "when defined with a hexadecimal value" do
44
+ subject { described_class.new hex }
45
+ let(:hex) { 0xFF777777 }
46
+ let(:expected_color_values) { [ 119, 119, 119, 255 ] }
47
+ it_behaves_like "a correctly defined color"
48
+ end
49
+
50
+ context "when defined with a gosu color hex string" do
51
+ subject { described_class.new hex }
52
+ let(:hex) { "0xFF777777" }
53
+ let(:expected_color_values) { [ 119, 119, 119, 255 ] }
54
+ it_behaves_like "a correctly defined color"
55
+ end
56
+
57
+ context "when defined with a hex string" do
58
+ subject { described_class.new hex }
59
+ let(:hex) { "#777777" }
60
+ let(:expected_color_values) { [ 119, 119, 119, 255 ] }
61
+ it_behaves_like "a correctly defined color"
62
+ end
63
+
64
+ context "when defined with a rgb string" do
65
+ subject { described_class.new rgb }
66
+ let(:rgb) { "rgb(127,127,127)" }
67
+ let(:expected_color_values) { [ 127, 127, 127, 255 ] }
68
+ it_behaves_like "a correctly defined color"
69
+ end
70
+
71
+ context "when defined with a rgba color" do
72
+ subject { described_class.new rgba }
73
+ let(:rgba) { "rgba(127,127,127,0.5)" }
74
+ let(:expected_color_values) { [ 127, 127, 127, 127 ] }
75
+ it_behaves_like "a correctly defined color"
76
+ end
77
+
78
+ end
79
+
80
+ end