Parse Moves.
This commit is contained in:
48
src/BuildData/BuildMoves.cpp
Normal file
48
src/BuildData/BuildMoves.cpp
Normal file
@@ -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;
|
||||
}
|
||||
11
src/BuildData/BuildMoves.hpp
Normal file
11
src/BuildData/BuildMoves.hpp
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user