Tileson 1.4.0
A helpful json parser for Tiled maps
Loading...
Searching...
No Matches
Public Member Functions | List of all members
tson::Object Class Reference

#include <Object.hpp>

Public Member Functions

 Object ()=default
 
 Object (IJson &json, tson::Map *map)
 
bool parse (IJson &json, tson::Map *map)
 
ObjectType getObjectType () const
 
bool isEllipse () const
 
uint32_t getGid () const
 
const Vector2igetSize () const
 
int getId () const
 
const std::string & getName () const
 
bool isPoint () const
 
float getRotation () const
 
const std::string & getTemplate () const
 
const std::string & getType () const
 
const std::string & getClassType () const
 
tson::TiledClassgetClass ()
 
bool isVisible () const
 
const Vector2igetPosition () const
 
const std::vector< tson::Vector2i > & getPolygons () const
 
const std::vector< tson::Vector2i > & getPolylines () const
 
PropertyCollectiongetProperties ()
 
const TextgetText () const
 
template<typename T >
get (const std::string &name)
 
tson::PropertygetProp (const std::string &name)
 
TileFlipFlags getFlipFlags () const
 
bool hasFlipFlags (TileFlipFlags flags)
 

Constructor & Destructor Documentation

◆ Object() [1/2]

tson::Object::Object ( )
inlinedefault

◆ Object() [2/2]

tson::Object::Object ( IJson json,
tson::Map map 
)
inlineexplicit

Parses a json Tiled object

Parameters
json

Member Function Documentation

◆ get()

template<typename T >
T tson::Object::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.

◆ getClass()

tson::TiledClass * tson::Object::getClass ( )
inline

Gets the class information for the 'type'/'class' This may only give a valid result if the map is loaded through a tson::Project

Returns
a tson::TiledClass object if related map was loaded through tson::Project

◆ getClassType()

const std::string & tson::Object::getClassType ( ) const
inline

'class': String assigned to class field in editor This was renamed from 'type' to 'class' in Tiled v1.9

Returns

◆ getFlipFlags()

tson::TileFlipFlags tson::Object::getFlipFlags ( ) const
inline

Get all flip flags

Returns

◆ getGid()

uint32_t tson::Object::getGid ( ) const
inline

'gid': GID, only if object comes from a Tilemap

Returns

◆ getId()

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

'id': Incremental id - unique across all objects

Returns

◆ getName()

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

'name': String assigned to name field in editor

Returns

◆ getObjectType()

tson::ObjectType tson::Object::getObjectType ( ) const
inline

Gets what type of object this is.

Returns

◆ getPolygons()

const std::vector< tson::Vector2i > & tson::Object::getPolygons ( ) const
inline

'polygon': A list of x,y coordinates in pixels. If this is a Polygon type, this function will return the points used to create it

Returns

◆ getPolylines()

const std::vector< tson::Vector2i > & tson::Object::getPolylines ( ) const
inline

'polyline': A list of x,y coordinates in pixels If this is a Polyline type, this function will return the points used to create it

Returns

◆ getPosition()

const tson::Vector2i & tson::Object::getPosition ( ) const
inline

'x' and 'y': coordinate in pixels

Returns

◆ getProp()

tson::Property * tson::Object::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::Object::getProperties ( )
inline

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

Returns

◆ getRotation()

float tson::Object::getRotation ( ) const
inline

'rotation': Angle in degrees clockwise

Returns

◆ getSize()

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

x = 'width' (Width in pixels), y = 'height' (Height in pixels). Ignored if using a gid.)

Returns

◆ getTemplate()

const std::string & tson::Object::getTemplate ( ) const
inline

'template': Reference to a template file, in case object is a template instance

Returns

◆ getText()

const tson::Text & tson::Object::getText ( ) const
inline

'type': String assigned to type field in editor

Returns

◆ getType()

const std::string & tson::Object::getType ( ) const
inline

'type': String assigned to type field in editor This was renamed to 'class' in Tiled v1.9

Returns

◆ hasFlipFlags()

bool tson::Object::hasFlipFlags ( TileFlipFlags  flags)
inline
Parameters
flagsWhich flags to check for. Several flags can be checked at once using the bitwise or operator. Example: hasFlipFlags(TileFlipFlags::Vertically | TileFlipFlags::Horizontally)
Returns
true if the flag(s) specified are set

◆ isEllipse()

bool tson::Object::isEllipse ( ) const
inline

'ellipse': Used to mark an object as an ellipse

Returns

◆ isPoint()

bool tson::Object::isPoint ( ) const
inline

'point': Used to mark an object as a point

Returns
true if the object is of type point

◆ isVisible()

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

Declared in tileson_forward.hpp

'visible': Whether object is shown in editor.

Returns

◆ parse()

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

Parses a json Tiled object and automatically determines the object type based on the data presented. Call getObjectType() to see what object type it is.

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

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