metro 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ module Metro
2
+ class SceneActor
3
+
4
+ attr_reader :name, :options
5
+
6
+ def initialize(name,options)
7
+ @name = name.to_s.downcase
8
+ @options = options
9
+ end
10
+
11
+ def create(contents = {})
12
+ contents = {} unless contents
13
+ actor_instance = class_for_actor(contents['model']).new
14
+ actor_instance._load(contents)
15
+ actor_instance
16
+ end
17
+
18
+ def load_from_previous_scene?
19
+ options[:from] == :previous_scene
20
+ end
21
+
22
+ def class_for_actor(model_name)
23
+ Model.model(model_name || name)
24
+ end
25
+ end
26
+ end
@@ -2,9 +2,6 @@ require_relative 'yaml_view'
2
2
  require_relative 'json_view'
3
3
  require_relative 'no_view'
4
4
 
5
- require_relative 'drawers/drawer'
6
- require_relative 'drawers/composite_drawer'
7
-
8
5
  module Metro
9
6
 
10
7
  #
@@ -15,23 +12,17 @@ module Metro
15
12
 
16
13
  #
17
14
  # When the module is included insure that all the class helper methods are added
18
- # at the same time. As well as re-defining the {Scene#base_draw} method to allow
19
- # for the use of the view_drawer.
15
+ # at the same time.
20
16
  #
21
17
  def self.included(base)
22
18
  base.extend ClassMethods
23
-
24
- base.send :define_method, :base_draw do
25
- view_drawer.draw(view)
26
- draw
27
- end
28
19
  end
29
20
 
30
21
  #
31
22
  # Supported view formats
32
23
  #
33
24
  def _view_parsers
34
- [ YAMLView, JSONView, NoView ]
25
+ self.class._view_parsers
35
26
  end
36
27
 
37
28
  #
@@ -41,21 +32,7 @@ module Metro
41
32
  # @return a Hash of view content.
42
33
  #
43
34
  def view
44
- @view ||= begin
45
- parser = _view_parsers.find { |parser| parser.exists? self.class.view_name }
46
- parser.parse self.class.view_name
47
- end
48
- end
49
-
50
- #
51
- # @return an instance of a SceneView::Drawer that is capable of drawing
52
- # the Scene.
53
- def view_drawer
54
- @view_drawer ||= begin
55
- drawer = SceneView::CompositeDrawer.new(self)
56
- drawer.draw_debug = Game.debug?
57
- drawer
58
- end
35
+ self.class.view
59
36
  end
60
37
 
61
38
  module ClassMethods
@@ -69,7 +46,7 @@ module Metro
69
46
  # class ClosingScene < Metro::Scene
70
47
  # view_name 'alternative'
71
48
  # end
72
- #
49
+ #
73
50
  # ClosingScene.view_name # => views/alternative
74
51
  #
75
52
  def view_name(filename = nil)
@@ -80,6 +57,26 @@ module Metro
80
57
  end
81
58
  end
82
59
 
60
+ #
61
+ # Supported view formats
62
+ #
63
+ def _view_parsers
64
+ [ YAMLView, JSONView, NoView ]
65
+ end
66
+
67
+ #
68
+ # Loads and caches the view content based on the avilable view parsers and
69
+ # the view files defined.
70
+ #
71
+ # @return a Hash of view content.
72
+ #
73
+ def view
74
+ @view ||= begin
75
+ parser = _view_parsers.find { |parser| parser.exists? view_name }
76
+ parser.parse view_name
77
+ end
78
+ end
79
+
83
80
  end
84
81
 
85
82
  end
data/lib/metro/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Metro
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/metro/window.rb CHANGED
@@ -35,7 +35,7 @@ module Metro
35
35
  #
36
36
  def update
37
37
  scene.fire_events_for_held_buttons
38
- scene.update
38
+ scene.base_update
39
39
  end
40
40
 
41
41
  #
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.0.3
4
+ version: 0.0.5
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-10-19 00:00:00.000000000 Z
12
+ date: 2012-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gosu
@@ -41,6 +41,7 @@ files:
41
41
  - README.md
42
42
  - Rakefile
43
43
  - bin/metro
44
+ - lib/gosu_ext/color.rb
44
45
  - lib/metro.rb
45
46
  - lib/metro/animation/animation.rb
46
47
  - lib/metro/animation/easing.rb
