metro 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  # Metro
2
2
 
3
+ ## 0.1.4 / 2012-10-28
4
+
5
+ * Removed dependency on the sender gem so metro is playable on Windows
6
+
3
7
  ## 0.1.3 / 2012-10-28
4
8
 
5
9
  * Fade Scene Transition support added
@@ -62,7 +62,7 @@ module Metro
62
62
  end
63
63
 
64
64
  desc "help", "This commoand"
65
- def help(topic)
65
+ def help
66
66
  say banner
67
67
  print_table self.class.printable_tasks, indent: 4
68
68
  end
@@ -1,7 +1,6 @@
1
1
  require 'gosu'
2
2
  require 'gosu_ext/color'
3
3
  require 'gosu_ext/gosu_constants'
4
- require 'sender'
5
4
  require 'i18n'
6
5
 
7
6
 
@@ -11,6 +10,8 @@ require 'logger'
11
10
  require 'erb'
12
11
 
13
12
  require 'locale/locale'
13
+ require 'metro/asset_path'
14
+ require 'metro/logging'
14
15
  require 'metro/version'
15
16
  require 'metro/template_message'
16
17
  require 'metro/window'
@@ -28,28 +29,6 @@ require_relative 'metro/missing_scene'
28
29
  #
29
30
  Game = Metro::Game
30
31
 
31
- def asset_path(name)
32
- File.join Dir.pwd, "assets", name
33
- end
34
-
35
- def log
36
- @log ||= begin
37
- logger = Logger.new(STDOUT)
38
- logger.level = Logger::DEBUG
39
- logger
40
- end
41
- end
42
-
43
- def error(messages, details = {})
44
- details = { show: true }.merge details
45
-
46
- message = TemplateMessage.new messages: messages, details: details,
47
- website: Game.website, contact: Game.contact
48
-
49
- warn message if details[:show]
50
- exit 1
51
- end
52
-
53
32
  module Metro
54
33
  extend self
55
34
  extend GosuConstants
@@ -71,6 +50,7 @@ module Metro
71
50
  #
72
51
  def run(filename=default_game_filename)
73
52
  load_game_files
53
+ change_into_game_directory(filename)
74
54
  load_game_configuration(filename)
75
55
  configure_controls!
76
56
  start_game
@@ -80,13 +60,26 @@ module Metro
80
60
 
81
61
  def load_game_files
82
62
  $LOAD_PATH.unshift(Dir.pwd) unless $LOAD_PATH.include?(Dir.pwd)
83
- Dir['models/*.rb'].each {|model| require model }
84
- Dir['scenes/*.rb'].each {|scene| require scene }
63
+ load_paths 'models', 'scenes', 'lib'
64
+ end
65
+
66
+ def change_into_game_directory(filename)
67
+ game_directory = File.dirname(filename)
68
+ Dir.chdir game_directory
69
+ end
70
+
71
+ def load_paths(*paths)
72
+ paths.flatten.compact.each {|path| load_path path }
73
+ end
74
+
75
+ def load_path(path)
76
+ Dir["#{path}/**/*.rb"].each {|model| require model }
85
77
  end
86
78
 
87
79
  def load_game_configuration(filename)
88
- game_files_exist!(filename)
89
- game_contents = File.read(filename)
80
+ gamefile = File.basename(filename)
81
+ game_files_exist!(gamefile)
82
+ game_contents = File.read(gamefile)
90
83
  game_block = lambda {|instance| eval(game_contents) }
91
84
  game = Game::DSL.parse(&game_block)
92
85
  Game.setup game
@@ -110,7 +103,7 @@ module Metro
110
103
 
111
104
  def game_file_exists?(file)
112
105
  unless File.exists? file
113
- error "error.missing_metro_file", file: file
106
+ error! "error.missing_metro_file", file: file
114
107
  end
115
108
  end
116
109
 
@@ -0,0 +1,22 @@
1
+ #
2
+ # The asset_path is a helper which will generate a filepath based on the current working
3
+ # directory of the game. This allows for game author's to specify a path relative within
4
+ # the assets directory of their game.
5
+ #
6
+ # @note Paths that are defined within views use this helper and are assumed to be paths
7
+ # relative within the assets directory of the game.
8
+ #
9
+ # @example Loading the branding image for the player model.
10
+ #
11
+ # class Player < Metro::Model
12
+ # def image
13
+ # @image ||= Gosu::Image.new( window, asset_path("player.png"), false )
14
+ # end
15
+ # def draw
16
+ # image.draw_rot(x,y,2,angle)
17
+ # end
18
+ # end
19
+ #
20
+ def asset_path(name)
21
+ File.join Dir.pwd, "assets", name
22
+ end
@@ -68,7 +68,7 @@ module Metro
68
68
 
