metro 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ module Metro
2
+ module UI
3
+
4
+ #
5
+ # The model labeler will draw a bounding box and label around all the
6
+ # scene's drawers.
7
+ #
8
+ # The model labeler is used in the edit transition scene to generate
9
+ # the bounding boxes and labeles around all the actors within the scene
10
+ # being edited.
11
+ #
12
+ class ModelLabeler < Metro::Model
13
+
14
+ # @attribute
15
+ # The color use for the border surrounding each actor and the background
16
+ # behind the model's name.
17
+ property :color, default: "rgba(255,0,0,0.5)"
18
+
19
+ # @attribute
20
+ # Sets whether to draw the bounding boxes around the actors.
21
+ property :should_draw_bounding_boxes, type: :boolean, default: true
22
+
23
+ # @attribute
24
+ # The color of the model name text.
25
+ property :label_color, default: "rgba(255,255,255,1.0)"
26
+
27
+ # @attribute
28
+ # The font of the model name label.
29
+ property :font, default: { name: 'Arial', size: 16 }
30
+
31
+ # @attribute
32
+ # Sets whether to draw the model name labels
33
+ property :should_draw_labels, type: :boolean, default: true
34
+
35
+ # @attribute
36
+ # For actors that have no bounds, like sound or custom models without
37
+ # a position, they are normally hidden but can be shown. Currently they
38
+ # appear all overlapped in the upper-left corner of the screen.
39
+ #
40
+ # @todo when enabled the boundless actors should be presented in a cleaner
41
+ # way to allow for easier viewing of them.
42
+ property :should_hide_boundless_actors, type: :boolean, default: true
43
+
44
+ # Store the labels that are being drawn in the scene. This hash of labels
45
+ # acts as a cache around the items that are being labeled based on the
46
+ # name of the objects that are being labeled.
47
+ def labels
48
+ @labels ||= {}
49
+ end
50
+
51
+ def show
52
+ self.saveable_to_view = false
53
+ end
54
+
55
+ def update
56
+ scene.drawers.each do |drawer|
57
+ next if (drawer.bounds == Bounds.none and should_hide_boundless_actors)
58
+ label = labels[drawer.name]
59
+
60
+ unless label
61
+ label = create "metro::ui::modellabel", target: drawer
62
+ labels[drawer.name] = label
63
+ end
64
+
65
+ label.should_draw_label = should_draw_labels
66
+ label.should_draw_bounding_box = should_draw_bounding_boxes
67
+ label.bounds = drawer.bounds
68
+ end
69
+
70
+ end
71
+
72
+ def draw
73
+ labels.values.each { |label| label.draw }
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+ end
@@ -14,10 +14,16 @@ module Metro
14
14
  #
15
15
  class Rectangle < ::Metro::Model
16
16
 
17
+ # @attribute
18
+ # The position of the upper-left corner of the rectangle
17
19
  property :position
18
20
 
21
+ # @attribute
22
+ # The color to rectangle
19
23
  property :color
20
24
 
25
+ # @attribute
26
+ # The dimensions of the rectangle
21
27
  property :dimensions do
22
28
  window.dimensions
23
29
  end
@@ -513,7 +513,7 @@ module Metro
513
513
  # @return a hash of all the drawers
514
514
  #
515
515
  def to_hash
516
- drawn = drawers.find_all{|draw| draw.saveable? }.inject({}) do |hash,drawer|
516
+ drawn = drawers.find_all{|draw| draw.saveable_to_view }.inject({}) do |hash,drawer|
517
517
  drawer_hash = drawer.to_hash
518
518
  hash.merge drawer_hash
519
519
  end
@@ -2,6 +2,19 @@ require_relative '../events/hit_list'
2
2
 
3
3
  module Metro
4
4
 
5
+ #
6
+ # The Edit Transition Scene is place where scenes go to be edited. Any scene
7
+ # can transition into edit mode. This scene will copy all the actors and
8
+ # gain access to the view.
9
+ #
10
+ # This scene grants new keyboard commands that will enable, disable, and
11
+ # toggle feature of edit mode:
12
+ #
13
+ # * `e` will end edit mode
14
+ # * `g` will toggle the display of the grid
15
+ # * `l` will toggle the display of the model labels
16
+ # * `b` will toggle the bounding boxes around the models.
17
+ #
5
18
  class EditTransitionScene < Metro::TransitionScene
