Module: Metro

Extended by:
Metro, GosuConstants
Included in:
Metro
Defined in:
lib/metro.rb,
lib/metro/font.rb,
lib/metro/game.rb,
lib/metro/song.rb,
lib/metro/image.rb,
lib/metro/scene.rb,
lib/metro/sample.rb,
lib/metro/scenes.rb,
lib/metro/window.rb,
lib/commands/thor.rb,
lib/metro/version.rb,
lib/metro/game/dsl.rb,
lib/metro/animation.rb,
lib/metro/asset_path.rb,
lib/metro/views/view.rb,
lib/metro/units/point.rb,
lib/metro/units/scale.rb,
lib/metro/models/draws.rb,
lib/metro/models/model.rb,
lib/metro/units/bounds.rb,
lib/metro/missing_scene.rb,
lib/metro/models/models.rb,
lib/metro/models/ui/fps.rb,
lib/metro/views/no_view.rb,
lib/metro/views/parsers.rb,
lib/metro/views/writers.rb,
lib/metro/models/ui/menu.rb,
lib/metro/events/controls.rb,
lib/metro/events/hit_list.rb,
lib/metro/models/ui/image.rb,
lib/metro/models/ui/label.rb,
lib/metro/views/json_view.rb,
lib/metro/views/yaml_view.rb,
lib/commands/generate_game.rb,
lib/commands/generate_view.rb,
lib/metro/models/ui/border.rb,
lib/metro/models/ui/sprite.rb,
lib/metro/units/dimensions.rb,
lib/metro/views/scene_view.rb,
lib/commands/generate_model.rb,
lib/commands/generate_scene.rb,
lib/gosu_ext/gosu_constants.rb,
lib/metro/events/event_data.rb,
lib/metro/events/has_events.rb,
lib/metro/models/audio/song.rb,
lib/metro/models/ui/generic.rb,
lib/metro/events/event_relay.rb,
lib/metro/models/ui/tile_map.rb,
lib/metro/parameters/options.rb,
lib/metro/models/ui/rectangle.rb,
lib/metro/events/event_factory.rb,
lib/metro/models/model_factory.rb,
lib/metro/events/unknown_sender.rb,
lib/metro/models/ui/grid_drawer.rb,
lib/metro/models/ui/model_label.rb,
lib/metro/units/rectangle_bounds.rb,
lib/metro/animation/easing/easing.rb,
lib/metro/animation/easing/linear.rb,
lib/metro/events/event_dictionary.rb,
lib/metro/models/key_value_coding.rb,
lib/metro/models/ui/model_labeler.rb,
lib/setup_handlers/game_execution.rb,
lib/metro/animation/easing/ease_in.rb,
lib/metro/animation/has_animations.rb,
lib/setup_handlers/exit_if_dry_run.rb,
lib/setup_handlers/load_game_files.rb,
lib/metro/animation/scene_animation.rb,
lib/metro/events/control_definition.rb,
lib/metro/models/ui/animated_sprite.rb,
lib/metro/events/event_state_manager.rb,
lib/metro/models/properties/property.rb,
lib/metro/animation/animation_factory.rb,
lib/metro/animation/implicit_animation.rb,
lib/metro/transitions/transition_scene.rb,
lib/metro/animation/on_update_operation.rb,
lib/metro/transitions/scene_transitions.rb,
lib/metro/units/calculation_validations.rb,
lib/metro/models/properties/font_property.rb,
lib/metro/models/properties/song_property.rb,
lib/metro/models/properties/text_property.rb,
lib/setup_handlers/move_to_game_directory.rb,
lib/metro/animation/after_interval_factory.rb,
lib/metro/models/properties/array_property.rb,
lib/metro/models/properties/color_property.rb,
lib/metro/models/properties/image_property.rb,
lib/metro/models/properties/model_property.rb,
lib/metro/models/properties/property_owner.rb,
lib/metro/models/properties/scale_property.rb,
lib/setup_handlers/load_game_configuration.rb,
lib/metro/models/properties/sample_property.rb,
lib/metro/transitions/edit_transition_scene.rb,
lib/metro/transitions/fade_transition_scene.rb,
lib/metro/models/properties/boolean_property.rb,
lib/metro/models/properties/numeric_property.rb,
lib/metro/models/properties/position_property.rb,
lib/metro/parameters/command_line_args_parser.rb,
lib/metro/models/properties/animation_property.rb,
lib/metro/models/properties/dimensions_property.rb,
lib/setup_handlers/reload_game_on_game_file_changes.rb,
lib/metro/models/properties/options_property/options.rb,
lib/metro/models/properties/options_property/no_option.rb,
lib/metro/models/properties/options_property/options_property.rb

