Tileson  1.3.0
A helpful json parser for Tiled maps
Public Member Functions | List of all members
tson::Layer Class Reference

#include <Layer.hpp>

Public Member Functions

 Layer ()=default
 
 Layer (IJson &json, tson::Map *map)
 
bool parse (IJson &json, tson::Map *map)
 
const std::string & getCompression () const
 
const std::vector< uint32_t > & getData () const
 
const std::string & getBase64Data () const
 
const std::string & getDrawOrder () const
 
const std::string & getEncoding () const
 
int getId () const
 
const std::string & getImage () const
 
const std::string & getName () const
 
const Vector2fgetOffset () const
 
float getOpacity () const
 
const Vector2igetSize () const
 
const ColorigetTransparentColor () const
 
const Vector2fgetParallax () const
 
LayerType getType () const
 
const std::string & getTypeStr () const
 
bool isVisible () const
 
int getX () const
 
int getY () const
 
std::vector< tson::Chunk > & getChunks ()
 
std::vector< tson::Layer > & getLayers ()
 
std::vector< tson::Object > & getObjects ()
 
PropertyCollectiongetProperties ()
 
tson::ObjectgetObj (int id)
 
tson::ObjectfirstObj (const std::string &name)
 
std::vector< tson::ObjectgetObjectsByName (const std::string &name)
 
std::vector< tson::ObjectgetObjectsByType (tson::ObjectType type)
 
template<typename T >
get (const std::string &name)
 
tson::PropertygetProp (const std::string &name)
 
void assignTileMap (std::map< uint32_t, tson::Tile * > *tileMap)
 
void createTileData (const Vector2i &mapSize, bool isInfiniteMap)
 
const std::map< std::tuple< int, int >, tson::Tile * > & getTileData () const
 
tson::TilegetTileData (int x, int y)
 
const ColorigetTintColor () const
 
tson::MapgetMap () const
 
std::map< std::tuple< int, int >, tson::TileObject > & getTileObjects ()
 
tson::TileObjectgetTileObject (int x, int y)
 
const std::set< uint32_t > & getUniqueFlaggedTiles () const
 
void resolveFlaggedTiles ()
 

Constructor & Destructor Documentation

◆ Layer() [1/2]

tson::Layer::Layer ( )
inlinedefault

◆ Layer() [2/2]

tson::Layer::Layer ( IJson json,
tson::Map map 
)
inline

Parses a Tiled layer from json

Parameters
json

Member Function Documentation

◆ assignTileMap()

void tson::Layer::assignTileMap ( std::map< uint32_t, tson::Tile * > *  tileMap)
inline

Assigns a tilemap of pointers to existing tiles.

Parameters
tileMapThe tilemap. key: tile id, value: pointer to Tile.

◆ createTileData()

void tson::Layer::createTileData ( const Vector2i mapSize,
bool  isInfiniteMap 
)
inline

This is only supported for non-infinite maps!

Parameters
mapSizeThe size of the map
isInfiniteMapWhether or not the current map is infinte.

◆ firstObj()

tson::Object * tson::Layer::firstObj ( const std::string &  name)
inline

Returns the first object with the given name

Parameters
nameName of the object to find.
Returns
A pointer to the object if found. nullptr otherwise.

◆ get()

template<typename T >
T tson::Layer::get ( const std::string &  name)
inline

A shortcut for getting a property. Alternative to getProperties().getValue<T>("<name>")

Template Parameters
TThe template value
Parameters
nameName of the property
Returns
The actual value, if it exists. Otherwise: The default value of the type.

◆ getBase64Data()

const std::string & tson::Layer::getBase64Data ( ) const
inline

'data' (when string): Array of unsigned int (GIDs) or base64-encoded data. tilelayer only.

Returns

◆ getChunks()

std::vector< tson::Chunk > & tson::Layer::getChunks ( )
inline

'chunks': Array of chunks (optional). tilelayer only.

Returns

◆ getCompression()

const std::string & tson::Layer::getCompression ( ) const
inline

'compression': zlib, gzip or empty (default). tilelayer only.

Returns

◆ getData()

const std::vector< uint32_t > & tson::Layer::getData ( ) const
inline

'data' (when uint array): Array of unsigned int (GIDs) or base64-encoded data. tilelayer only.

Returns

◆ getDrawOrder()

const std::string & tson::Layer::getDrawOrder ( ) const
inline

'draworder': topdown (default) or index. objectgroup only.

Returns

◆ getEncoding()

const std::string & tson::Layer::getEncoding ( ) const
inline

'encoding': csv (default) or base64. tilelayer only.

Returns

◆ getId()

int tson::Layer::getId ( ) const
inline

'id': Incremental id - unique across all layers

Returns

◆ getImage()

const std::string & tson::Layer::getImage ( ) const
inline

'image': Image used by this layer. imagelayer only.

Returns

◆ getLayers()

std::vector< tson::Layer > & tson::Layer::getLayers ( )
inline

'layers': Array of layers. group on

Returns

◆ getMap()

tson::Map * tson::Layer::getMap ( ) const
inline

Used for getting the tson::Map who is the parent of this Layer.