6
19
 
7
20
  def initialize
@@ -15,7 +28,8 @@ module Metro
15
28
  # easier to dup scenes.
16
29
  #
17
30
  self.class.drawings.clear
18
- self.class.draw :overlay, model: "Metro::UI::GridDrawer"
31
+ self.class.draw :overlay, model: "metro::ui::griddrawer"
32
+ self.class.draw :labeler, model: "metro::ui::modellabeler"
19
33
  add_actors_to_scene
20
34
  after_initialize
21
35
  end
@@ -44,6 +58,18 @@ module Metro
44
58
  transition_to next_scene.scene_name
45
59
  end
46
60
 
61
+ event :on_up, KbG do
62
+ overlay.enabled = !overlay.enabled
63
+ end
64
+
65
+ event :on_up, KbL do
66
+ labeler.should_draw_labels = !labeler.should_draw_labels
67
+ end
68
+
69
+ event :on_up, KbB do
70
+ labeler.should_draw_bounding_boxes = !labeler.should_draw_bounding_boxes
71
+ end
72
+
47
73
  #
48
74
  # Generate a hitlist which manages the click start, hold, and release
49
75
  # of the mouse button.
@@ -65,6 +91,7 @@ module Metro
65
91
  end
66
92
 
67
93
  event :on_up, KbS do
94
+ log.info "Saving changes to Scene #{previous_scene} View - #{view_name}"
68
95
  save_view
69
96
  end
70
97
 
@@ -19,7 +19,7 @@ module Metro
19
19
  # two attributes width and height.
20
20
  #
21
21
  def self.parse(string)
22
- of *string.split(",",2).map(&:to_f)
22
+ of *string.to_s.split(",",2).map(&:to_f)
23
23
  end
24
24
 
25
25
 
@@ -28,7 +28,7 @@ module Metro
28
28
  # will enforce that the values added are converted to floating
29
29
  # point numbers.
30
30
  #
31
- def self.of(width,height)
31
+ def self.of(width=0.0,height=0.0)
32
32
  new width.to_f, height.to_f
33
33
  end
34
34
 
@@ -36,6 +36,33 @@ module Metro
36
36
  "#{width},#{height}"
37
37
  end
38
38
 
39
+ #
40
+ # Add the dimensions to another dimensions-like structure. A
41
+ # dimensions like structure is anything that responds to width and height.
42
+ #
43
+ # @return a new dimensions which is the sum of the two dimensions
44
+ #
45
+ def +(value)
46
+ raise "Unable to add dimension to #{value} #{value.class}" if [ :width, :height ].find { |method| ! value.respond_to?(method) }
47
+ self.class.of (width + value.width.to_f), (height + value.height.to_f)
48
+ end
49
+
50
+ #
51
+ # Subtract the dimensions-like structure from this dimension. A
52
+ # dimensions like structure is anything that responds to width and height.
53
+ #
54
+ # @return a new dimensions which is the different of the two dimensions
55
+ #
56
+ def -(value)
57
+ raise "Unable to subtract from these dimensions with #{value} #{value.class}" if [ :width, :height ].find { |method| ! value.respond_to?(method) }
58
+ self.class.of (width - value.width.to_f), (height - value.height.to_f)
59
+ end
60
+
61
+ def <=>(value)
62
+ raise "Unable to subtract from these dimensions with #{value} #{value.class}" if [ :width, :height ].find { |method| ! value.respond_to?(method) }
63
+ (width * height) <=> (value.width * value.height)
64
+ end
65
+
39
66
  end
40
67
  end
41
68
  end
@@ -40,14 +40,26 @@ module Metro
40
40
  end
41
41
 
42
42
  #
43
- # Add the point to another point-like structure. Anything that also has
44
- # the methods x, y, and z.
43
+ # Add this point to another another point-like structure. A point like structure
44
+ # is anything has the methods x, y, and z.
45
45
  #
46
46
  # @return a new point which is the sum of the point and the provided value.
47
47
  #
48
48
  def +(value)
