Class TileData


public class TileData
Represents the tile data for a tile map. This class handles the encoding, compression, and storage of tile data.
  • Constructor Details

    • TileData

      public TileData()
      Default constructor for the TileData class. This constructor is required for serialization purposes.
    • TileData

      public TileData(List<Tile> tiles, int width, int height, String encoding, String compression) throws TmxException
      Constructs a new TileData instance with the specified parameters.
      Parameters:
      tiles - The list of tiles.
      width - The width of the tile data.
      height - The height of the tile data.
      encoding - The encoding type of the tile data.
      compression - The compression type of the tile data.
      Throws:
      TmxException - If the encoding or compression type is invalid.
    • TileData

      public TileData(TileData original)
      Copy constructor for the TileData class. Creates a new instance of the TileData class by copying the properties from the provided TileData object.
      Parameters:
      original - The original TileData object to copy from.
  • Method Details

    • getEncoding

      public String getEncoding()
    • getCompression

      public String getCompression()
    • getValue

      public String getValue()
    • setEncoding

      public void setEncoding(String encoding)
      Sets the encoding type for the tile data.
      Parameters:
      encoding - The encoding type to set.
    • setCompression

      public void setCompression(String compression)
      Sets the compression type for the tile data.
      Parameters:
      compression - The compression type to set.
    • setValue

      public void setValue(String value)
      Sets the value for the tile data and updates the raw value list.
      Parameters:
      value - The value to set.
    • getTiles

      public List<Tile> getTiles()
      Retrieves the list of tiles for the tile data. If the tiles are already parsed, it returns the cached list. Otherwise, it parses the tile data based on the encoding and compression.
      Returns:
      The list of tiles.
    • encode

      public static String encode(TileData data) throws IOException
      Encodes the provided TileData instance into a string based on its encoding type.
      Parameters:
      data - The TileData instance to encode.
      Returns:
      The encoded string representation of the tile data.
      Throws:
      IOException - If an I/O error occurs during encoding.
    • setMinChunkOffsets

      protected void setMinChunkOffsets(int x, int y)
      Sets the minimum chunk offsets for the tile data.
      Parameters:
      x - The minimum chunk offset on the x-axis.
      y - The minimum chunk offset on the y-axis.
    • isInfinite

      protected boolean isInfinite()
      Checks if the tile data represents an infinite map.
      Returns:
      true if the map is infinite, false otherwise.
    • getWidth

      protected int getWidth()
      Retrieves the width of the tile data. For infinite maps, the width is adjusted based on the chunk offsets.
      Returns:
      The width of the tile data.
    • getHeight

      protected int getHeight()
      Retrieves the height of the tile data. For infinite maps, the height is adjusted based on the chunk offsets.
      Returns:
      The height of the tile data.
    • getOffsetX

      protected int getOffsetX()
      Retrieves the x-axis offset of the tile data.
      Returns:
      The x-axis offset.
    • getOffsetY

      protected int getOffsetY()
      Retrieves the y-axis offset of the tile data.
      Returns:
      The y-axis offset.
    • parseBase64Data

      protected static List<Tile> parseBase64Data(String value, String compression) throws InvalidTileLayerException
      Parses the tile data from a Base64 encoded string.
      Parameters:
      value - The Base64 encoded string containing the tile data.
      compression - The compression type used on the tile data (e.g., GZIP, ZLIB, or null for no compression).
      Returns:
      A list of Tile objects parsed from the Base64 encoded string.
      Throws:
      InvalidTileLayerException - If the Base64 string is invalid or an I/O error occurs during parsing.
    • parseCsvData

      protected static List<Tile> parseCsvData(String value) throws InvalidTileLayerException
      Parses the tile data from a CSV formatted string.
      Parameters:
      value - The CSV formatted string containing the tile data.
      Returns:
      A list of Tile objects parsed from the CSV string.
      Throws:
      InvalidTileLayerException - If the CSV string is invalid or an error occurs during parsing.