lib/demiurge/tmx.rb
# Extract the animations included in the TMX file
#
# @since 0.1.0
Extract the animations included in the TMX file
Extract the animations included in the TMX file
def animations_from_tilesets tilesets
      tilesets.flat_map do |tileset|
        (tileset["tiles"] || []).map do |tile|
          p = tile["properties"]
          if p && p["animation-frame0"]
            section = 0
            anim = []
            while p["animation-frame#{section}"]
              section_hash = {
                "frame" => p["animation-frame#{section}"].to_i + tileset[:firstgid],
                "duration" => p["animation-delay#{section}"].to_i
              }
              anim.push section_hash
              section += 1
            end
            { "tile_anim_#{tile["id"].to_i + tileset[:firstgid]}" => anim }
          else
            nil
          end
        end.compact
      end.inject({}, &:merge)
    end
def animations_from_tilesets tilesets tilesets . flat_map do | tileset | ( tileset [ "tiles" ] || [ ] ) . map do | tile | p = tile [ "properties" ] if p && p [ "animation-frame0" ] section = 0 anim = [ ] while p [ "animation-frame#{section}" ] section_hash = { "frame" => p [ "animation-frame#{section}" ] . to_i + tileset [ :firstgid ] , "duration" => p [ "animation-delay#{section}" ] . to_i } anim . push section_hash section += 1 end { "tile_anim_#{tile["id"].to_i + tileset[:firstgid]}" => anim } else nil end end . compact end . inject ( { } , & :merge ) end
Extract the animations included in the TMX file
Extract the animations included in the TMX file
tilesets
since
None