Class: TilesetTooling::Data::TileSet

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/tileset_tooling/data/tileset.rb

Overview

Class representing a TileSet’s information

Instance Method Summary collapse

Instance Method Details

#for_each_tile(&block) ⇒ Object

Runs the given bloc on each tile of the tileset



39
40
41
42
43
44
45
# File 'lib/tileset_tooling/data/tileset.rb', line 39

def for_each_tile(&block)
  rows.each do |row|
    row.tiles.each do |tile|
      block.call(tile)
    end
  end
end

#heightObject

Gets the height of the tileset/image



48
49
50
# File 'lib/tileset_tooling/data/tileset.rb', line 48

def height
  image.height
end

#to_sObject

Helper to print all information in the image



27
28
29
30
31
32
33
34
35
36
# File 'lib/tileset_tooling/data/tileset.rb', line 27

def to_s
  %(
Image '#{original_image_path}'
Tile height: #{tile_height}
Tile width: #{tile_width}
Margin: #{margin}
Top offset: #{offset_top}
Left offset: #{offset_left}
Number of tiles: #{rows.count * rows[0].tiles.count})
end

#widthObject

Gets the width of the tileset/image



53
54
55
# File 'lib/tileset_tooling/data/tileset.rb', line 53

def width
  image.width
end