Package games.stendhal.common.tiled
Class LayerDefinition
java.lang.Object
games.stendhal.common.tiled.LayerDefinition
- All Implemented Interfaces:
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
build()
Builds the real data array based on the byte array.static LayerDefinition
decode(InputStream in)
Deserializes a layer definition.byte[]
encode()
int[]
expose()
byte[]
int
Returns the height of the layer.getName()
Returns the name of the layer.int
getTileAt(int x, int y)
Returns the tile at the x,y position.getTilesetFor(int value)
Returns the name of the tileset a tile belongs to.int
getWidth()
Returns the width of the layer.void
Method to build the object from a stream of bytesvoid
set(int x, int y, int tileId)
Set a tile at the given x,y position.void
setMap(StendhalMapStructure map)
Sets the map to which this layer belong to.void
Sets the name of the layer.void
writeObject(OutputSerializer out)
Method to convert the object into a stream
-
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
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 positiony
- the y positiontileId
- 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 positiony
- the y position- Returns:
- the tile that exists at that position or 0 for none.
-
encode
- Returns:
- the encode byte array
- Throws:
IOException
-
decode
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
Returns the name of the tileset a tile belongs to.- Parameters:
value
- the tile id- Returns:
- the name of the tileset
-
setName
Sets the name of the layer.- Parameters:
layerName
- the name of the layer
-
getName
Returns the name of the layer.- Returns:
- the layer's name
-
readObject
Description copied from interface:Serializable
Method to build the object from a stream of bytes- Specified by:
readObject
in interfaceSerializable
- Parameters:
in
- InputSerializer to read from- Throws:
IOException
- in case of an IO-error
-
writeObject
Description copied from interface:Serializable
Method to convert the object into a stream- Specified by:
writeObject
in interfaceSerializable
- Parameters:
out
- OutputSerializer to write the object to- Throws:
IOException
- in case of an IO-error
-