Builds Growth Rates library.
This commit is contained in:
parent
dfa7e79ab2
commit
380086d358
|
@ -28,7 +28,7 @@ static CreatureLib::Library::ItemCategory ParseItemCategory(std::string& in){
|
|||
PkmnLib::Library::ItemLibrary* BuildItems::Build(const std::string& path) {
|
||||
std::ifstream fileStream(path.c_str());
|
||||
if (fileStream.fail()) {
|
||||
std::cout << "Failed to load Move data file at '" << path << "'\n";
|
||||
std::cout << "Failed to load Items data file at '" << path << "'\n";
|
||||
return nullptr;
|
||||
}
|
||||
auto lib = new PkmnLib::Library::ItemLibrary();
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#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(name, new LookupGrowthRate(values.get<std::vector<uint32_t >>()));
|
||||
}
|
||||
|
||||
return lib;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef GEN7TESTS_GROWTHRATESBUILDER_HPP
|
||||
#define GEN7TESTS_GROWTHRATESBUILDER_HPP
|
||||
|
||||
#include <CreatureLib/Library/GrowthRates/GrowthRate.hpp>
|
||||
#include <CreatureLib/Library/GrowthRates/GrowthRateLibrary.hpp>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
class LookupGrowthRate : public CreatureLib::Library::GrowthRate {
|
||||
std::vector<uint32_t> _experience;
|
||||
|
||||
public:
|
||||
LookupGrowthRate(std::vector<uint32_t> experience) : _experience(std::move(experience)) {}
|
||||
|
||||
[[nodiscard]] uint8_t CalculateLevel(uint32_t experience) const override {
|
||||
for (size_t i = 0; i < _experience.size(); i++) {
|
||||
if (_experience[i] > experience) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return _experience[_experience.size() - 1];
|
||||
}
|
||||
|
||||
[[nodiscard]] uint32_t CalculateExperience(uint8_t level) const override { return _experience[level - 1]; }
|
||||
};
|
||||
|
||||
class GrowthRatesBuilder {
|
||||
public:
|
||||
static CreatureLib::Library::GrowthRateLibrary* Build(const std::string& file);
|
||||
};
|
||||
|
||||
#endif // GEN7TESTS_GROWTHRATESBUILDER_HPP
|
12
src/main.cpp
12
src/main.cpp
|
@ -5,6 +5,7 @@
|
|||
#include "BuildData/BuildNatures.hpp"
|
||||
#include "BuildData/BuildSpecies.hpp"
|
||||
#include "BuildData/BuildTypes.hpp"
|
||||
#include "BuildData/GrowthRatesBuilder.hpp"
|
||||
#include "Library.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
@ -15,13 +16,15 @@ int main(int argc, char* argv[]) {
|
|||
std::string pokemonFile = "Pokemon.json";
|
||||
std::string moveFile = "Moves.json";
|
||||
std::string itemsFile = "Items.json";
|
||||
std::string growthRatesFile = "GrowthRates.json";
|
||||
|
||||
using namespace Catch::clara;
|
||||
auto cli = session.cli() | Opt(pokemonFile, "Species")["--species"]("Which species file to load.") |
|
||||
Opt(typesFile, "Types")["--types"]("Which Types file to load.") |
|
||||
Opt(naturesFile, "Natures")["--natures"]("Which Natures file to load.") |
|
||||
Opt(moveFile, "Moves")["--moves"]("Which Moves file to load.") |
|
||||
Opt(itemsFile, "Items")["--items"]("Which Items file to load.");
|
||||
Opt(itemsFile, "Items")["--items"]("Which Items file to load.") |
|
||||
Opt(growthRatesFile, "Growthrates")["--growthrates"]("Which Growthrates file to load.");
|
||||
|
||||
session.cli(cli);
|
||||
|
||||
|
@ -34,14 +37,15 @@ int main(int argc, char* argv[]) {
|
|||
auto speciesLibrary = BuildSpecies::BuildLibrary(pokemonFile, typesLibrary);
|
||||
auto movesLibrary = BuildMoves::Build(moveFile, typesLibrary);
|
||||
auto itemsLibrary = BuildItems::Build(itemsFile);
|
||||
auto growthRates = GrowthRatesBuilder::Build(growthRatesFile);
|
||||
|
||||
if (typesLibrary == nullptr || speciesLibrary == nullptr || natureLibrary == nullptr || movesLibrary == nullptr ||
|
||||
itemsLibrary == nullptr)
|
||||
itemsLibrary == nullptr || growthRates == nullptr)
|
||||
return 1;
|
||||
|
||||
auto settings = new PkmnLib::Library::LibrarySettings(100, 4, 4096);
|
||||
auto library = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, movesLibrary, itemsLibrary, nullptr,
|
||||
typesLibrary, natureLibrary);
|
||||
auto library = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, movesLibrary, itemsLibrary,
|
||||
growthRates, typesLibrary, natureLibrary);
|
||||
|
||||
Library::SetStaticLib(library);
|
||||
|
||||
|
|
Loading…
Reference in New Issue