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);
39 inline bool parseTiled15Props(
IJson &json);
43 std::vector<tson::WangTile> m_wangTiles;
44 std::vector<tson::WangColor> m_cornerColors;
45 std::vector<tson::WangColor> m_edgeColors;
49 std::vector<tson::WangColor> m_colors;
62 return m_properties.getValue<T>(name);
75 if(json.
count(
"tile") > 0) m_tile = json[
"tile"].
get<
int>();
else allFound =
false;
76 if(json.
count(
"name") > 0) m_name = json[
"name"].get<std::string>();
else allFound =
false;
79 if(json.
count(
"wangtiles") > 0 && json[
"wangtiles"].
isArray())
81 auto &wangtiles = json.
array(
"wangtiles");
82 std::for_each(wangtiles.begin(), wangtiles.end(), [&](std::unique_ptr<IJson> &item) { m_wangTiles.emplace_back(*item); });
84 if(json.
count(
"cornercolors") > 0 && json[
"cornercolors"].
isArray())
86 auto &cornercolors = json.
array(
"cornercolors");
87 std::for_each(cornercolors.begin(), cornercolors.end(), [&](std::unique_ptr<IJson> &item) { m_cornerColors.emplace_back(*item); });
89 if(json.
count(
"edgecolors") > 0 && json[
"edgecolors"].
isArray())
91 auto &edgecolors = json.
array(
"edgecolors");
92 std::for_each(edgecolors.begin(), edgecolors.end(), [&](std::unique_ptr<IJson> &item) { m_edgeColors.emplace_back(*item); });
94 if(json.
count(
"properties") > 0 && json[
"properties"].
isArray())
96 auto &properties = json.
array(
"properties");
97 std::for_each(properties.begin(), properties.end(), [&](std::unique_ptr<IJson> &item) { m_properties.add(*item); });
100 if(!parseTiled15Props(json))
112 bool tson::WangSet::parseTiled15Props(
tson::IJson &json)
114 if(json.
count(
"colors") > 0 && json[
"colors"].isArray())
116 auto &colors = json.
array(
"colors");
117 std::for_each(colors.begin(), colors.end(), [&](std::unique_ptr<IJson> &item) { m_colors.emplace_back(*item); });
155 return m_cornerColors;
183 if(m_properties.hasProperty(name))
184 return m_properties.getProperty(name);
207 auto color = std::find_if(m_colors.begin(), m_colors.end(), [&](
const auto &c) { return c.getName() == name; });
209 if(color != m_colors.end())
210 return &color.operator*();
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: PropertyCollection.hpp:15
Definition: Property.hpp:21
Definition: WangColor.hpp:14
Definition: WangSet.hpp:16
const std::vector< tson::WangColor > & getColors() const
Definition: WangSet.hpp:193
int getTile() const
Definition: WangSet.hpp:135
bool parse(IJson &json)
Definition: WangSet.hpp:71
PropertyCollection & getProperties()
Definition: WangSet.hpp:171
const std::vector< tson::WangTile > & getWangTiles() const
Definition: WangSet.hpp:144
const std::string & getName() const
Definition: WangSet.hpp:126
const std::vector< tson::WangColor > & getEdgeColors() const
Definition: WangSet.hpp:162
tson::WangColor * getColor(const std::string &name)
Definition: WangSet.hpp:205
const std::vector< tson::WangColor > & getCornerColors() const
Definition: WangSet.hpp:153
tson::Property * getProp(const std::string &name)
Definition: WangSet.hpp:181
T get(const std::string &name)
Definition: WangSet.hpp:60
Definition: Base64.hpp:12