5#ifndef TILESON_WANGSET_HPP
6#define TILESON_WANGSET_HPP
11#include "../objects/PropertyCollection.hpp"
22 [[nodiscard]]
inline const std::string &
getName()
const;
23 [[nodiscard]]
inline int getTile()
const;
25 [[nodiscard]]
inline const std::vector<tson::WangTile> &
getWangTiles()
const;
26 [[nodiscard]]
inline const std::vector<tson::WangColor> &
getCornerColors()
const;
27 [[nodiscard]]
inline const std::vector<tson::WangColor> &
getEdgeColors()
const;
30 inline const std::vector<tson::WangColor> &
getColors()
const;
34 inline T
get(
const std::string &name);
37 [[nodiscard]]
inline const std::string &
getClassType()
const;
42 inline bool parseTiled15Props(
IJson &json);
46 std::vector<tson::WangTile> m_wangTiles;
47 std::vector<tson::WangColor> m_cornerColors;
48 std::vector<tson::WangColor> m_edgeColors;
52 std::vector<tson::WangColor> m_colors;
55 std::string m_classType {};
56 std::shared_ptr<tson::TiledClass> m_class {};
69 return m_properties.getValue<T>(name);
83 if(json.
count(
"tile") > 0) m_tile = json[
"tile"].
get<
int>();
else allFound =
false;
84 if(json.
count(
"name") > 0) m_name = json[
"name"].get<std::string>();
else allFound =
false;
87 if(json.
count(
"wangtiles") > 0 && json[
"wangtiles"].
isArray())
89 auto &wangtiles = json.
array(
"wangtiles");
90 std::for_each(wangtiles.begin(), wangtiles.end(), [&](std::unique_ptr<IJson> &item) { m_wangTiles.emplace_back(*item); });
92 if(json.
count(
"cornercolors") > 0 && json[
"cornercolors"].
isArray())
94 auto &cornercolors = json.
array(
"cornercolors");
95 std::for_each(cornercolors.begin(), cornercolors.end(), [&](std::unique_ptr<IJson> &item) { m_cornerColors.emplace_back(*item, m_map); });
97 if(json.
count(
"edgecolors") > 0 && json[
"edgecolors"].
isArray())
99 auto &edgecolors = json.
array(
"edgecolors");
100 std::for_each(edgecolors.begin(), edgecolors.end(), [&](std::unique_ptr<IJson> &item) { m_edgeColors.emplace_back(*item, m_map); });
102 if(json.
count(
"properties") > 0 && json[
"properties"].
isArray())
104 auto &properties = json.
array(
"properties");
105 std::for_each(properties.begin(), properties.end(), [&](std::unique_ptr<IJson> &item) { m_properties.add(*item); });
108 if(json.
count(
"class") > 0) m_classType = json[
"class"].
get<std::string>();
110 if(!parseTiled15Props(json))
122bool tson::WangSet::parseTiled15Props(
tson::IJson &json)
124 if(json.
count(
"colors") > 0 && json[
"colors"].isArray())
126 auto &colors = json.
array(
"colors");
127 std::for_each(colors.begin(), colors.end(), [&](std::unique_ptr<IJson> &item) { m_colors.emplace_back(*item, m_map); });
165 return m_cornerColors;
193 if(m_properties.hasProperty(name))
194 return m_properties.getProperty(name);
217 auto color = std::find_if(m_colors.begin(), m_colors.end(), [&](
const auto &c) { return c.getName() == name; });
219 if(color != m_colors.end())
220 return &color.operator*();
T get(std::string_view key)
Definition IJson.hpp:82
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 PropertyCollection.hpp:15
Definition Property.hpp:23
Definition TiledClass.hpp:11
Definition WangColor.hpp:14
Definition WangSet.hpp:16
const std::string & getClassType() const
Definition WangSet.hpp:225
const std::vector< tson::WangColor > & getColors() const
Definition WangSet.hpp:203
int getTile() const
Definition WangSet.hpp:145
PropertyCollection & getProperties()
Definition WangSet.hpp:181
const std::vector< tson::WangTile > & getWangTiles() const
Definition WangSet.hpp:154
tson::TiledClass * getClass()
Definition tileson_forward.hpp:528
bool parse(IJson &json, tson::Map *map)
Definition WangSet.hpp:78
const std::string & getName() const
Definition WangSet.hpp:136
const std::vector< tson::WangColor > & getEdgeColors() const
Definition WangSet.hpp:172
tson::WangColor * getColor(const std::string &name)
Definition WangSet.hpp:215
const std::vector< tson::WangColor > & getCornerColors() const
Definition WangSet.hpp:163
tson::Property * getProp(const std::string &name)
Definition WangSet.hpp:191
T get(const std::string &name)
Definition WangSet.hpp:67