Parse Moves.
This commit is contained in:
parent
f6ae8432b3
commit
5a7ff141eb
|
@ -0,0 +1,48 @@
|
||||||
|
#include "BuildMoves.hpp"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#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<uint8_t >() == 0)
|
||||||
|
continue;
|
||||||
|
auto type = types->GetTypeId(_type.get<std::string>());
|
||||||
|
auto move = new PkmnLib::Library::MoveData(
|
||||||
|
_name.get<std::string>(), type, PkmnLib::Library::MoveCategory ::Physical, _power.get<uint8_t>(),
|
||||||
|
_accuracy.get<uint8_t>(), _pp.get<uint8_t>(), CreatureLib::Library::AttackTarget::Any,
|
||||||
|
_priority.get<int8_t>(), _flags.get<std::unordered_set<std::string>>());
|
||||||
|
|
||||||
|
lib->LoadAttack(move->GetName(),move);
|
||||||
|
}
|
||||||
|
|
||||||
|
return lib;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef GEN7TESTS_BUILDMOVES_HPP
|
||||||
|
#define GEN7TESTS_BUILDMOVES_HPP
|
||||||
|
|
||||||
|
#include <CreatureLib/Library/TypeLibrary.hpp>
|
||||||
|
#include <PkmnLib/Library/Moves/MoveLibrary.hpp>
|
||||||
|
class BuildMoves {
|
||||||
|
public:
|
||||||
|
static PkmnLib::Library::MoveLibrary* Build(const std::string& path, const CreatureLib::Library::TypeLibrary* types);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GEN7TESTS_BUILDMOVES_HPP
|
|
@ -1,5 +1,6 @@
|
||||||
#define CATCH_CONFIG_RUNNER
|
#define CATCH_CONFIG_RUNNER
|
||||||
#include "../extern/catch.hpp"
|
#include "../extern/catch.hpp"
|
||||||
|
#include "BuildData/BuildMoves.hpp"
|
||||||
#include "BuildData/BuildNatures.hpp"
|
#include "BuildData/BuildNatures.hpp"
|
||||||
#include "BuildData/BuildSpecies.hpp"
|
#include "BuildData/BuildSpecies.hpp"
|
||||||
#include "BuildData/BuildTypes.hpp"
|
#include "BuildData/BuildTypes.hpp"
|
||||||
|
@ -11,11 +12,13 @@ int main(int argc, char* argv[]) {
|
||||||
std::string typesFile = "Types.csv";
|
std::string typesFile = "Types.csv";
|
||||||
std::string naturesFile = "Natures.csv";
|
std::string naturesFile = "Natures.csv";
|
||||||
std::string pokemonFile = "Pokemon.json";
|
std::string pokemonFile = "Pokemon.json";
|
||||||
|
std::string moveFile = "Moves.json";
|
||||||
|
|
||||||
using namespace Catch::clara;
|
using namespace Catch::clara;
|
||||||
auto cli = session.cli() | Opt(pokemonFile, "Species")["--species"]("Which species file to load.") |
|
auto cli = session.cli() | Opt(pokemonFile, "Species")["--species"]("Which species file to load.") |
|
||||||
Opt(typesFile, "Types")["--types"]("Which Types 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);
|
session.cli(cli);
|
||||||
|
|
||||||
|
@ -26,12 +29,13 @@ int main(int argc, char* argv[]) {
|
||||||
auto typesLibrary = BuildTypes::Build(typesFile);
|
auto typesLibrary = BuildTypes::Build(typesFile);
|
||||||
auto natureLibrary = BuildNatures::Build(naturesFile);
|
auto natureLibrary = BuildNatures::Build(naturesFile);
|
||||||
auto speciesLibrary = BuildSpecies::BuildLibrary(pokemonFile, typesLibrary);
|
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;
|
return 1;
|
||||||
|
|
||||||
auto settings = new PkmnLib::Library::LibrarySettings(100, 4, 4096);
|
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);
|
typesLibrary, natureLibrary);
|
||||||
|
|
||||||
Library::SetStaticLib(library);
|
Library::SetStaticLib(library);
|
||||||
|
|
Loading…
Reference in New Issue