69
69
  def self.check_for_already_defined_control!(control)
70
70
  if instance_methods.include? control.name
71
- error "error.reserved_control_name", name: control.name
71
+ error! "error.reserved_control_name", name: control.name
72
72
  end
73
73
  end
74
74
 
@@ -0,0 +1,33 @@
1
+
2
+ #
3
+ # Generates a default logger to standard out that can be used within Metro or the game.
4
+ #
5
+ # @example Outputting information at the debug level
6
+ #
7
+ # log.debug "The the screen resolution is #{Game.width},#{Game.height}"
8
+ #
9
+ def log
10
+ @log ||= begin
11
+ logger = Logger.new(STDOUT)
12
+ logger.level = Logger::DEBUG
13
+ logger
14
+ end
15
+ end
16
+
17
+ #
18
+ # Display an error message defined within the localization file. A game error displays
19
+ # a error title, message, and actions that can be taken to possibly address this issue.
20
+ #
21
+ # @param [String] message the I18n string found in the locale file.
22
+ # @param [Hash] details contains all the possible key-value pairs that might be needed
23
+ # for the localized error messages.
24
+ #
25
+ def error!(messages, details = {})
26
+ details = { show: true }.merge details
27
+
28
+ message = TemplateMessage.new messages: messages, details: details,
29
+ website: Game.website, contact: Game.contact
30
+
31
+ warn message if details[:show]
32
+ exit 1
33
+ end
@@ -50,7 +50,7 @@ module Metro
50
50
  # @param [Symbol] event the name of the notification to generate.
51
51
  #
52
52
  def notification(event)
53
- scene.notification(event.to_sym)
53
+ scene.notification(event.to_sym,self)
54
54
  end
55
55
 
56
56
  #
@@ -121,9 +121,7 @@ module Metro
121
121
  options.each do |raw_key,value|
122
122
 
123
123
  key = raw_key.to_s.dup
124
- key.gsub!(/-/,'_')
125
- key.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
126
- key.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
124
+ key = key.gsub(/-/,'_').snake_case
127
125
 
128
126
  unless respond_to? key
129
127
  self.class.send :define_method, key do
@@ -187,10 +185,7 @@ module Metro
187
185
  hash = Hash.new(Models::Generic)
188
186
 
189
187
  models.each do |model|
