Uranus  1.0.1.0
Uranus is a GameEngine written in C++
Loading...
Searching...
No Matches
tson::Layer Class Reference
Collaboration diagram for tson::Layer:
[legend]

Public Member Functions

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

Private Member Functions

void decompressData ()
 
void queueFlaggedTile (size_t x, size_t y, uint32_t id)
 
void setTypeByString ()
 

Private Attributes

std::string m_base64Data
 
std::vector< tson::Chunkm_chunks
 
std::shared_ptr< tson::TiledClassm_class {}
 
std::string m_classType {}
 
std::string m_compression
 
std::vector< uint32_t > m_data
 
std::string m_drawOrder
 
std::string m_encoding
 
std::vector< tson::FlaggedTilem_flaggedTiles
 
int m_id {}
 
std::string m_image
 
std::vector< tson::Layerm_layers
 
tson::Mapm_map
 
std::string m_name
 
std::vector< tson::Objectm_objects
 
tson::Vector2f m_offset
 
float m_opacity {}
 
tson::Vector2f m_parallax {1.f, 1.f}
 
tson::PropertyCollection m_properties
 
bool m_repeatX {}
 
bool m_repeatY {}
 
tson::Vector2i m_size
 
std::map< std::tuple< int, int >, tson::Tile * > m_tileData
 
std::map< uint32_t, tson::Tile * > * m_tileMap
 
std::map< std::tuple< int, int >, tson::TileObjectm_tileObjects
 
tson::Colori m_tintColor
 
tson::Colori m_transparentColor
 
LayerType m_type {LayerType::Undefined}
 
std::string m_typeStr
 
std::set< uint32_t > m_uniqueFlaggedTiles
 
bool m_visible {}
 
int m_x {}
 
int m_y {}
 

Constructor & Destructor Documentation

◆ Layer()

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.

◆ decompressData()

void tson::Layer::decompressData ( )
inlineprivate

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

Decompresses data if there are matching decompressors

◆ 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.

◆ 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

Declared in tileson_forward.hpp

'type': tilelayer, objectgroup, imagelayer or group

Returns
string with the object type

◆ 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)

◆ hasRepeatX()

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

New in Tiled v1.8 'repeatx': Whether the image drawn by this layer is repeated along the X axis.

Returns
true if image layer is repeated along the X axis, false otherwise.

◆ hasRepeatY()

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

New in Tiled v1.8 'repeatx': Whether the image drawn by this layer is repeated along the Y axis.

Returns
true if image layer is repeated along the Y axis, false otherwise.

◆ 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.

◆ queueFlaggedTile()

void tson::Layer::queueFlaggedTile ( size_t  x,
size_t  y,
uint32_t  id 
)
inlineprivate

Defined in tileson_forward.hpp

◆ setTypeByString()

void tson::Layer::setTypeByString ( )
inlineprivate

Set type by string tilelayer, objectgroup, imagelayer or group

Field Documentation

◆ m_base64Data

std::string tson::Layer::m_base64Data
private

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

◆ m_class

std::shared_ptr<tson::TiledClass> tson::Layer::m_class {}
private

'class': The class of this map (since 1.9, defaults to “”).

◆ m_compression

std::string tson::Layer::m_compression
private

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

◆ m_data

std::vector<uint32_t> tson::Layer::m_data
private

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

◆ m_drawOrder

std::string tson::Layer::m_drawOrder
private

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

◆ m_encoding

std::string tson::Layer::m_encoding
private

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

◆ m_id

int tson::Layer::m_id {}
private

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

◆ m_image

std::string tson::Layer::m_image
private

'id': Incremental id - unique across all layers

◆ m_layers

std::vector<tson::Layer> tson::Layer::m_layers
private

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

◆ m_map

tson::Map* tson::Layer::m_map
private

Queue a flagged tile

◆ m_name

std::string tson::Layer::m_name
private

'layers': Array of layers. group on

◆ m_objects

std::vector<tson::Object> tson::Layer::m_objects
private

'name': Name assigned to this layer

◆ m_offset

tson::Vector2f tson::Layer::m_offset
private

'objects': Array of objects. objectgroup only.

◆ m_opacity

float tson::Layer::m_opacity {}
private

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

◆ m_parallax

tson::Vector2f tson::Layer::m_parallax {1.f, 1.f}
private

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

◆ m_properties

tson::PropertyCollection tson::Layer::m_properties
private

'opacity': Value between 0 and 1

◆ m_repeatX

bool tson::Layer::m_repeatX {}
private

Tiled v1.5: parallax factor for this layer. Defaults to 1. x = 'parallaxx', y = 'parallaxy'

◆ m_repeatY

bool tson::Layer::m_repeatY {}
private

'repeatx': Whether the image drawn by this layer is repeated along the X axis. (since Tiled 1.8)

◆ m_size

tson::Vector2i tson::Layer::m_size
private

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

◆ m_tileMap

std::map<uint32_t, tson::Tile *>* tson::Layer::m_tileMap
private

'repeaty': Whether the image drawn by this layer is repeated along the Y axis. (since Tiled 1.8)

◆ m_tileObjects

std::map<std::tuple<int, int>, tson::TileObject> tson::Layer::m_tileObjects
private

The map who owns this layer

◆ m_tintColor

tson::Colori tson::Layer::m_tintColor
private

Key: Tuple of x and y pos in tile units.

◆ m_transparentColor

tson::Colori tson::Layer::m_transparentColor
private

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

◆ m_type

LayerType tson::Layer::m_type {LayerType::Undefined}
private

'type': tilelayer, objectgroup, imagelayer or group

◆ m_typeStr

std::string tson::Layer::m_typeStr
private

'transparentcolor': Hex-formatted color (#RRGGBB) (optional, imagelayer only

◆ m_visible

bool tson::Layer::m_visible {}
private

Layer type as enum

◆ m_x

int tson::Layer::m_x {}
private

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

◆ m_y

int tson::Layer::m_y {}
private

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


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