Defined Under Namespace

Modules: Audio, Draws, EventDictionary, Game, GosuConstants, HasAnimations, HasEvents, KeyValueCoding, Models, Parameters, PropertyOwner, SceneAnimation, SceneTransitions, SceneView, Scenes, SetupHandlers, UI, Units, Views Classes: AfterIntervalFactory, Animation, AnimationFactory, AssetPath, ControlDefinition, Controls, Easing, EditTransitionScene, EventData, EventFactory, EventRelay, EventStateManager, FadeTransitionScene, Font, GenerateGame, GenerateModel, GenerateScene, GenerateView, Generator, HitList, Image, ImplicitAnimation, MissingScene, Model, ModelFactory, OnUpdateOperation, PropertyDefinition, Sample, Scene, Song, Thor, TransitionScene, UnknownGenerator, UnknownSender, View, Window

Constant Summary collapse

VERSION =
"0.3.3"
WEBSITE =
"https://github.com/burtlo/metro"
CONTACT_EMAILS =
["[email protected]"]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GosuConstants

add, extended, find_all_constants_with_prefix, gamepad_events, gosu, keyboard_events, mouse_events

Class Method Details

.changes_for_version(version) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/metro/version.rb', line 6

def self.changes_for_version(version)

  change = Struct::Changes.new(nil,[])

  grab_changes = false

  changelog_filename = "#{File.dirname(__FILE__)}/../../changelog.md"

  File.open(changelog_filename,'r') do |file|
    while (line = file.gets) do

      if line =~ /^##\s*#{version.gsub('.','\.')}\s*\/\s*(.+)\s*$/
        grab_changes = true
        change.date = $1.strip
      elsif line =~ /^##\s*.+$/
        grab_changes = false
      elsif grab_changes
        change.changes.push line
      end

    end
  end

  change
end

Instance Method Details

#asset_dirString

Returns the filepath to the Metro assets.

Returns:

  • (String)

    the filepath to the Metro assets



62
63
64
# File 'lib/metro.rb', line 62

def asset_dir
  File.join File.dirname(__FILE__), "assets"
end

#executable_pathString

Returns the filepath to the Metro executable.

Returns:

  • (String)

    the filepath to the Metro executable



55
56
57
# File 'lib/metro.rb', line 55

def executable_path
  File.absolute_path File.join(File.dirname(__FILE__), "..", "bin", "metro")
end

#game_has_valid_code?TrueClass, FalseClass

When called the game-related code will be loaded in a sub-process to see if the code is valid. This is used in tandem with #reload and should be called prior to ensure that the code that is replacing the current code is valid.

Returns:

  • (TrueClass, FalseClass)

    true if the game code that was loaded was loaded successfully. false if the game code was not able to be loaded.



125
126
127
128
129
130
131
132
133
# File 'lib/metro.rb', line 125

def game_has_valid_code?
  execution = SetupHandlers::LoadGameFiles.new.launch_game_in_dry_run_mode

  if execution.invalid?
    error! 'error.unloadable_source', output: execution.output, exit: false
  end

  execution.valid?
end

#register_setup_handler(handler) ⇒ Object

Register a setup handler. While this method is present, it is far too late for game code to be executed as these pregame handlers will already have started executing. This allows for modularity within the Metro library with the possibility that this functionality could become available to individual games if the load process were to be updated.



81
82
83
# File 'lib/metro.rb', line 81

def register_setup_handler(handler)
  setup_handlers.push handler
end

#reload!Object

When called all the game-related code will be unloaded and reloaded. Providding an opportunity for a game author to tweak the code without having to restart the game.



112
113
114
# File 'lib/metro.rb', line 112

def reload!
  SetupHandlers::LoadGameFiles.new.load_game_files!
end

#run(*parameters) ⇒ Object

Run will load the contents of the game contents and game files within the current working directory and start the game.

Parameters:

  • parameters (Array<String>)

    an array of parameters that contains the commands in the format that would normally be parsed into the ARGV array.



93
94
95
96
97
# File 'lib/metro.rb', line 93

def run(*parameters)
  options = Parameters::CommandLineArgsParser.parse(parameters)
  setup_handlers.each { |handler| handler.setup(options) }
  start_game
end

#setup_handlersArray

Returns an array of all the handlers that will be executed prior to the game being launched.

Returns:

  • (Array)

    an array of all the handlers that will be executed prior to the game being launched.



70
71
72
# File 'lib/metro.rb', line 70

def setup_handlers
  @setup_handlers ||= []
end

#start_gameObject

Start the game by lanunching a window with the game configuration and data that has been loaded.



103
104
105
# File 'lib/metro.rb', line 103

def start_game
  Game.start!
end