From fe0db983ceac6fda3b019f703209166af0d3a4a8 Mon Sep 17 00:00:00 2001 From: William JCM Date: Thu, 2 Dec 2021 15:27:00 +0100 Subject: [PATCH] Mass: add tuning reading support. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Writing support SOON™. --- src/Mass/Mass.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++- src/Mass/Mass.h | 14 +++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/Mass/Mass.cpp b/src/Mass/Mass.cpp index 7b4a028..41464e3 100644 --- a/src/Mass/Mass.cpp +++ b/src/Mass/Mass.cpp @@ -177,9 +177,15 @@ void Mass::refreshValues() { if(!_demo) { getGlobalStyles(); + if(_state == State::Invalid) { + return; + } } - // TODO: tuning + getTuning(); + if(_state == State::Invalid) { + return; + } auto account_prop = _mass->at("Account"); if(!account_prop) { @@ -883,6 +889,47 @@ auto Mass::writeGlobalStyle(UnsignedLong index) -> bool { return setCustomStyle(_globalStyles[index], index, global_styles); } +void Mass::getTuning() { + getTuningCategory("Engine", _tuning.engineId, "Gears", _tuning.gearIds); + if(_state == State::Invalid) { + return; + } + + getTuningCategory("OS", _tuning.osId, "Modules", _tuning.moduleIds); + if(_state == State::Invalid) { + return; + } + + getTuningCategory("Architect", _tuning.archId, "Techs", _tuning.techIds); + if(_state == State::Invalid) { + return; + } +} + +auto Mass::engine() -> Int& { + return _tuning.engineId; +} + +auto Mass::gears() -> Containers::ArrayView { + return _tuning.gearIds; +} + +auto Mass::os() -> Int& { + return _tuning.osId; +} + +auto Mass::modules() -> Containers::ArrayView { + return _tuning.moduleIds; +} + +auto Mass::architecture() -> Int& { + return _tuning.archId; +} + +auto Mass::techs() -> Containers::ArrayView { + return _tuning.techIds; +} + auto Mass::updateSteamId(const std::string& steam_id) -> bool { _steamId = steam_id; @@ -1196,3 +1243,31 @@ auto Mass::writeWeaponType(const char* prop_name, Containers::ArrayView return _mass->saveToFile(); } + +void Mass::getTuningCategory(const char* big_node_prop_name, Int& big_node_id, + const char* small_nodes_prop_name, Containers::ArrayView small_nodes_ids) +{ + auto node_id = _mass->at(big_node_prop_name); + if(!node_id) { + _state = State::Invalid; + return; + } + big_node_id = node_id->value; + + auto node_ids = _mass->at(small_nodes_prop_name); + if(!node_ids) { + _state = State::Invalid; + return; + } + + if(node_ids->items.size() != small_nodes_ids.size()) { + _state = State::Invalid; + return; + } + + for(UnsignedInt i = 0; i < small_nodes_ids.size(); i++) { + auto small_node_id = node_ids->at(i); + CORRADE_INTERNAL_ASSERT(small_node_id); + small_nodes_ids[i] = small_node_id->value; + } +} diff --git a/src/Mass/Mass.h b/src/Mass/Mass.h index a161046..8ff8989 100644 --- a/src/Mass/Mass.h +++ b/src/Mass/Mass.h @@ -196,6 +196,17 @@ class Mass { void getGlobalStyles(); auto writeGlobalStyle(UnsignedLong index) -> bool; + void getTuning(); + + auto engine() -> Int&; + auto gears() -> Containers::ArrayView; + + auto os() -> Int&; + auto modules() -> Containers::ArrayView; + + auto architecture() -> Int&; + auto techs() -> Containers::ArrayView; + auto updateSteamId(const std::string& steam_id) -> bool; private: @@ -208,6 +219,9 @@ class Mass { void getWeaponType(const char* prop_name, Containers::ArrayView weapon_array); auto writeWeaponType(const char* prop_name, Containers::ArrayView weapon_array) -> bool; + void getTuningCategory(const char* big_node_prop_name, Int& big_node_id, + const char* small_nodes_prop_name, Containers::ArrayView small_nodes_ids); + Containers::Optional _mass; static std::string _lastError;