diff --git a/src/BuildData/BuildMoves.cpp b/src/BuildData/BuildMoves.cpp new file mode 100644 index 0000000..cb1bdfb --- /dev/null +++ b/src/BuildData/BuildMoves.cpp @@ -0,0 +1,48 @@ +#include "BuildMoves.hpp" +#include +#include +#include "../../extern/json.hpp" +using json = nlohmann::json; + +#define GET(o, objectKey, key) \ + auto _##objectKey = o[#objectKey]; \ + if (_##objectKey.is_null()) { \ + std::cout << "Failed to retrieve key '" << #objectKey << "' for object with value '" << key << "' in file '" \ + << path << "'\n"; \ + return nullptr; \ + } + +PkmnLib::Library::MoveLibrary* BuildMoves::Build(const std::string& path, + const CreatureLib::Library::TypeLibrary* types) { + std::ifstream fileStream(path.c_str()); + if (fileStream.fail()) { + std::cout << "Failed to load Move data file at '" << path << "'\n"; + return nullptr; + } + auto lib = new PkmnLib::Library::MoveLibrary(); + json j; + fileStream >> j; + for (auto i : j.items()) { + auto val = i.value(); + GET(val, name, i); + GET(val, type, i); + GET(val, power, i); + GET(val, pp, i); + GET(val, accuracy, i); + GET(val, priority, i); + GET(val, target, i); + GET(val, category, i); + GET(val, flags, i); + if (_pp.get() == 0) + continue; + auto type = types->GetTypeId(_type.get()); + auto move = new PkmnLib::Library::MoveData( + _name.get(), type, PkmnLib::Library::MoveCategory ::Physical, _power.get(), + _accuracy.get(), _pp.get(), CreatureLib::Library::AttackTarget::Any, + _priority.get(), _flags.get>()); + + lib->LoadAttack(move->GetName(),move); + } + + return lib; +} diff --git a/src/BuildData/BuildMoves.hpp b/src/BuildData/BuildMoves.hpp new file mode 100644 index 0000000..5501498 --- /dev/null +++ b/src/BuildData/BuildMoves.hpp @@ -0,0 +1,11 @@ +#ifndef GEN7TESTS_BUILDMOVES_HPP +#define GEN7TESTS_BUILDMOVES_HPP + +#include +#include +class BuildMoves { +public: + static PkmnLib::Library::MoveLibrary* Build(const std::string& path, const CreatureLib::Library::TypeLibrary* types); +}; + +#endif // GEN7TESTS_BUILDMOVES_HPP diff --git a/src/main.cpp b/src/main.cpp index ec266a6..758a6ea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #define CATCH_CONFIG_RUNNER #include "../extern/catch.hpp" +#include "BuildData/BuildMoves.hpp" #include "BuildData/BuildNatures.hpp" #include "BuildData/BuildSpecies.hpp" #include "BuildData/BuildTypes.hpp" @@ -11,11 +12,13 @@ int main(int argc, char* argv[]) { std::string typesFile = "Types.csv"; std::string naturesFile = "Natures.csv"; std::string pokemonFile = "Pokemon.json"; + std::string moveFile = "Moves.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(naturesFile, "Natures")["--natures"]("Which Natures file to load."); + Opt(moveFile, "Moves")["--moves"]("Which Moves file to load."); session.cli(cli); @@ -26,12 +29,13 @@ int main(int argc, char* argv[]) { auto typesLibrary = BuildTypes::Build(typesFile); auto natureLibrary = BuildNatures::Build(naturesFile); auto speciesLibrary = BuildSpecies::BuildLibrary(pokemonFile, typesLibrary); + auto movesLibrary = BuildMoves::Build(moveFile, typesLibrary); - if (typesLibrary == nullptr || speciesLibrary == nullptr || natureLibrary == nullptr) + if (typesLibrary == nullptr || speciesLibrary == nullptr || natureLibrary == nullptr || movesLibrary == nullptr) return 1; auto settings = new PkmnLib::Library::LibrarySettings(100, 4, 4096); - auto library = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, nullptr, nullptr, nullptr, + auto library = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, movesLibrary, nullptr, nullptr, typesLibrary, natureLibrary); Library::SetStaticLib(library);