metro 0.2.0 → 0.2.1

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.
data/changelog.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Metro
2
2
 
3
+ ## 0.2.1 / 2012-11-08
4
+
5
+ * FIX Scene fade transition color changing and implicit animations
6
+ for colors
7
+ * Games creating custom properties will appear in the property list
8
+ * Properties now correctly default to numeric properties
9
+ * Point objects can be added to other point objects.
10
+
3
11
  ## 0.2.0 / 2012-11-07
4
12
 
5
13
  * Views now use position instead of `x`, `y`, and `z-order`
data/lib/metro.rb CHANGED
@@ -128,7 +128,7 @@ module Metro
128
128
  def load_path(path,options = {})
129
129
  files = Dir["#{path}/**/*.rb"]
130
130
  files.sort! {|file| File.basename(file) == options[:prioritize] ? -1 : 1 }
131
- files.each {|model| require_or_load model }
131
+ files.each {|file| require_or_load file }
132
132
  end
133
133
 
134
134
  def load_game_configuration(filename)
@@ -55,11 +55,14 @@ module Metro
55
55
 
56
56
  if attribute == :color
57
57
  final = Gosu::Color.new final
58
+
59
+ # @TODO: This is not going to work when the color uses a non-standard
60
+ # name for the color property.
58
61
 
59
- animations.push build_animation_step(:"color.red",start.red,final.red)
60
- animations.push build_animation_step(:"color.green",start.green,final.green)
61
- animations.push build_animation_step(:"color.blue",start.blue,final.blue)
62
- animations.push build_animation_step(:"color.alpha",start.alpha,final.alpha)
62
+ animations.push build_animation_step(:red,start.red,final.red)
63
+ animations.push build_animation_step(:green,start.green,final.green)
64
+ animations.push build_animation_step(:blue,start.blue,final.blue)
65
+ animations.push build_animation_step(:alpha,start.alpha,final.alpha)
63
66
  else
64
67
  animations.push build_animation_step(attribute,start,final)
65
68
  end
@@ -89,11 +92,11 @@ module Metro
89
92
  #
90
93
  def stepping(stepping)
91
94
  @steppings ||= begin
92
- hash = Hash.new(Easing::Linear)
93
- hash.merge! linear: Easing::Linear,
94
- ease_in: Easing::EaseIn
95
+ hash = HashWithIndifferentAccess.new("Metro::Easing::Linear")
96
+ hash.merge! linear: "Metro::Easing::Linear",
97
+ ease_in: "Metro::Easing::EaseIn"
95
98
  end
96
- @steppings[stepping]
99
+ @steppings[stepping].constantize
97
100
  end
98
101
 
99
102
  #
@@ -9,7 +9,7 @@ module Metro
9
9
  # All defined events within this dictionary.
10
10
  #
11
11
  def events
12
- @events ||= Hash.new
12
+ @events ||= HashWithIndifferentAccess.new
13
13
  end
14
14
 
15
15
  #
@@ -89,7 +89,7 @@ module Metro
89
89
  @up_actions ||= {}
90
90
  @down_actions ||= {}
91
91
  @held_actions ||= {}
92
- @custom_notifications ||= Hash.new([])
92
+ @custom_notifications ||= HashWithIndifferentAccess.new([])
93
93
  end
94
94
 
95
95
  attr_reader :target, :window
@@ -275,13 +275,12 @@ module Metro
275
275
  def self.model(name)
276
276
  @models_hash ||= begin
277
277
 
278
- hash = Hash.new("Metro::Models::Generic")
278
+ hash = HashWithIndifferentAccess.new("Metro::Models::Generic")
279
279
 
280
280
  models.each do |model|
281
- common_name = model.to_s.underscore
282
281
  hash[model.to_s] = model
283
282
  hash[model.downcase] = model
284
- hash[common_name] = model
283
+ hash[model.to_s.underscore] = model
285
284
  end
286
285
 
287
286
  hash
@@ -56,6 +56,9 @@ module Metro
56
56
  class ColorProperty < Property
57
57
 
58
58
  define_property :alpha
59
+ define_property :red
60
+ define_property :green
61
+ define_property :blue
59
62
 
60
63
  # By default convert the value to the default color if it
61
64
  # cannot be processed by the other get filters.
@@ -1,5 +1,3 @@
1
- require_relative 'text'
2
-
3
1
  module Metro
4
2
  class Model
5
3
 
@@ -3,7 +3,7 @@ module Metro
3
3
 
4
4
  class Property
5
5
  include Units
6
-
6
+
7
7
  attr_reader :model, :options
8
8
 
9
9
  def initialize(model,options={})
@@ -13,7 +13,7 @@ module Metro
13
13
 
14
14
  def self.gets
15
15
  @gets ||= begin
