Tileson  1.3.0
A helpful json parser for Tiled maps
Frame.hpp
Go to the documentation of this file.
1 //
2 // Created by robin on 22.03.2020.
3 //
4 
5 #ifndef TILESON_FRAME_HPP
6 #define TILESON_FRAME_HPP
7 
8 //#include "../external/json.hpp"
9 
10 namespace tson
11 {
12  class Frame
13  {
14  public:
15  inline Frame() = default;
16  inline Frame(int duration, uint32_t tileId);
17  inline explicit Frame(IJson &json);
18 
19  inline bool parse(IJson &json);
20 
21  [[nodiscard]] inline int getDuration() const;
22  [[nodiscard]] inline uint32_t getTileId() const;
23 
24  private:
25  int m_duration {};
26  uint32_t m_tileId {};
27  };
28 }
29 
35 tson::Frame::Frame(int duration, uint32_t tileId) : m_duration {duration}, m_tileId {tileId}
36 {
37 
38 }
39 
45 {
46  parse(json);
47 }
48 
55 {
56  bool allFound = true;
57 
58  if(json.count("duration") > 0) m_duration = json["duration"].get<int>(); else allFound = false;
59  if(json.count("tileid") > 0) m_tileId = json["tileid"].get<uint32_t>() + 1; else allFound = false;
60 
61  return allFound;
62 }
63 
69 {
70  return m_duration;
71 }
72 
77 uint32_t tson::Frame::getTileId() const
78 {
79  return m_tileId;
80 }
81 
82 #endif //TILESON_FRAME_HPP
Definition: Frame.hpp:13
int getDuration() const
Definition: Frame.hpp:68
Frame()=default
uint32_t getTileId() const
Definition: Frame.hpp:77
bool parse(IJson &json)
Definition: Frame.hpp:54
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