metro-ld26 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +14 -0
- data/Guardfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +177 -0
- data/Rakefile +18 -0
- data/bin/metro +16 -0
- data/changelog.md +153 -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 +144 -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 +342 -0
- data/lib/metro/events/event_state_manager.rb +70 -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 +75 -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 +246 -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 +98 -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 +132 -0
- data/lib/metro/models/ui/tmx/isometric_position.rb +43 -0
- data/lib/metro/models/ui/tmx/orthogonal_position.rb +15 -0
- data/lib/metro/models/ui/tmx/tile_layer.rb +78 -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 +478 -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 +148 -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 +95 -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 +43 -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/tmx_ext/object.rb +26 -0
- data/lib/tmx_ext/tile_set.rb +41 -0
- data/metro.gemspec +57 -0
- data/metro.png +0 -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/image_spec.rb +33 -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/units/rectangle_bounds_spec.rb +56 -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
- data/spec/tmx_ext/object_spec.rb +96 -0
- data/spec/tmx_ext/tile_set_spec.rb +24 -0
- metadata +379 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metro::Image do
|
4
|
+
|
5
|
+
describe "Class Methods" do
|
6
|
+
|
7
|
+
let(:subject) { described_class }
|
8
|
+
|
9
|
+
describe ".crop" do
|
10
|
+
|
11
|
+
let(:image) { stub('Original Image') }
|
12
|
+
let(:window) { stub('Gosu::Window') }
|
13
|
+
let(:mock_image) { mock("TexPlay Created Image",refresh_cache: nil) }
|
14
|
+
let(:bounds) { Metro::Units::RectangleBounds.new(left: 2,top: 2,right: 30,bottom:30) }
|
15
|
+
|
16
|
+
let(:expected_crop_params) { [ bounds.left, bounds.top, bounds.right, bounds.bottom ]}
|
17
|
+
|
18
|
+
it "crops the image with the bounds provided" do
|
19
|
+
TexPlay.should_receive(:create_image).and_return(mock_image)
|
20
|
+
mock_image.should_receive(:splice).with(image,0,0,crop: expected_crop_params)
|
21
|
+
|
22
|
+
subject.crop(window,image,bounds)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "refreshes the cache for the image so when Metro reloads the images are not corrupt" do
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
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
|
@@ -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
|