16
- hash = Hash.new { |hash,key| hash["NilClass"] }
16
+ hash = HashWithIndifferentAccess.new { |hash,key| hash["NilClass"] }
17
17
  hash["NilClass"] = lambda { |value| raise "#{self} is not able to translate the #{value} (#{value.class})" }
18
18
  hash
19
19
  end
@@ -30,7 +30,7 @@ module Metro
30
30
 
31
31
  def self.sets
32
32
  @sets ||= begin
33
- hash = Hash.new { |hash,key| hash["NilClass"] }
33
+ hash = HashWithIndifferentAccess.new { |hash,key| hash["NilClass"] }
34
34
  hash["NilClass"] = lambda { |value| raise "#{self} is not able to translate the #{value} (#{value.class})" }
35
35
  hash
36
36
  end
@@ -59,7 +59,8 @@ module Metro
59
59
  end
60
60
 
61
61
  def self.inherited(subclass)
62
- properties << subclass
62
+ property_name = subclass.to_s.gsub(/Property$/,'').split("::").last.underscore
63
+ properties_hash[property_name] = subclass.to_s
63
64
  end
64
65
 
65
66
  def self.properties
@@ -67,21 +68,12 @@ module Metro
67
68
  end
68
69
 
69
70
  def self.property(name)
70
- properties_hash[name]
71
+ property_classname = properties_hash[name]
72
+ property_classname.constantize
71
73
  end
72
74
 
73
75
  def self.properties_hash
74
- @properties_hash ||= begin
75
- hash = ActiveSupport::HashWithIndifferentAccess.new(NumericProperty)
76
- # TODO: do not store classes within the structure - this will misbehave on reloading
77
- properties.each do |prop|
78
- prop_name = prop.to_s.gsub(/Property$/,'').split("::").last.underscore
79
- hash[prop_name] = prop
80
- hash[prop_name.to_sym] = prop
81
- end
82
- # puts hash
83
- hash
84
- end
76
+ @properties_hash ||= ActiveSupport::HashWithIndifferentAccess.new { |hash,key| hash[:numeric] }
85
77
  end
86
78
 
87
79
  end
@@ -100,14 +92,13 @@ module Metro
100
92
 
101
93
  end
102
94
 
103
- require_relative 'angle'
104
- require_relative 'animation'
105
- require_relative 'color'
106
- require_relative 'dimensions'
107
- require_relative 'font'
108
- require_relative 'image'
109
- require_relative 'numeric'
110
- require_relative 'position'
111
- require_relative 'scale'
112
- require_relative 'text'
113
- require_relative 'velocity'
95
+ require_relative 'numeric_property'
96
+ require_relative 'text_property'
97
+
98
+ require_relative 'animation_property'
99
+ require_relative 'color_property'
100
+ require_relative 'dimensions_property'
101
+ require_relative 'font_property'
102
+ require_relative 'image_property'
103
+ require_relative 'position_property'
104
+ require_relative 'scale_property'
@@ -26,7 +26,7 @@ module Metro
26
26
 
27
27
  def supported_transitions
28
28
  @supported_transitions ||= begin
29
- hash = Hash.new("Metro::FadeTransitionScene")
29
+ hash = HashWithIndifferentAccess.new("Metro::FadeTransitionScene")
30
30
  hash[:edit] = "Metro::EditTransitionScene"
31
31
  hash
32
32
  end
@@ -20,6 +20,11 @@ module Metro
20
20
  "#{x},#{y},#{z}"
21
21
  end
22
22
 
23
+ def +(value)
24
+ raise "Unabled to add point to #{value} #{value.class}" if [ :x, :y, :z ].find { |method| ! value.respond_to?(method) }
25
+ self.class.new((x + value.x),(y + value.y),(z + value.z))
26
+ end
27
+
23
28
  end
24
29
  end
25
30
  end
data/lib/metro/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metro
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  WEBSITE = "https://github.com/burtlo/metro"
4
4
  CONTACT_EMAILS = ["franklin.webber@gmail.com"]
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gosu
@@ -156,18 +156,16 @@ files:
156
156
  - lib/metro/models/models/label.rb
157
157
  - lib/metro/models/models/menu.rb
158
158
  - lib/metro/models/models/rectangle.rb
159
- - lib/metro/models/properties/angle.rb
160
- - lib/metro/models/properties/animation.rb
161
- - lib/metro/models/properties/color.rb
162
- - lib/metro/models/properties/dimensions.rb
163
- - lib/metro/models/properties/font.rb
164
- - lib/metro/models/properties/image.rb
165
- - lib/metro/models/properties/numeric.rb
166
- - lib/metro/models/properties/position.rb
159
+ - lib/metro/models/properties/animation_property.rb
160
+ - lib/metro/models/properties/color_property.rb
161
+ - lib/metro/models/properties/dimensions_property.rb
162
+ - lib/metro/models/properties/font_property.rb
163
+ - lib/metro/models/properties/image_property.rb
164
+ - lib/metro/models/properties/numeric_property.rb
165
+ - lib/metro/models/properties/position_property.rb
167
166
  - lib/metro/models/properties/property.rb
