module Tmx

Constants

VERSION

Public Instance Methods

load(filename,options={}) click to toggle source

Load the specified TMX file and return a Map that was found.

@param [String] filename the name fo the Tiled Map file. @param [Hash] options

@returns [Map] the map instance defined within the specified file

# File lib/tmx.rb, line 18
def load(filename,options={})
  options = default_options(filename).merge(options)

  # Pass :filename in options for resolving relative "source" paths
  parse contents(filename), options.merge(:filename => filename)
end
parse(contents,options={}) click to toggle source

Parse the the string contents of a TMX file.

@returns [Map] the map instance defined within the string

# File lib/tmx.rb, line 29
def parse(contents,options={})
  contents = parser(options).parse contents
  Map.new contents.merge(contents: contents)
end

Private Instance Methods

contents(filename) click to toggle source
# File lib/tmx.rb, line 40
def contents(filename)
  File.read(filename)
end
default_options(filename) click to toggle source
# File lib/tmx.rb, line 44
def default_options(filename)
  { format: format(filename) }
end
format(filename) click to toggle source
# File lib/tmx.rb, line 36
def format(filename)
  File.extname(filename)[1..-1]
end
parser(options) click to toggle source
# File lib/tmx.rb, line 48
def parser(options)
  format = options[:format].to_sym
  parsers[format].new(options)
end
parsers() click to toggle source
# File lib/tmx.rb, line 53
def parsers
  Parsers.parsers
end