BuildData/GrowthRatesBuilder.cpp

26 lines
787 B
C++

#include "GrowthRatesBuilder.hpp"
#include <fstream>
#include <iostream>
#include "../../extern/json.hpp"
using json = nlohmann::json;
CreatureLib::Library::GrowthRateLibrary* GrowthRatesBuilder::Build(const std::string& path) {
std::ifstream fileStream(path.c_str());
if (fileStream.fail()) {
std::cout << "Failed to load Pokemon data file at '" << path << "'\n";
return nullptr;
}
auto lib = new CreatureLib::Library::GrowthRateLibrary();
json j;
fileStream >> j;
for (const auto& i : j.items()) {
const auto& name = i.key();
auto values = i.value();
lib->AddGrowthRate(ArbUt::StringView(name.c_str()),
new LookupGrowthRate(values.get<std::vector<uint32_t>>()));
}
return lib;
}