metro-ld25 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +12 -0
- data/Guardfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +189 -0
- data/Rakefile +18 -0
- data/bin/metro +16 -0
- data/changelog.md +157 -0
- data/lib/assets/menu-movement.wav +0 -0
- data/lib/assets/menu-selection.wav +0 -0
- data/lib/assets/missing.ogg +0 -0
- data/lib/assets/missing.png +0 -0
- data/lib/assets/missing.wav +0 -0
- data/lib/assets/missing_animation.png +0 -0
- data/lib/commands/generate_game.rb +13 -0
- data/lib/commands/generate_model.rb +25 -0
- data/lib/commands/generate_scene.rb +36 -0
- data/lib/commands/generate_view.rb +21 -0
- data/lib/commands/thor.rb +83 -0
- data/lib/core_ext/class.rb +14 -0
- data/lib/core_ext/numeric.rb +59 -0
- data/lib/gosu_ext/color.rb +62 -0
- data/lib/gosu_ext/gosu_constants.rb +53 -0
- data/lib/locale/en.yml +35 -0
- data/lib/locale/locale.rb +1 -0
- data/lib/metro.rb +140 -0
- data/lib/metro/animation.rb +135 -0
- data/lib/metro/animation/after_interval_factory.rb +12 -0
- data/lib/metro/animation/animation_factory.rb +15 -0
- data/lib/metro/animation/easing/ease_in.rb +15 -0
- data/lib/metro/animation/easing/easing.rb +51 -0
- data/lib/metro/animation/easing/linear.rb +15 -0
- data/lib/metro/animation/has_animations.rb +70 -0
- data/lib/metro/animation/implicit_animation.rb +100 -0
- data/lib/metro/animation/on_update_operation.rb +96 -0
- data/lib/metro/animation/scene_animation.rb +16 -0
- data/lib/metro/asset_path.rb +97 -0
- data/lib/metro/events/control_definition.rb +11 -0
- data/lib/metro/events/controls.rb +42 -0
- data/lib/metro/events/event_data.rb +60 -0
- data/lib/metro/events/event_dictionary.rb +52 -0
- data/lib/metro/events/event_factory.rb +17 -0
- data/lib/metro/events/event_relay.rb +300 -0
- data/lib/metro/events/event_state_manager.rb +63 -0
- data/lib/metro/events/events.rb +3 -0
- data/lib/metro/events/has_events.rb +108 -0
- data/lib/metro/events/hit_list.rb +75 -0
- data/lib/metro/events/unknown_sender.rb +5 -0
- data/lib/metro/font.rb +69 -0
- data/lib/metro/game.rb +102 -0
- data/lib/metro/game/dsl.rb +68 -0
- data/lib/metro/image.rb +68 -0
- data/lib/metro/logging.rb +33 -0
- data/lib/metro/missing_scene.rb +21 -0
- data/lib/metro/models/audio/song.rb +33 -0
- data/lib/metro/models/draws.rb +86 -0
- data/lib/metro/models/key_value_coding.rb +38 -0
- data/lib/metro/models/model.rb +236 -0
- data/lib/metro/models/model_factory.rb +32 -0
- data/lib/metro/models/models.rb +62 -0
- data/lib/metro/models/properties/animation_property.rb +115 -0
- data/lib/metro/models/properties/array_property.rb +24 -0
- data/lib/metro/models/properties/boolean_property.rb +27 -0
- data/lib/metro/models/properties/color_property.rb +116 -0
- data/lib/metro/models/properties/dimensions_property.rb +84 -0
- data/lib/metro/models/properties/font_property.rb +130 -0
- data/lib/metro/models/properties/image_property.rb +96 -0
- data/lib/metro/models/properties/model_property.rb +84 -0
- data/lib/metro/models/properties/numeric_property.rb +29 -0
- data/lib/metro/models/properties/options_property/no_option.rb +29 -0
- data/lib/metro/models/properties/options_property/options.rb +94 -0
- data/lib/metro/models/properties/options_property/options_property.rb +125 -0
- data/lib/metro/models/properties/position_property.rb +90 -0
- data/lib/metro/models/properties/property.rb +221 -0
- data/lib/metro/models/properties/property_owner.rb +137 -0
- data/lib/metro/models/properties/sample_property.rb +84 -0
- data/lib/metro/models/properties/scale_property.rb +80 -0
- data/lib/metro/models/properties/song_property.rb +89 -0
- data/lib/metro/models/properties/text_property.rb +75 -0
- data/lib/metro/models/ui/animated_sprite.rb +85 -0
- data/lib/metro/models/ui/border.rb +95 -0
- data/lib/metro/models/ui/fps.rb +54 -0
- data/lib/metro/models/ui/generic.rb +66 -0
- data/lib/metro/models/ui/grid_drawer.rb +74 -0
- data/lib/metro/models/ui/image.rb +87 -0
- data/lib/metro/models/ui/label.rb +175 -0
- data/lib/metro/models/ui/menu.rb +214 -0
- data/lib/metro/models/ui/model_label.rb +65 -0
- data/lib/metro/models/ui/model_labeler.rb +79 -0
- data/lib/metro/models/ui/rectangle.rb +59 -0
- data/lib/metro/models/ui/sprite.rb +79 -0
- data/lib/metro/models/ui/tile_map.rb +162 -0
- data/lib/metro/models/ui/ui.rb +13 -0
- data/lib/metro/parameters/command_line_args_parser.rb +68 -0
- data/lib/metro/parameters/options.rb +25 -0
- data/lib/metro/parameters/parameters.rb +2 -0
- data/lib/metro/sample.rb +40 -0
- data/lib/metro/scene.rb +477 -0
- data/lib/metro/scenes.rb +154 -0
- data/lib/metro/song.rb +56 -0
- data/lib/metro/template_message.rb +60 -0
- data/lib/metro/transitions/edit_transition_scene.rb +100 -0
- data/lib/metro/transitions/fade_transition_scene.rb +66 -0
- data/lib/metro/transitions/scene_transitions.rb +44 -0
- data/lib/metro/transitions/transition_scene.rb +19 -0
- data/lib/metro/units/bounds.rb +8 -0
- data/lib/metro/units/calculation_validations.rb +74 -0
- data/lib/metro/units/dimensions.rb +60 -0
- data/lib/metro/units/point.rb +51 -0
- data/lib/metro/units/rectangle_bounds.rb +85 -0
- data/lib/metro/units/scale.rb +46 -0
- data/lib/metro/units/units.rb +6 -0
- data/lib/metro/version.rb +32 -0
- data/lib/metro/views/json_view.rb +60 -0
- data/lib/metro/views/no_view.rb +34 -0
- data/lib/metro/views/parsers.rb +42 -0
- data/lib/metro/views/scene_view.rb +107 -0
- data/lib/metro/views/view.rb +133 -0
- data/lib/metro/views/writers.rb +43 -0
- data/lib/metro/views/yaml_view.rb +94 -0
- data/lib/metro/window.rb +94 -0
- data/lib/setup_handlers/exit_if_dry_run.rb +26 -0
- data/lib/setup_handlers/game_execution.rb +65 -0
- data/lib/setup_handlers/load_game_configuration.rb +65 -0
- data/lib/setup_handlers/load_game_files.rb +101 -0
- data/lib/setup_handlers/move_to_game_directory.rb +25 -0
- data/lib/setup_handlers/reload_game_on_game_file_changes.rb +79 -0
- data/lib/templates/game/README.md.tt +52 -0
- data/lib/templates/game/assets/brand.jpg +0 -0
- data/lib/templates/game/assets/hero.png +0 -0
- data/lib/templates/game/lib/custom_easing.rb +32 -0
- data/lib/templates/game/metro.tt +63 -0
- data/lib/templates/game/models/hero.rb +62 -0
- data/lib/templates/game/scenes/brand_scene.rb +19 -0
- data/lib/templates/game/scenes/brand_to_title_scene.rb +13 -0
- data/lib/templates/game/scenes/first_scene.rb +28 -0
- data/lib/templates/game/scenes/game_scene.rb +43 -0
- data/lib/templates/game/scenes/title_scene.rb +15 -0
- data/lib/templates/game/views/brand.yaml +4 -0
- data/lib/templates/game/views/brand_to_title.yaml +8 -0
- data/lib/templates/game/views/first.yaml +26 -0
- data/lib/templates/game/views/title.yaml +11 -0
- data/lib/templates/message.erb +23 -0
- data/lib/templates/model.rb.tt +111 -0
- data/lib/templates/scene.rb.tt +140 -0
- data/lib/templates/view.yaml.tt +11 -0
- data/lib/tmxed_ext/tile_set.rb +34 -0
- data/metro.gemspec +56 -0
- data/spec/core_ext/numeric_spec.rb +78 -0
- data/spec/core_ext/string_spec.rb +33 -0
- data/spec/gosu_ext/color_spec.rb +80 -0
- data/spec/metro/events/event_state_manager_spec.rb +5 -0
- data/spec/metro/models/key_value_coding_spec.rb +61 -0
- data/spec/metro/models/properties/array_property_spec.rb +60 -0
- data/spec/metro/models/properties/color_property_spec.rb +85 -0
- data/spec/metro/models/properties/dimensions_spec.rb +29 -0
- data/spec/metro/models/properties/font_property_spec.rb +127 -0
- data/spec/metro/models/properties/numeric_property_spec.rb +46 -0
- data/spec/metro/models/properties/options_property/no_option_spec.rb +25 -0
- data/spec/metro/models/properties/options_property/options_property_spec.rb +133 -0
- data/spec/metro/models/properties/options_property/options_spec.rb +125 -0
- data/spec/metro/models/properties/position_property_spec.rb +90 -0
- data/spec/metro/models/ui/label_spec.rb +259 -0
- data/spec/metro/parameters/command_line_args_parser_spec.rb +42 -0
- data/spec/metro/scene_spec.rb +15 -0
- data/spec/metro/scene_views/json_view_spec.rb +27 -0
- data/spec/metro/scene_views/yaml_view_spec.rb +38 -0
- data/spec/metro/scenes_spec.rb +77 -0
- data/spec/metro/units/point_spec.rb +132 -0
- data/spec/metro/views/view_spec.rb +53 -0
- data/spec/setup_handlers/exit_if_dry_run_spec.rb +27 -0
- data/spec/setup_handlers/reload_game_on_game_file_changes_spec.rb +68 -0
- data/spec/spec_helper.rb +20 -0
- metadata +374 -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,34 @@
|
|
1
|
+
module Tmxed
|
2
|
+
class TileSet
|
3
|
+
attr_accessor :window
|
4
|
+
|
5
|
+
def full_width
|
6
|
+
tilewidth + spacing
|
7
|
+
end
|
8
|
+
|
9
|
+
def full_height
|
10
|
+
tileheight + spacing
|
11
|
+
end
|
12
|
+
|
13
|
+
def crop_bounds
|
14
|
+
[ margin, margin, tilewidth - spacing, tileheight - spacing ]
|
15
|
+
end
|
16
|
+
|
17
|
+
def image_path
|
18
|
+
Metro::AssetPath.with(image).filepath
|
19
|
+
end
|
20
|
+
|
21
|
+
def images
|
22
|
+
@images ||= begin
|
23
|
+
original_images = Gosu::Image.load_tiles window, image_path, full_width,full_height, true
|
24
|
+
crop_images original_images
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def crop_images(images)
|
31
|
+
images
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/metro.gemspec
ADDED
@@ -0,0 +1,56 @@
|
|
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-ld25"
|
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 'thor', '~> 0.16.0'
|
29
|
+
gem.add_dependency 'i18n', '~> 0.6.1'
|
30
|
+
gem.add_dependency 'active_support', '~> 3.0.0'
|
31
|
+
gem.add_dependency 'listen', '~> 0.6.0'
|
32
|
+
gem.add_dependency 'tmxed', '~> 0.0.1'
|
33
|
+
gem.add_development_dependency 'rspec', '~> 2.11'
|
34
|
+
|
35
|
+
gem.files = `git ls-files`.split($/)
|
36
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
37
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
38
|
+
gem.require_paths = ["lib"]
|
39
|
+
|
40
|
+
changes = Metro.changes_for_version(::Metro::VERSION)
|
41
|
+
|
42
|
+
gem.post_install_message = <<-EOM
|
43
|
+
______ ___ _____
|
44
|
+
___ |/ /_____ __ /_______________
|
45
|
+
__ /|_/ / _ _ \\_ __/__ ___/_ __ \\
|
46
|
+
_ / / / / __// /_ _ / / /_/ /
|
47
|
+
/_/ /_/ \\___/ \\__/ /_/ \\____/
|
48
|
+
|
49
|
+
Thank you for installing metro #{::Metro::VERSION} / #{changes.date}.
|
50
|
+
---------------------------------------------------------------------
|
51
|
+
Changes:
|
52
|
+
#{changes.changes.map{|change| " #{change}"}.join("")}
|
53
|
+
---------------------------------------------------------------------
|
54
|
+
EOM
|
55
|
+
|
56
|
+
end
|
@@ -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
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::KeyValueCoding do
|
4
|
+
|
5
|
+
class KeyValueCodingObject
|
6
|
+
include Metro::KeyValueCoding
|
7
|
+
attr_accessor :description, :properties
|
8
|
+
end
|
9
|
+
|
10
|
+
subject do
|
11
|
+
object = KeyValueCodingObject.new
|
12
|
+
|
13
|
+
object.description = "Describe Yourself"
|
14
|
+
object.properties = { height: 100, width: 50 }
|
15
|
+
|
16
|
+
object
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#get" do
|
20
|
+
context "when given a key with a single attribute" do
|
21
|
+
let(:key) { :description }
|
22
|
+
let(:expected_value) { "Describe Yourself" }
|
23
|
+
|
24
|
+
it "should return the value" do
|
25
|
+
subject.get(key).should eq expected_value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when given a key with multiple attributes" do
|
30
|
+
let(:key) { "properties.keys" }
|
31
|
+
let(:expected_value) { [ :height, :width ] }
|
32
|
+
|
33
|
+
it "should return the expected value" do
|
34
|
+
subject.get(key).should eq expected_value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#set" do
|
40
|
+
context "when given a key with a single attribute" do
|
41
|
+
let(:key) { :description }
|
42
|
+
let(:expected_value) { "New Description" }
|
43
|
+
|
44
|
+
it "should set the value" do
|
45
|
+
subject.set(key,expected_value)
|
46
|
+
subject.get(key).should eq expected_value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when given a key with multiple attributes" do
|
51
|
+
let(:key) { "properties.default" }
|
52
|
+
let(:expected_value) { 0 }
|
53
|
+
|
54
|
+
it "should set the value" do
|
55
|
+
subject.set(key,expected_value)
|
56
|
+
subject.get(key).should eq expected_value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|