2021-08-22 10:10:26 +00:00
|
|
|
#include "GrowthRatesBuilder.hpp"
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2021-08-28 14:52:47 +00:00
|
|
|
#include "json.hpp"
|
2021-08-22 10:10:26 +00:00
|
|
|
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;
|
|
|
|
}
|