diff options
author | Aki <please@ignore.pl> | 2022-06-09 20:08:22 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-06-09 20:08:22 +0200 |
commit | e0de78eecfbc8898b028f191326e87f647d6aa5b (patch) | |
tree | 1041ba51f7a5638d5bc84bcdf5c48cd8f59443d1 /Snapshot.cpp | |
parent | b08f360cf92e76fabf5b762bf79032f60f751e30 (diff) | |
download | derelict-e0de78eecfbc8898b028f191326e87f647d6aa5b.zip derelict-e0de78eecfbc8898b028f191326e87f647d6aa5b.tar.gz derelict-e0de78eecfbc8898b028f191326e87f647d6aa5b.tar.bz2 |
Added group icons to wreck labels
Diffstat (limited to 'Snapshot.cpp')
-rw-r--r-- | Snapshot.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/Snapshot.cpp b/Snapshot.cpp index 99cf400..5d76e73 100644 --- a/Snapshot.cpp +++ b/Snapshot.cpp @@ -5,11 +5,13 @@ #include <string> #include <unordered_map> #include <vector> +#include <iostream> #include <nlohmann/json.hpp> #include <raylib.h> #include "Killmail.h" +#include "Owner.h" using json = nlohmann::json; @@ -24,7 +26,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LongVector3, x, y, z) Snapshot::Snapshot(const char* filename) : - m_killmails {} + m_killmails {}, + m_teams {} { if (!FileExists(filename)) throw "File does not exist"; @@ -38,6 +41,14 @@ Snapshot::Snapshot(const char* filename) : dump.at("killmails").get_to(m_killmails); for (auto& km : m_killmails) km.group = group_lookup[km.ship]; + int team = 0; + for (const auto& members : dump.at("teams")) { + for (const auto& entry : members) { + const auto id = entry.get<long int>(); + m_teams[id] = team; + } + ++team; + } UnloadFileText(text); } @@ -49,6 +60,25 @@ Snapshot::killmails() const } +int +Snapshot::team(const Owner& owner) const +{ + auto find = [this](long int id) -> int { + if (id < 0) + return -1; + const auto search = m_teams.find(id); + if (search == m_teams.end()) + return -1; + return search->second; + }; + int id; + if ((id = find(owner.faction)) != -1) return id; + if ((id = find(owner.alliance)) != -1) return id; + if ((id = find(owner.corporation)) != -1) return id; + return -1; +} + + void from_json(const json& j, tm& d) { |