Sha256: 01217c70b74414d68ca859316e5b43f603dd778432f97097ec44a84621597b03

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# Copyright (c) 2020 Jean-Sebastien Gelinas, see LICENSE.txt
# frozen_string_literal: true

require 'tileset_tooling/data/point'

# Class representing a TileSet's information
class ::TilesetTooling::Data::Tile < ::Dry::Struct
  attribute :top, ::TilesetTooling::Data::Types::Integer
  attribute :left, ::TilesetTooling::Data::Types::Integer
  attribute :height, ::TilesetTooling::Data::Types::Integer
  attribute :width, ::TilesetTooling::Data::Types::Integer

  attribute :margin_top, ::TilesetTooling::Data::Types::Integer
  attribute :margin_left, ::TilesetTooling::Data::Types::Integer
  attribute :margin_bottom, ::TilesetTooling::Data::Types::Integer
  attribute :margin_right, ::TilesetTooling::Data::Types::Integer

  attribute :row_index, ::TilesetTooling::Data::Types::Integer
  attribute :column_index, ::TilesetTooling::Data::Types::Integer

  # Helper to get the bottom coordinate
  def bottom
    top + height
  end

  # Helper to get the right coordinate
  def right
    left + width
  end

  # Helper to get the top-left point of this tile
  def top_left
    ::TilesetTooling::Data::Point.new(x: left, y: top)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tileset_tooling-0.1.0 lib/tileset_tooling/data/tile.rb