Returns
a pointer to the tson::Map where this layer is contained.

◆ getName()

const std::string & tson::Layer::getName ( ) const
inline

'name': Name assigned to this layer

Returns

◆ getObj()

tson::Object * tson::Layer::getObj ( int  id)
inline

Get an object by ID

Parameters
idUnique ID of the object
Returns
A pointer to the object if found. nullptr otherwise.

◆ getObjects()

std::vector< tson::Object > & tson::Layer::getObjects ( )
inline

'objects': Array of objects. objectgroup only.

Returns

◆ getObjectsByName()

std::vector< tson::Object > tson::Layer::getObjectsByName ( const std::string &  name)
inline

Copies all objects with a name that equals the parameter

Parameters
nameName of the objects to return
Returns
All objects with a matching name

◆ getObjectsByType()

std::vector< tson::Object > tson::Layer::getObjectsByType ( tson::ObjectType  type)
inline

Copies all objects with a type that equals the parameter

Parameters
typeLayerType of the objects to return
Returns
All objects with a matching type

◆ getOffset()

const tson::Vector2f & tson::Layer::getOffset ( ) const
inline

'offsetx' and 'offsety': Horizontal and Vertical layer offset in pixels (default: {0, 0})

Returns

◆ getOpacity()

float tson::Layer::getOpacity ( ) const
inline

'opacity': Value between 0 and 1

Returns

◆ getParallax()

const tson::Vector2f & tson::Layer::getParallax ( ) const
inline

New in Tiled v1.5 Gets the parallax factor for current layer. Defaults to 1.

Returns
A vector with the x and y values of the parallax factor.

◆ getProp()

tson::Property * tson::Layer::getProp ( const std::string &  name)
inline

Shortcut for getting a property object. Alternative to getProperties().getProperty("<name>");

Parameters
nameName of the property
Returns

◆ getProperties()

tson::PropertyCollection & tson::Layer::getProperties ( )
inline

'properties': A list of properties (name, value, type).

Returns

◆ getSize()

const tson::Vector2i & tson::Layer::getSize ( ) const
inline

x = 'width': (Column count. Same as map width for fixed-size maps.) y = 'height': Row count. Same as map height for fixed-size maps.

Returns
width and height as a single size

◆ getTileData() [1/2]

const std::map< std::tuple< int, int >, tson::Tile * > & tson::Layer::getTileData ( ) const
inline

Get tile data as some kind of map with x and y position with pointers to existing tiles. Map only contains tiles that are not empty. x and y position is in tile units.

Example of getting tile from the returned map:

Tile *tile = tileData[{0, 4}];

Returns
A map that represents the data returned from getData() in a 2D map with Tile pointers.

◆ getTileData() [2/2]

tson::Tile * tson::Layer::getTileData ( int  x,
int  y 
)
inline

A safe way to get tile data Get tile data as some kind of map with x and y position with pointers to existing tiles. Map only contains tiles that are not empty. x and y position is in tile units.

Example of getting tile: Tile *tile = layer->getTileData(0, 4)

Parameters
xX position in tile units
yY position in tile units
Returns
pointer to tile, if it exists. nullptr otherwise.

◆ getTileObject()

tson::TileObject * tson::Layer::getTileObject ( int  x,
int  y 
)
inline

◆ getTileObjects()

std::map< std::tuple< int, int >, tson::TileObject > & tson::Layer::getTileObjects ( )
inline

◆ getTintColor()

const tson::Colori & tson::Layer::getTintColor ( ) const
inline

'tintcolor': Hex-formatted color (#RRGGBB or #AARRGGBB) that is multiplied with any graphics drawn by this layer or any child layers (optional).

Returns
tintcolor

◆ getTransparentColor()

const tson::Colori & tson::Layer::getTransparentColor ( ) const
inline

'transparentcolor': Color created from a hex color (#RRGGBB) (optional, imagelayer only)

Returns
color as color object with rgba channel.

◆ getType()

tson::LayerType tson::Layer::getType ( ) const
inline

Get layer type

Returns
Layer type as enum

◆ getTypeStr()

const std::string & tson::Layer::getTypeStr ( ) const
inline

'type': tilelayer, objectgroup, imagelayer or group

Returns
string with the object type

◆ getUniqueFlaggedTiles()

const std::set< uint32_t > & tson::Layer::getUniqueFlaggedTiles ( ) const
inline

◆ getX()

int tson::Layer::getX ( ) const
inline

'x': Horizontal layer offset in tiles. Always 0.

Returns
x value (always 0 for layer)

◆ getY()

int tson::Layer::getY ( ) const
inline

'y': Horizontal layer offset in tiles. Always 0.

Returns
y value (always 0 for layer)

◆ isVisible()

bool tson::Layer::isVisible ( ) const
inline

'visible': Whether layer is shown or hidden in editor

Returns

◆ parse()

bool tson::Layer::parse ( IJson json,
tson::Map map 
)
inline

Parses a Tiled layer from json

Parameters
json
Returns
true if all mandatory fields was found. false otherwise.

◆ resolveFlaggedTiles()

void tson::Layer::resolveFlaggedTiles ( )
inline

The documentation for this class was generated from the following files: