Class: Ruby2d::Tiled::LDTK

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2d/tiled/ldtk.rb

Class Method Summary collapse

Class Method Details

.load(ldtk_file) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/ruby2d/tiled/ldtk.rb', line 6

def self.load(ldtk_file)
  ldtk_file_path = File.expand_path(File.dirname(ldtk_file))
  json = JSON.parse(File.read(ldtk_file))

  layer_data = json['defs']['layers']
  levels = json.delete('levels').map { |level_data| Level.new(level_data, ldtk_file_path, layer_data) }

  World.new(json, levels)
end