-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSON_util.cpp
36 lines (34 loc) · 967 Bytes
/
JSON_util.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
33
34
35
36
#include "JSON_util.h"
#include "Sea.h"
#include "Coastal.h"
#include "Landlock.h"
#include <stdexcept>
using std::string;
using std::map;
using std::shared_ptr;
using std::invalid_argument;
Json::Value get_val(const string& key, const Json::Value& root)
{
Json::Value val = root[key];
if(!val)
throw invalid_argument("no '" + key + "' field");
return val;
}
// TODO add "landlock" to default_world.json
// TODO coastals need to specify coast nums of each adj coast
// TODO all Coastals need coast fields. Adjacent refers only to adjacent Landlocks
void set_terrs(const Json::Value& loc,
const Json::Value& locs,
map<string,shared_ptr<Terr>>& terrs)
{
string terrain = loc["terrain"].asString();
if(terrain == "sea") {
new Sea(loc, locs, terrs);
} else if(terrain == "landlock") {
new Landlock(loc, locs, terrs);
} else if(terrain == "coastal") {
new Coastal(loc, locs, terrs);
} else {
throw invalid_argument("unrecognized Terr subtype");
}
}