Class LayerDefinition

java.lang.Object
games.stendhal.common.tiled.LayerDefinition
All Implemented Interfaces:
Serializable

public class LayerDefinition extends Object implements Serializable
The class that stores the definition of a layer. A Layer consists mainly of:
  • width and height
  • name VERY IMPORTANT
  • data
Author:
miguel
  • Constructor Details

    • LayerDefinition

      public LayerDefinition(int layerWidth, int layerHeight)
      Constructor.
      Parameters:
      layerWidth - the width of the layer.
      layerHeight - the height of the layer
  • Method Details

    • setMap

      public void setMap(StendhalMapStructure map)
      Sets the map to which this layer belong to.
      Parameters:
      map - the map
    • build

      public void build()
      Builds the real data array based on the byte array. It is only needed for objects, collision and protection, which is at most 40% of the layers.
    • exposeRaw

      public byte[] exposeRaw()
      Returns:
      the allocated raw array so it can be modified.
    • expose

      public int[] expose()
      Returns:
      the allocated data array of size width*height containing ints.
    • set

      public void set(int x, int y, int tileId)
      Set a tile at the given x,y position.
      Parameters:
      x - the x position
      y - the y position
      tileId - the tile code to set ( Use 0 for none ).
    • getTileAt

      public int getTileAt(int x, int y)
      Returns the tile at the x,y position.
      Parameters:
      x - the x position
      y - the y position
      Returns:
      the tile that exists at that position or 0 for none.
    • encode

      public byte[] encode() throws IOException
      Returns:
      the encode byte array
      Throws:
      IOException
    • decode

      public static LayerDefinition decode(InputStream in) throws IOException, ClassNotFoundException
      Deserializes a layer definition.
      Parameters:
      in - input serializer
      Returns:
      an instance of a layer definition
      Throws:
      IOException
      ClassNotFoundException
    • getWidth

      public int getWidth()
      Returns the width of the layer.
      Returns:
      the layer's width
    • getHeight

      public int getHeight()
      Returns the height of the layer.
      Returns:
      the layer's height
    • getTilesetFor

      public TileSetDefinition getTilesetFor(int value)
      Returns the name of the tileset a tile belongs to.
      Parameters:
      value - the tile id
      Returns:
      the name of the tileset
    • setName

      public void setName(String layerName)
      Sets the name of the layer.
      Parameters:
      layerName - the name of the layer
    • getName

      public String getName()
      Returns the name of the layer.
      Returns:
      the layer's name
    • readObject

      public void readObject(InputSerializer in) throws IOException
      Description copied from interface: Serializable
      Method to build the object from a stream of bytes
      Specified by:
      readObject in interface Serializable
      Parameters:
      in - InputSerializer to read from
      Throws:
      IOException - in case of an IO-error
    • writeObject

      public void writeObject(OutputSerializer out) throws IOException
      Description copied from interface: Serializable
      Method to convert the object into a stream
      Specified by:
      writeObject in interface Serializable
      Parameters:
      out - OutputSerializer to write the object to
      Throws:
      IOException - in case of an IO-error