49
- raise "Unabled to add point to #{value} #{value.class}" if [ :x, :y, :z ].find { |method| ! value.respond_to?(method) }
50
- self.class.at((x + value.x),(y + value.y),(z + value.z))
49
+ raise "Unable to add point to #{value} #{value.class}" if [ :x, :y, :z ].find { |method| ! value.respond_to?(method) }
50
+ self.class.at (x + value.x.to_f), (y + value.y.to_f), (z + value.z.to_f)
51
+ end
52
+
53
+ #
54
+ # Subtract the point-like structure from this point. A point like structure
55
+ # is anything has the methods x, y, and z.
56
+ #
57
+ # @return a new point which is the difference of the point and the
58
+ # provided value.
59
+ #
60
+ def -(value)
61
+ raise "Unable to subtract from this point with #{value} #{value.class}" if [ :x, :y, :z ].find { |method| ! value.respond_to?(method) }
62
+ self.class.at (x - value.x.to_f), (y - value.y.to_f), (z - value.z.to_f)
51
63
  end
52
64
 
53
65
  end
@@ -4,46 +4,68 @@ module Metro
4
4
  #
5
5
  # An object that represents a rectanglar bounds.
6
6
  #
7
- class RectangleBounds < Struct.new(:min_x,:min_y,:max_x,:max_y)
7
+ class RectangleBounds
8
8
 
9
9
  # Allow the ability to refer to the min, max values with their
10
10
  # other alternate names.
11
11
 
12
- alias_method :left, :min_x
13
- alias_method :left=, :min_x=
14
- alias_method :right, :max_x
15
- alias_method :right=, :max_x=
16
- alias_method :top, :min_y
17
- alias_method :top=, :min_y=
18
- alias_method :bottom, :max_y
19
- alias_method :bottom=, :max_y=
12
+ attr_accessor :left, :right, :top, :bottom
13
+
14
+ def self.none
15
+ new left: 0, right: 0, top: 0, bottom: 0
16
+ end
20
17
 
21
18
  #
22
19
  # Create a bounds with bounds.
23
20
  #
24
21
  def initialize(params = {})
25
- self.min_x = params[:x] || params[:min_x]
26
- self.min_y = params[:y] || params[:min_y]
27
- self.max_x = (params[:max_x] || (min_x + params[:width]))
28
- self.max_y = (params[:max_y] || (min_y + params[:height]))
22
+ @left = params[:left].to_f
23
+ @top = params[:top].to_f
24
+ @right = params[:right].to_f
25
+ @bottom = params[:bottom].to_f
26
+ end
27
+
28
+ def top_left
29
+ Point.at(left,top)
30
+ end
31
+
32
+ def top_right
33
+ Point.at(right,top)
34
+ end
35
+
36
+ def bottom_right
37
+ Point.at(right,bottom)
38
+ end
39
+
40
+ def bottom_left
41
+ Point.at(left,bottom)
42
+ end
43
+
44
+ def dimensions
45
+ Dimensions.of (right - left), (bottom - top)
46
+ end
47
+
48
+ def ==(value)
49
+ return if [ :left, :right, :top, :bottom ].find { |method| ! value.respond_to?(method) }
50
+ left == value.left and right == value.right and top == value.top and bottom == value.bottom
29
51
  end
30
52
 
31
53
  #
32
54
  # Does this bounds contain the following point?
33
55
  #
34
56
  def contains?(x,y)
35
- x > min_x and x < max_x and y > min_y and y < max_y
57
+ x > left and x < right and y > top and y < bottom
36
58
  end
37
59
 
38
60
  #
39
61
  # Does this rectanglular bounds intersect with another rectanglular bounds?
40
62
  #
41
63
  def intersect?(b)
42
- not(b.min_x > max_x or b.max_x < min_x or b.min_y > max_y or b.max_y < min_y)
64
+ not(b.left > right or b.right < left or b.top > bottom or b.bottom < top)
43
65
  end
44
66
 
45
67
  def to_s
46
- "(#{min_x},#{min_y}) to (#{max_x},#{max_y})"
68
+ "(#{left},#{top}) to (#{right},#{bottom})"
47
69
  end
48
70
 
49
71
  end
@@ -1,5 +1,5 @@
1
1
  module Metro
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  WEBSITE = "https://github.com/burtlo/metro"
4
4
  CONTACT_EMAILS = ["dev@rubymetro.com"]
