Tileson  1.3.0
A helpful json parser for Tiled maps
WangTile.hpp
Go to the documentation of this file.
1 //
2 // Created by robin on 22.03.2020.
3 //
4 
5 #ifndef TILESON_WANGTILE_HPP
6 #define TILESON_WANGTILE_HPP
7 
8 //#include "../external/json.hpp"
9 
10 namespace tson
11 {
12  class WangTile
13  {
14  public:
15  inline WangTile() = default;
16  inline explicit WangTile(IJson &json);
17  inline bool parse(IJson &json);
18 
19  [[nodiscard]] inline bool hasDFlip() const;
20  [[nodiscard]] inline bool hasHFlip() const;
21  [[nodiscard]] inline uint32_t getTileid() const;
22  [[nodiscard]] inline bool hasVFlip() const;
23 
24  [[nodiscard]] inline const std::vector<uint32_t> &getWangIds() const;
25 
26  private:
27  bool m_dflip{};
28  bool m_hflip{};
29  uint32_t m_tileid{};
30  bool m_vflip{};
31  std::vector<uint32_t> m_wangId;
32  };
33 }
34 
36 {
37  parse(json);
38 }
39 
46 {
47  bool allFound = true;
48 
49  if(json.count("dflip") > 0) m_dflip = json["dflip"].get<bool>(); //Removed in Tiled v1.5 and is now optional
50  if(json.count("hflip") > 0) m_hflip = json["hflip"].get<bool>(); //Removed in Tiled v1.5 and is now optional
51  if(json.count("vflip") > 0) m_vflip = json["vflip"].get<bool>(); //Removed in Tiled v1.5 and is now optional
52 
53  if(json.count("tileid") > 0) m_tileid = json["tileid"].get<uint32_t>(); else allFound = false;
54  if(json.count("wangid") > 0 && json["wangid"].isArray())
55  {
56  auto &wangid = json.array("wangid");
57  std::for_each(wangid.begin(), wangid.end(), [&](std::unique_ptr<IJson> &item) { m_wangId.emplace_back(item->get<uint32_t>()); });
58  }
59 
60  return allFound;
61 }
62 
70 {
71  return m_dflip;
72 }
73 
81 {
82  return m_hflip;
83 }
84 
89 uint32_t tson::WangTile::getTileid() const
90 {
91  return m_tileid;
92 }
93 
101 {
102  return m_vflip;
103 }
104 
109 const std::vector<uint32_t> &tson::WangTile::getWangIds() const
110 {
111  return m_wangId;
112 }
113 
114 #endif //TILESON_WANGTILE_HPP
Definition: IJson.hpp:11
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: WangTile.hpp:13
bool hasHFlip() const
Definition: WangTile.hpp:80
WangTile()=default
bool hasDFlip() const
Definition: WangTile.hpp:69
uint32_t getTileid() const
Definition: WangTile.hpp:89
bool parse(IJson &json)
Definition: WangTile.hpp:45
bool hasVFlip() const
Definition: WangTile.hpp:100
const std::vector< uint32_t > & getWangIds() const
Definition: WangTile.hpp:109
Definition: Base64.hpp:12