Tileson  1.3.0
A helpful json parser for Tiled maps
WorldMapData.hpp
Go to the documentation of this file.
1 //
2 // Created by robin on 01.08.2020.
3 //
4 
5 #ifndef TILESON_WORLDMAPDATA_HPP
6 #define TILESON_WORLDMAPDATA_HPP
7 
8 namespace tson
9 {
11  {
12  public:
13  inline WorldMapData(const fs::path &folder_, IJson &json);
14  inline void parse(const fs::path &folder_, IJson &json);
15  //inline WorldMapData(fs::path folder_, std::string fileName_) : folder {std::move(folder_)}, fileName {fileName_}
16  //{
17  // path = folder / fileName;
18  //}
19 
20  fs::path folder;
21  fs::path path;
22  std::string fileName;
25  };
26 
27  WorldMapData::WorldMapData(const fs::path &folder_, IJson &json)
28  {
29  parse(folder_, json);
30  }
31 
32  void WorldMapData::parse(const fs::path &folder_, IJson &json)
33  {
34  folder = folder_;
35  if(json.count("fileName") > 0) fileName = json["fileName"].get<std::string>();
36  if(json.count("height") > 0) size = {json["width"].get<int>(), json["height"].get<int>()};
37  if(json.count("x") > 0) position = {json["x"].get<int>(), json["y"].get<int>()};
38 
39  path = (!fileName.empty()) ? folder / fileName : folder;
40  }
41 }
42 
43 #endif //TILESON_WORLDMAPDATA_HPP
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: WorldMapData.hpp:11
void parse(const fs::path &folder_, IJson &json)
Definition: WorldMapData.hpp:32
std::string fileName
Definition: WorldMapData.hpp:22
tson::Vector2i position
Definition: WorldMapData.hpp:24
fs::path path
Definition: WorldMapData.hpp:21
WorldMapData(const fs::path &folder_, IJson &json)
Definition: WorldMapData.hpp:27
fs::path folder
Definition: WorldMapData.hpp:20
tson::Vector2i size
Definition: WorldMapData.hpp:23
Definition: Base64.hpp:12