#include "BuildAbilities.hpp" #include "json.hpp" #include using json = nlohmann::json; #define GET(o, objectKey, key) \ auto& _##objectKey = o[#objectKey]; \ if (_##objectKey.is_null()) { \ auto errorKeyFunc = [=]() { return key; }; \ std::cout << "Failed to retrieve key '" << #objectKey << "' for object with key '" << errorKeyFunc() << path \ << "'\n"; \ return nullptr; \ } CreatureLib::Library::TalentLibrary* BuildAbilities::Build(const std::string& path) { std::ifstream fileStream(path.c_str()); if (fileStream.fail()) { std::cout << "Failed to load Abilities data file at '" << path << "'\n"; return nullptr; } auto lib = new CreatureLib::Library::TalentLibrary(); json j; fileStream >> j; for (const auto& i : j.items()) { if (i.key().starts_with("$")) { continue; } auto& val = i.value(); auto _effect = val["effect"]; auto _parameters = val["parameters"]; ArbUt::StringView effectName = ""_cnc; if (!_effect.empty()) { effectName = ArbUt::StringView(_effect.get().c_str(), _effect.get().length()); } ArbUt::List realParameters; if (!_parameters.empty()) { for (auto& kv : _parameters.items()) { auto& p = kv.value(); auto t = p.type(); switch (t) { case json::value_t::boolean: realParameters.Append(new CreatureLib::Library::EffectParameter(p.get())); break; case json::value_t::number_integer: case json::value_t::number_unsigned: realParameters.Append(new CreatureLib::Library::EffectParameter(p.get())); break; case json::value_t::number_float: realParameters.Append(new CreatureLib::Library::EffectParameter(p.get())); break; default: continue; } } } auto key = ArbUt::StringView(i.key().c_str(), i.key().length()); lib->Insert(key, new CreatureLib::Library::Talent(key, effectName, realParameters)); } return lib; }