5
5
 
@@ -64,9 +64,14 @@ module Metro
64
64
  def reload_game_because_files_changed(changed)
65
65
  log.debug "Metro has detected #{changed.count} game source #{changed.count != 1 ? 'files have' : 'file has'} changed. RELOADING GAME CODE!"
66
66
  if Metro.game_has_valid_code?
67
- Game.current_scene.after(1.tick) { Metro.reload! ; transition_to(scene_name) }
67
+ Game.current_scene.after(1.tick) do
68
+ Metro.reload!
69
+ scene_is_being_edited = scene_name == "metro/edit_transition"
70
+ transition_to(scene_name) unless scene_is_being_edited
71
+ end
68
72
  end
69
73
  end
74
+
70
75
  end
71
76
  end
72
77
 
@@ -1,4 +1,8 @@
1
1
  class FirstScene < GameScene
2
+
3
+ if Game.debug?
4
+ draw :fps, model: "metro::ui::fps", placement: 'bottom_right'
5
+ end
2
6
 
3
7
  draw :hero, position: Game.center
4
8
 
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.3.2
4
+ version: 0.3.3
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-26 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gosu
@@ -182,6 +182,7 @@ files:
182
182
  - lib/metro/models/properties/dimensions_property.rb
183
183
  - lib/metro/models/properties/font_property.rb
184
184
  - lib/metro/models/properties/image_property.rb
185
+ - lib/metro/models/properties/model_property.rb
185
186
  - lib/metro/models/properties/numeric_property.rb
186
187
  - lib/metro/models/properties/options_property/no_option.rb
187
188
  - lib/metro/models/properties/options_property/options.rb
@@ -193,11 +194,15 @@ files:
193
194
  - lib/metro/models/properties/scale_property.rb
194
195
  - lib/metro/models/properties/song_property.rb
195
196
  - lib/metro/models/properties/text_property.rb
197
+ - lib/metro/models/ui/border.rb
198
+ - lib/metro/models/ui/fps.rb
196
199
  - lib/metro/models/ui/generic.rb
197
200
  - lib/metro/models/ui/grid_drawer.rb
198
201
  - lib/metro/models/ui/image.rb
199
202
  - lib/metro/models/ui/label.rb
200
203
  - lib/metro/models/ui/menu.rb
204
+ - lib/metro/models/ui/model_label.rb
205
+ - lib/metro/models/ui/model_labeler.rb
201
206
  - lib/metro/models/ui/rectangle.rb
202
207
  - lib/metro/parameters/command_line_args_parser.rb
203
208
  - lib/metro/parameters/options.rb
@@ -279,12 +284,13 @@ licenses:
279
284
  post_install_message: ! " ______ ___ _____\n ___ |/ /_____ __ /_______________\n
280
285
  \ __ /|_/ / _ _ \\_ __/__ ___/_ __ \\\n _ / / / / __// /_ _ / /
281
286
  /_/ /\n /_/ /_/ \\___/ \\__/ /_/ \\____/\n\n Thank you for installing
282
- metro 0.3.2 / 2012-11-26.\n ---------------------------------------------------------------------\n
283
- \ Changes:\n \n * Debug Mode will now automatically reload the game and scene
284
- on source\n file changes.\n * Reloading the game will no longer take down the
285
- app for syntax errors\n and other errors that are easily detected by simply loading
286
- the code.\n * Template game is now automatically has debug mode enabled by default\n
287
- \ \n\n ---------------------------------------------------------------------\n"
287
+ metro 0.3.3 / 2012-11-28.\n ---------------------------------------------------------------------\n
288
+ \ Changes:\n \n * Edit Mode - actors within a scene can have their position
289
+ edited\n and saved. Actors within the scene that have a valid bounds\n specified
290
+ will appear within the scene with name and bounding box.\n * Dimensions can now
291
+ be defined as strings\n * Game bounds and Game dimensions return objects of that
292
+ type\n * `metr::ui::fps` added and has some shortcut placements settings\n \n\n
293
+ \ ---------------------------------------------------------------------\n"
288
294
  rdoc_options: []
289
295
  require_paths:
290
296
  - lib