-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (37 loc) · 1.56 KB
/
main.cpp
File metadata and controls
45 lines (37 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "src/Manager.h"
std::string determinePath();
int main() {
std::vector<float> positions;
Sprite spruce(determinePath());
Sprite cherryBlossomTree("../assets/cherry-blossom-tree.svg");
Manager manager(spruce, cherryBlossomTree, positions);
manager.init();
}
std::string determinePath() {
std::ifstream ifs("../config.json");
if (!ifs.is_open()) {
throw std::runtime_error("JsonFileManager::determinePath: Could not open json file ('../config.json')");
}
std::stringstream buffer;
buffer << ifs.rdbuf();
std::string jsonString = buffer.str();
ifs.close();
rapidjson::Document doc;
doc.Parse(jsonString.c_str());
if (doc.HasParseError()) {
throw std::runtime_error("JsonFileManager::determinePath: Failed to parse json file");
}
std::string colorsAllowed[8] = { "mystic", "golden", "frost", "emerald", "purple", "yellow", "blue", "green" };
std::string toReturn[8] = { "spruce-purple", "spruce-yellow", "spruce-blue", "spruce-green", "spruce-purple", "spruce-yellow", "spruce-blue", "spruce-green" };
if (doc.HasMember("currColor") && doc["currColor"].IsString()) {
for (int i = 0; i < 8; i++) {
if (colorsAllowed[i] == doc["currColor"].GetString()) {
return "../assets/" + toReturn[i] + ".svg";
}
}
throw std::runtime_error("JsonFileManager::determinePath: Invalid color set in config");
} else {
throw std::runtime_error("JsonFileManager::determinePath: Missing or invalid 'currColor'");
}
return "";
}