5 #ifndef TILESON_OBJECT_HPP
6 #define TILESON_OBJECT_HPP
9 #include "../objects/Vector2.hpp"
10 #include "../objects/PropertyCollection.hpp"
13 #include "../common/Enums.hpp"
39 [[nodiscard]]
inline bool isEllipse()
const;
40 [[nodiscard]]
inline uint32_t
getGid()
const;
42 [[nodiscard]]
inline int getId()
const;
43 [[nodiscard]]
inline const std::string &
getName()
const;
44 [[nodiscard]]
inline bool isPoint()
const;
46 [[nodiscard]]
inline const std::string &
getTemplate()
const;
47 [[nodiscard]]
inline const std::string &
getType()
const;
48 [[nodiscard]]
inline bool isVisible()
const;
51 [[nodiscard]]
inline const std::vector<tson::Vector2i> &
getPolygons()
const;
52 [[nodiscard]]
inline const std::vector<tson::Vector2i> &
getPolylines()
const;
57 inline T
get(
const std::string &name);
66 inline void setObjectTypeByJson(
IJson &json);
75 std::vector<tson::Vector2i> m_polygon;
76 std::vector<tson::Vector2i> m_polyline;
79 std::string m_template;
98 return m_properties.getValue<T>(name);
119 bool allFound =
true;
121 if(json.
count(
"ellipse") > 0) m_ellipse = json[
"ellipse"].
get<
bool>();
122 if(json.
count(
"gid") > 0)
124 uint32_t gid = json[
"gid"].
get<uint32_t>();
130 gid &= ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG);
134 if(json.
count(
"id") > 0) m_id = json[
"id"].get<int>();
else allFound =
false;
135 if(json.
count(
"name") > 0) m_name = json[
"name"].get<std::string>();
else allFound =
false;
136 if(json.
count(
"point") > 0) m_point = json[
"point"].get<bool>();
137 if(json.
count(
"rotation") > 0) m_rotation = json[
"rotation"].get<float>();
else allFound =
false;
138 if(json.
count(
"template") > 0) m_template = json[
"template"].get<std::string>();
139 if(json.
count(
"type") > 0) m_type = json[
"type"].get<std::string>();
else allFound =
false;
140 if(json.
count(
"visible") > 0) m_visible = json[
"visible"].get<bool>();
else allFound =
false;
142 if(json.
count(
"width") > 0 && json.
count(
"height") > 0)
143 m_size = {json[
"width"].
get<
int>(), json[
"height"].get<int>()};
else allFound =
false;
144 if(json.
count(
"x") > 0 && json.
count(
"y") > 0)
145 m_position = {json[
"x"].
get<
int>(), json[
"y"].get<int>()};
else allFound =
false;
147 if(json.
count(
"text") > 0)
149 bool hasColor = json[
"text"].
count(
"color") > 0;
151 m_text = {json[
"text"][
"text"].
get<std::string>(), json[
"text"][
"wrap"].get<bool>(), c};
154 setObjectTypeByJson(json);
160 if(json.
count(
"polygon") > 0 && json[
"polygon"].
isArray())
162 auto &polygon = json.
array(
"polygon");
163 std::for_each(polygon.begin(), polygon.end(),[&](std::unique_ptr<IJson> &item)
166 m_polygon.emplace_back(j[
"x"].get<int>(), j[
"y"].get<int>());
171 if(json.
count(
"polyline") > 0 && json[
"polyline"].
isArray())
173 auto &polyline = json.
array(
"polyline");
174 std::for_each(polyline.begin(), polyline.end(),[&](std::unique_ptr<IJson> &item)
177 m_polyline.emplace_back(j[
"x"].get<int>(), j[
"y"].get<int>());
181 if(json.
count(
"properties") > 0 && json[
"properties"].
isArray())
183 auto &properties = json.
array(
"properties");
184 std::for_each(properties.begin(), properties.end(), [&](std::unique_ptr<IJson> &item)
186 m_properties.add(*item);
198 void tson::Object::setObjectTypeByJson(
IJson &json)
205 else if(json.
count(
"polygon") > 0)
207 else if(json.
count(
"polyline") > 0)
209 else if(json.
count(
"text") > 0)
211 else if(json.
count(
"gid") > 0)
213 else if(json.
count(
"template") > 0)
373 if(m_properties.hasProperty(name))
374 return m_properties.getProperty(name);
397 return ((m_flipFlags & flags) == flags) ? true :
false;
T get(std::string_view key)
Definition: IJson.hpp:72
virtual bool isArray() const =0
virtual size_t count(std::string_view key) const =0
virtual std::vector< std::unique_ptr< IJson > > array()=0
Definition: Object.hpp:18
const std::string & getTemplate() const
Definition: Object.hpp:296
bool hasFlipFlags(TileFlipFlags flags)
Definition: Object.hpp:395
T get(const std::string &name)
Definition: Object.hpp:96
const std::string & getName() const
Definition: Object.hpp:269
TileFlipFlags getFlipFlags() const
Definition: Object.hpp:382
const std::vector< tson::Vector2i > & getPolygons() const
Definition: Object.hpp:333
tson::Property * getProp(const std::string &name)
Definition: Object.hpp:371
const std::string & getType() const
Definition: Object.hpp:305
float getRotation() const
Definition: Object.hpp:287
const std::vector< tson::Vector2i > & getPolylines() const
Definition: Object.hpp:343
const Vector2i & getPosition() const
Definition: Object.hpp:323
const Vector2i & getSize() const
Definition: Object.hpp:251
ObjectType getObjectType() const
Definition: Object.hpp:224
bool isVisible() const
Definition: Object.hpp:314
uint32_t getGid() const
Definition: Object.hpp:242
const Text & getText() const
Definition: Object.hpp:361
bool isEllipse() const
Definition: Object.hpp:233
int getId() const
Definition: Object.hpp:260
bool parse(IJson &json)
Definition: Object.hpp:117
PropertyCollection & getProperties()
Definition: Object.hpp:352
bool isPoint() const
Definition: Object.hpp:278
Definition: PropertyCollection.hpp:15
Definition: Property.hpp:21
Definition: Base64.hpp:12
ObjectType
Definition: Enums.hpp:55
TileFlipFlags
Definition: Enums.hpp:74