190
- common_name = model.to_s.gsub(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
191
- common_name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
192
- common_name.downcase!
193
-
188
+ common_name = model.to_s.snake_case
194
189
  hash[common_name] = model
195
190
  end
196
191
  hash
@@ -104,16 +104,9 @@ module Metro
104
104
  # Post a custom notification event. This will trigger any objects that are listening
105
105
  # for custom events.
106
106
  #
107
- def notification(event)
107
+ def notification(event,sender=nil)
108
108
 
109
- # __sender__ is made available through the sender gem, this is solely to make the
110
- # the api call to generate a notification simply `#notification`. Freeing the caller
111
- # from having to include themself in the execution.
112
- #
113
- # @note if the sender functionality proves troublesome across platforms this can
114
- # be dropped and simply require the sender to be included.
115
- #
116
- sender = __sender__ rescue UnknownSender
109
+ sender = sender || UnknownSender
117
110
 
118
111
  event_relays.each do |relay|
119
112
  relay.fire_events_for_notification(event,sender)
@@ -287,11 +280,7 @@ module Metro
287
280
  #
288
281
  def self.scene_name(scene_name=nil)
289
282
  @scene_name ||= begin
290
- root_name = to_s.gsub(/Scene$/,'')
291
- root_name.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
292
- root_name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
293
- root_name.downcase!
294
- root_name
283
+ to_s.gsub(/_?Scene$/i,'').snake_case
295
284
  end
296
285
 
297
286
  scene_name ? @scene_name = scene_name.to_s : @scene_name
@@ -1,5 +1,5 @@
1
1
  module Metro
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  WEBSITE = "https://github.com/burtlo/metro"
4
4
  CONTACT_EMAILS = ["franklin.webber@gmail.com"]
5
5
 
@@ -3,7 +3,7 @@ class BrandToTitleScene < Metro::Scene
3
3
  draws :title
4
4
 
5
5
  animate :title, to: { alpha: 255 }, interval: 2.seconds do
6
- transition_to :title, with: :fade
6
+ transition_to :title
7
7
  end
8
8
 
9
9
  event :cancel do
@@ -10,8 +10,8 @@ class <%= scene_class_name %> < Metro::Scene
10
10
  #
11
11
  # draw :title, 'text' => 'Title Screen',
12
12
  # 'x' => 20, 'y' => 20, 'z-order' => 0,
13
- # 'x-factor' => 3, 'y-factor' => 3,
14
- # 'color' => 0xffffffff,
13
+ # 'size' => 40,
14
+ # 'color' => 'rgb(255,255,255)',
15
15
  # 'model' => 'metro::models::label'
16
16
  #
17
17
  # The draw method can be simplier for models that have content defined
@@ -39,7 +39,7 @@ class <%= scene_class_name %> < Metro::Scene
39
39
  #
40
40
  # @example Registering the keyboard down event to execute a block of code
41
41
  #
42
- # event :on_down, Gosu::GpLeft, Gosu::GpUp, do
42
+ # event :on_down, GpLeft, GpUp, do
43
43
  # transition_to :next_scene
44
44
  # end
45
45
  #
@@ -49,7 +49,7 @@ class <%= scene_class_name %> < Metro::Scene
49
49
  #
50
50
  # @example Registering for button held events that would move an actor named `player`
51
51
  #
52
- # event :on_hold, KbRight, Gosu::GpRight do
52
+ # event :on_hold, KbRight, GpRight do
53
53
  # title.alpha = title.alpha - 1
54
54
  # end
55
55
  # Keystroke and Game Event Reference
@@ -26,7 +26,6 @@ Gem::Specification.new do |gem|
26
26
 
27
27
  gem.add_dependency 'gosu', '~> 0.7'
28
28
  gem.add_dependency 'thor', '~> 0.16.0'
29
- gem.add_dependency 'sender', '~> 1.5.10'
30
29
  gem.add_dependency 'i18n', '~> 0.6.1'
31
30
  gem.add_development_dependency 'rspec', '~> 2.11'
32
31
 
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.1.3
4
+ version: 0.1.4
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-28 00:00:00.000000000 Z
12
+ date: 2012-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gosu
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.16.0
46
- - !ruby/object:Gem::Dependency
47
- name: sender
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 1.5.10
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 1.5.10
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: i18n
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -129,6 +113,7 @@ files:
129
113
  - lib/metro/animation/implicit_animation.rb
130
114
  - lib/metro/animation/on_update_operation.rb
131
115
  - lib/metro/animation/scene_animation.rb
116
+ - lib/metro/asset_path.rb
132
117
  - lib/metro/events/control_definition.rb
133
118
  - lib/metro/events/controls.rb
134
119
  - lib/metro/events/event_factory.rb
@@ -137,6 +122,7 @@ files:
137
122
  - lib/metro/events/unknown_sender.rb
138
123
  - lib/metro/game.rb
139
124
  - lib/metro/game/dsl.rb
125
+ - lib/metro/logging.rb
140
126
  - lib/metro/missing_scene.rb
141
127
  - lib/metro/models/draws.rb
142
128
  - lib/metro/models/generic.rb
@@ -184,12 +170,9 @@ licenses: []
184
170
  post_install_message: ! " ______ ___ _____\n ___ |/ /_____ __ /_______________\n
185
171
  \ __ /|_/ / _ _ \\_ __/__ ___/_ __ \\\n _ / / / / __// /_ _ / /
186
172
  /_/ /\n /_/ /_/ \\___/ \\__/ /_/ \\____/\n\n Thank you for installing
187
- metro 0.1.3 / 2012-10-28.\n ---------------------------------------------------------------------\n
188
- \ Changes:\n \n * Fade Scene Transition support added\n * Numeric#seconds and
189
- Numeric#ticks helpers added\n * Scenes can now define delayed events `after 2.seconds
190
- do ; end`\n * Labels have more defaults and more font options and size\n * Labels
191
- and images will default to center of screen\n * Able to define game controls within
192
- your metro file\n * Implicit animations support color change.\n \n\n ---------------------------------------------------------------------\n"
173
+ metro 0.1.4 / 2012-10-28.\n ---------------------------------------------------------------------\n
174
+ \ Changes:\n \n * Removed dependency on the sender gem so metro is playable
175
+ on Windows\n \n\n ---------------------------------------------------------------------\n"
193
176
  rdoc_options: []
194
177
  require_paths:
195
178
  - lib