@@ -48,14 +49,13 @@ files:
48
49
  - lib/metro/event_relay.rb
49
50
  - lib/metro/game.rb
50
51
  - lib/metro/game/dsl.rb
51
- - lib/metro/model.rb
52
+ - lib/metro/models/generic.rb
53
+ - lib/metro/models/image.rb
54
+ - lib/metro/models/label.rb
55
+ - lib/metro/models/model.rb
56
+ - lib/metro/models/select.rb
52
57
  - lib/metro/scene.rb
53
- - lib/metro/scene_view/drawers/artists_block.rb
54
- - lib/metro/scene_view/drawers/composite_drawer.rb
55
- - lib/metro/scene_view/drawers/drawer.rb
56
- - lib/metro/scene_view/drawers/image.rb
57
- - lib/metro/scene_view/drawers/label.rb
58
- - lib/metro/scene_view/drawers/select.rb
58
+ - lib/metro/scene_actor.rb
59
59
  - lib/metro/scene_view/json_view.rb
60
60
  - lib/metro/scene_view/no_view.rb
61
61
  - lib/metro/scene_view/scene_view.rb
data/lib/metro/model.rb DELETED
@@ -1,12 +0,0 @@
1
- module Metro
2
- class Model
3
-
4
- def initialize(window)
5
- after_initialize
6
- end
7
-
8
- def after_initialize
9
- end
10
-
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- module Metro
2
- module SceneView
3
-
4
- #
5
- # This Drawer draws nothing. This is a nod to the age old struggle that
6
- # as artists we struggle with the impetus and ability to convey a message
7
- # but simply lack the message.
8
- #
9
- # It is the fallback drawer when no suitable drawer can be found.
10
- #
11
- class ArtistsBlock < Drawer
12
- def self.draw(view)
13
- # log.warn "The component #{view['type']} does not have a supported drawer."
14
- end
15
- end
16
- end
17
- end
@@ -1,87 +0,0 @@
1
- require_relative 'artists_block'
2
- require_relative 'label'
3
- require_relative 'select'
4
- require_relative 'image'
5
-
6
- module Metro
7
- module SceneView
8
-
9
- #
10
- # The CompositeDrawer is a special drawer that looks at all the created drawers
11
- # that have been defined and then determines which one should be used when drawing
12
- # for a particular view type.
13
- #
14
- # This Drawer is used in the SceneView to handle the multitude of view objects
15
- # that are thrown at it.
16
- #
17
- # @see SceneView
18
- #
19
- class CompositeDrawer < Drawer
20
-
21
- attr_accessor :draw_debug
22
-
23
- #
24
- # Render all the view elements defined that are supported by this drawer.
25
- #
26
- def draw(view)
27
- view.each do |name,content|
28
- type = content['type']
29
-
30
- if not content.key?('debug') or (content['debug'] and draw_debug)
31
- drawers[type].draw(content.merge 'name' => name)
32
- end
33
-
34
- end
35
- end
36
-
37
- #
38
- # Given all the registered drawers map the things that they can draw
39
- # to the particular drawer.
40
- #
41
- # @return a Hash which maps the types of things that can be drawn to
42
- # the specific drawer.
43
- #
44
- def drawers
45
- @drawers ||= begin
46
-
47
- # By default fall back to having artist's block when you do not know
48
- # how to draw a particular view component.
49
-
50
- hash = Hash.new(ArtistsBlock)
51
-
52
- Drawer.drawers.each do |drawer|
53
- drawer.draws_types.each do |type|
54
-
55
- if not hash.key?(type) or (hash.key?(type) and override_on_conflict?(drawer,type))
56
- hash[type] = drawer.new(scene)
57
- end
58
-
59
- end
60
- end
61
-
62
- hash
63
- end
64
- end
65
-
66
- #
67
- # @return true if the drawer should override the existing drawer, false if the drawer
68
- # should leave the existing drawer in it's place.
69
- #
70
- def override_on_conflict?(drawer,type)
71
- if drawer.draw_options[:override]
72
- true
73
- else
74
- log.warn override_warning_message(drawer,type)
75
- false
76
- end
77
- end
78
-
79
- def override_warning_message(drawer,type)
80
- [ "Drawer Attempting to Override Existing Drawer For '#{type}'",
81
- "#{drawer} will NOT be drawing '#{type}' as it is being handled by another Drawer.",
82
- "To override this in the #{drawer.class} class specify the parameter \"draws '#{type}', overrides: true\"" ].join("\n")
83
- end
84
-
85
- end
86
- end
87
- end
@@ -1,115 +0,0 @@
1
- module Metro
2
- module SceneView
3
-
4
- #
5
- # A Drawer subclass does all the artistic work defined in the view granted by
6
- # the {SceneView}. A Drawer at it's core defines a subclass which species
7
- # the things that it can draw and then the draw method which it will draw
8
- # those things.
9
- #
10
- # @example Creating a drawer to handle lines
11
- #
12
- # class Line < Metro::SceneView::Drawer
13
- # draws :lines
14
- #
15
- # def draw(view)
16
- # # Code would draw a line from:
17
- # # view['x1'],view['y1'] to view['x2'],view['y2']
18
- # # with a thickness of view['thickness']
19
- # end
20
- # end
21
- #
22
- class Drawer
23
-
24
- #
25
- # Allows a Drawer to specify what 'type' components it is able to draw. The
26
- # 'type' is defined within the view objects.
27
- #
28
- # class LabelDrawer < Metro::SceneView::Drawer
29
- # draws 'labels', 'shiny-labels', 'pulsing-labels'
30
- # end
31
- #
32
- # @param [String,Array<String>] args a list of 'types' that this drawer is capable
33
- # of drawing.
34
- #
35
- def self.draws(*args)
36
- @draws_types = args.flatten.compact.reject {|arg| arg.is_a? Hash }
37
- @draws_options = args.flatten.compact.find {|arg| arg.is_a? Hash }
38
- end
39
-
40
- #
41
- # This method is called right after initialization. Allowing for additional
42
- # configuration.
43
- #
44
- # @note This method should be implemented in the Drawer subclass.
45
- #
46
- def after_initialize ; end
47
-
48
- #
49
- # This method is called on the Drawer so that it renders content.
50
- #
51
- # @note This method should be implemented in the Drawer subclass.
52
- #
53
- # @param [Hash] view the hash content of the view.
54
- #
55
- def draw(view) ; end
56
-
57
- #
58
- # @return the instance of window that is often necessary to create Gosu
59
- # components for rendering.
60
- #
61
- attr_reader :window
62
-
63
- #
64
- # @return the scene that is being drawn. This is required if the view content
65
- # requires live information from the scene or if the drawing is effected
66
- # by the state of the scene.
67
- #
68
- attr_reader :scene
69
-
70
- #
71
- # Captures all classes that subclass Drawer.
72
- #
73
- def self.inherited(base)
74
- drawers << base
75
- end
76
-
77
- #
78
- # All subclasses of Drawer, this should be all the defined scenes within the game.
79
- #
80
- # @return an Array of Drawer subclasses
81
- #
82
- def self.drawers
83
- @drawers ||= []
84
- end
85
-
86
- #
87
- # @return an array of all the types of components that this Drawer
88
- # is able to handle drawing.
89
- #
90
- def self.draws_types
91
- Array(@draws_types)
92
- end
93
-
94
- def self.draw_options
95
- @draws_options || {}
96
- end
97
-
98
- #
99
- # This initialize sets up the drawer. If a subclass Drawer needs to perform
100
- # some customization, it is prefered to call {#after_initialize}.
101
- #
102
- # @see #after_initialize
103
- #
104
- # @param [Scene] scene the scene that this Drawer is going to be drawing. A
105
- # window is retrieved from the scene.
106
- #
107
- def initialize(scene)
108
- @scene = scene
109
- @window = scene.window
110
- after_initialize
111
- end
112
-
113
- end
114
- end
115
- end
@@ -1,31 +0,0 @@
1
- module Metro
2
- module SceneView
3
-
4
- class Image < Drawer
5
- draws 'image'
6
-
7
- attr_reader :images
8
-
9
- def after_initialize
10
- @images = {}
11
-
12
- content_images = scene.view.find_all { |name,content| self.class.draws_types.include?(content['type']) }
13
-
14
- content_images.each do |name,content|
15
- @images[name] = create_image(content)
16
- end
17
- end
18
-
19
- def create_image(content)
20
- Gosu::Image.new(window,asset_path(content['path']))
21
- end
22
-
23
- def draw(view)
24
- image = images[view['name']]
25
- image.draw(view['x'] - image.width / 2.0,view['y'] - image.height / 2.0,1)
26
- end
27
-
28
- end
29
-
30
- end
31
- end