168
- - lib/metro/models/properties/scale.rb
169
- - lib/metro/models/properties/text.rb
170
- - lib/metro/models/properties/velocity.rb
167
+ - lib/metro/models/properties/scale_property.rb
168
+ - lib/metro/models/properties/text_property.rb
171
169
  - lib/metro/models/rectangle_bounds.rb
172
170
  - lib/metro/scene.rb
173
171
  - lib/metro/scenes.rb
@@ -225,13 +223,11 @@ licenses: []
225
223
  post_install_message: ! " ______ ___ _____\n ___ |/ /_____ __ /_______________\n
226
224
  \ __ /|_/ / _ _ \\_ __/__ ___/_ __ \\\n _ / / / / __// /_ _ / /
227
225
  /_/ /\n /_/ /_/ \\___/ \\__/ /_/ \\____/\n\n Thank you for installing
228
- metro 0.2.0 / 2012-11-07.\n ---------------------------------------------------------------------\n
229
- \ Changes:\n \n * Views now use position instead of `x`, `y`, and `z-order`\n
230
- \ * Point, Scale, and Dimensions is available in model and scenes.\n * Events are
231
- shared from superclasses to subclases.\n * Templates updated to use GameScene and
232
- GameModel for each game.\n * Models are automatically added to the update loop\n
233
- \ * Model properties now make it easier to store/retrieve various\n common numeric,
234
- position font, image, and animation properties.\n \n \n\n ---------------------------------------------------------------------\n"
226
+ metro 0.2.1 / 2012-11-08.\n ---------------------------------------------------------------------\n
227
+ \ Changes:\n \n * FIX Scene fade transition color changing and implicit animations
228
+ \n for colors\n * Games creating custom properties will appear in the property
229
+ list\n * Properties now correctly default to numeric properties\n * Point objects
230
+ can be added to other point objects. \n \n\n ---------------------------------------------------------------------\n"
235
231
  rdoc_options: []
236
232
  require_paths:
237
233
  - lib
@@ -1,43 +0,0 @@
1
- module Metro
2
- class Model
3
-
4
- class AngleProperty < Property
5
-
6
- def get(value)
7
- value ? value : Angle.new(0.0, options[:step])
8
- end
9
-
10
- def set(value)
11
- Angle.new(value.to_f, options[:step])
12
- end
13
-
14
- class Angle
15
-
16
- attr_reader :value
17
-
18
- def initialize(value = 0.0,step = 1.0)
19
- @value = value.to_f
20
- @step = step || 1.0
21
- end
22
-
23
- def turn(direction)
24
- send(direction) if [ :left, :right ].include?(direction)
25
- end
26
-
27
- def left
28
- @value -= @step
29
- end
30
-
31
- def right
32
- @value += @step
33
- end
34
-
35
- def to_f
36
- @value.to_f
37
- end
38
-
39
- end
40
-
41
- end
42
- end
43
- end
@@ -1,80 +0,0 @@
1
- module Metro
2
- class Model
3
-
4
- class VectorProperty < Property
5
-
6
- def get(value)
7
- value ? value : Vector.new
8
- end
9
-
10
- def set(value)
11
- Vector.new value
12
- end
13
-
14
- class Vector
15
-
16
- def initialize(angle,velocity)
17
- @angle = angle
18
- @velocity = velocity
19
- end
20
-
21
- def decay!
22
- @velocity.decay!
23
- end
24
-
25
- def accelerate(amount,angle)
26
-
27
- end
28
-
29
- def apply_x(x_position)
30
-
31
- end
32
-
33
- def apply_y(y_position)
34
-
35
- end
36
-
37
-
38
- end
39
-
40
- end
41
-
42
- class VelocityProperty < Property
43
-
44
- def get(value)
45
- value ? value : Velocity.new(0.0,0.95)
46
- end
47
-
48
- def set(value)
49
- Velocity.new value
50
- end
51
-
52
- class Velocity
53
-
54
- def initialize(value,decay = default_decay)
55
- @value = value.to_f
56
- @decay = decay || default_decay
57
- end
58
-
59
- def default_decay
60
- 0.95
61
- end
62
-
63
- def decay
64
- @value *= @decay
65
- end
66
-
67
- def accelerate(amount)
68
- @value += amount
69
- end
70
-
71
- def to_f
72
- @value
73
- end
74
-
75
- end
76
-
77
- end
78
-
79
- end
80
- end