Deep RTS
ResourceLoader.h
Go to the documentation of this file.
1//
2// Created by per-arne on 02.04.17.
3//
4
5#ifndef DEEPRTS_RESOURCELOADER_H
6#define DEEPRTS_RESOURCELOADER_H
7
8#include <nlohmann/json.hpp>
9
13 std::unordered_map<int, std::string> tileID2Type;
14 std::unordered_map<std::string, nlohmann::json> tileData;
15
17 auto &tileType = tileID2Type[tileID];
18 auto &tData = tileData[tileType];
19 return tData;
20 }
21};
22
25public:
28
31
32
33private:
37 static std::string getFilePath(const std::string& fileName);
38
40 bool mapLoaded = false;
41
43 bool tilesLoaded = true;
44
46 void loadTileJSON();
47
50 loadTileJSON();
51 }
52
53public:
56 void loadMapJSON(const std::string& map_file);
57
58 // C++ 11
59 // =======
60 // We can use the better technique of deleting the methods
61 // we don't want.
62public:
64 void operator=(ResourceLoader const&) = delete;
65
67 // Note: Scott Meyers mentions in his Effective Modern
68 // C++ book, that deleted functions should generally
69 // be public as it results in better error messages
70 // due to the compilers behavior to check accessibility
71 // before deleted status
73 {
74 static ResourceLoader instance; // Guaranteed to be destroyed.
75 // Instantiated on first use.
76 return instance;
77 }
78
79 static TilePropertyData loadMAPJson(const nlohmann::json& tJSON);
80};
81
82
83#endif //DEEPRTS_RESOURCELOADER_H
nlohmann::json json
Definition: Websockets.cpp:17
The resourceLoader is primarily used to load maps.
Definition: ResourceLoader.h:24
static TilePropertyData loadMAPJson(const nlohmann::json &tJSON)
Definition: ResourceLoader.cpp:71
TilePropertyData tileData
Definition: ResourceLoader.h:66
nlohmann::json tileJSON
json object of the tile metadata
Definition: ResourceLoader.h:30
static ResourceLoader & getInstance()
Definition: ResourceLoader.h:72
void operator=(ResourceLoader const &)=delete
ResourceLoader(ResourceLoader const &)=delete
void loadMapJSON(const std::string &map_file)
Definition: ResourceLoader.cpp:44
nlohmann::json mapJSON
json object of the map
Definition: ResourceLoader.h:27
Definition: ResourceLoader.h:12
std::unordered_map< int, std::string > tileID2Type
Definition: ResourceLoader.h:13
nlohmann::json & getTileData(int tileID)
Definition: ResourceLoader.h:16
std::unordered_map< std::string, nlohmann::json > tileData
Definition: ResourceLoader.h:14