-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.cpp
32 lines (30 loc) · 862 Bytes
/
loader.cpp
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
#include "loader.h"
#include "tower/tower.h"
#include "tower/attackbuilder.h"
#include "nlohmann/json.hpp"
#include <fstream>
#include <iostream>
using json = nlohmann::json;
std::vector<Tower> loadTowers() {
std::vector<Tower> towers = std::vector<Tower>();
std::fstream towerFile("resources/towers.json");
try {
json towerJsons;
towerFile >> towerJsons;
for (json::iterator towerIt = towerJsons.begin(); towerIt != towerJsons.end(); ++towerIt) {
try {
Tower tower = Tower(towerIt.key(), towerIt.value());
towers.push_back(tower);
}
catch (json::exception &e) {
std::cout << "Error parsing tower " << towerIt.key() << ":" << std::endl;
std::cout << e.what() << std::endl;
}
}
}
catch (json::parse_error &e) {
std::cout << "Error reading file:" << std::endl;
std::cout << e.what() << std::endl;
}
return towers;
}