Tileson  1.3.0
A helpful json parser for Tiled maps
Grid.hpp
Go to the documentation of this file.
1 //
2 // Created by robin on 22.03.2020.
3 //
4 
5 #ifndef TILESON_GRID_HPP
6 #define TILESON_GRID_HPP
7 
8 #include "../objects/Vector2.hpp"
9 #include <string>
10 //#include "../external/json.hpp"
11 
12 namespace tson
13 {
14  class Grid
15  {
16  public:
17  inline Grid() = default;
18  inline explicit Grid(IJson &json);
19 
20  inline bool parse(IJson &json);
21 
22  [[nodiscard]] inline const std::string &getOrientation() const;
23  [[nodiscard]] inline const Vector2i &getSize() const;
24 
25  private:
26  std::string m_orientation;
27  tson::Vector2i m_size;
28  };
29 }
30 
36 {
37  parse(json);
38 }
39 
46 {
47  bool allFound = true;
48 
49  if(json.count("orientation") > 0) m_orientation = json["orientation"].get<std::string>(); //Optional
50 
51  if(json.count("width") > 0 && json.count("height") > 0)
52  m_size = {json["width"].get<int>(), json["height"].get<int>()}; else allFound = false;
53 
54  return allFound;
55 }
56 
61 const std::string &tson::Grid::getOrientation() const
62 {
63  return m_orientation;
64 }
65 
71 {
72  return m_size;
73 }
74 
75 #endif //TILESON_GRID_HPP
Definition: Grid.hpp:15
bool parse(IJson &json)
Definition: Grid.hpp:45
const Vector2i & getSize() const
Definition: Grid.hpp:70
Grid()=default
const std::string & getOrientation() const
Definition: Grid.hpp:61
Definition: IJson.hpp:11
T get(std::string_view key)
Definition: IJson.hpp:72
virtual size_t count(std::string_view key) const =0
Definition: Base64.hpp:12