blob: 1fdf7a8aef50c3858082e6aad3323485547a067d (
plain)
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 "DumpSource.h"
#include <string>
#include <utility>
#include <vector>
#include <nlohmann/json.hpp>
#include <raylib.h>
#include "Killmail.h"
using json = nlohmann::json;
DumpSource::DumpSource(const char* filename) :
m_killmails {}
{
if (!FileExists(filename))
throw "File does not exist";
char* text = LoadFileText(filename);
auto dump = json::parse(text);
for (const auto& info : dump["killmails"]) {
Killmail km;
km.position = {
info["victim"]["position"]["x"].get<long double>(),
info["victim"]["position"]["y"].get<long double>(),
info["victim"]["position"]["z"].get<long double>(),
};
auto id = info["solar_system_id"].get<long int>();
auto location = dump["locations"][std::to_string(id)];
km.location.system = location["name"].get<std::string>().data();
km.location.constellation = location["constellation"].get<std::string>().data();
km.location.region = location["region"].get<std::string>().data();
m_killmails.push_back(std::move(km));
}
UnloadFileText(text);
}
std::vector<Killmail>
DumpSource::killmails() const
{
return m_killmails;
}
|