BuildData/BuildLibrary.hpp

62 lines
2.8 KiB
C++

#ifndef PKMNLIB_AI_BUILDLIBRARY_HPP
#define PKMNLIB_AI_BUILDLIBRARY_HPP
#include <PkmnLib/Battling/Library/BattleLibrary.hpp>
#include <filesystem>
#include "BuildMoves.hpp"
#include "BuildNatures.hpp"
#include "BuildSpecies.hpp"
#include "BuildTypes.hpp"
#include "GrowthRatesBuilder.hpp"
class BuildLibrary {
static PkmnLib::Library::TimeOfDay GetTime() { return PkmnLib::Library::TimeOfDay::Morning; }
public:
static PkmnLib::Battling::BattleLibrary* Build(const std::string& pathString) {
auto path = std::filesystem::path(pathString);
auto* typesLibrary = BuildTypes::Build(path / "Types.csv");
auto* natureLibrary = BuildNatures::Build(path / "Natures.csv");
auto* movesLibrary = BuildMoves::Build(path / "Moves.json", typesLibrary);
auto* speciesLibrary = BuildSpecies::BuildLibrary(path / "Pokemon.json", typesLibrary, movesLibrary);
auto* itemsLibrary = BuildItems::Build(path / "Items.json");
auto* growthRates = GrowthRatesBuilder::Build(path / "GrowthRates.json");
auto scriptsPath = path / "Scripts";
if (typesLibrary == nullptr || speciesLibrary == nullptr || natureLibrary == nullptr ||
movesLibrary == nullptr || itemsLibrary == nullptr || growthRates == nullptr) {
return nullptr;
}
auto settings = new PkmnLib::Library::LibrarySettings(100, 4, 4096);
auto staticLibrary = new PkmnLib::Library::PokemonLibrary(settings, speciesLibrary, movesLibrary, itemsLibrary,
growthRates, typesLibrary, natureLibrary);
auto scriptResolver = PkmnLib::Battling::BattleLibrary::CreateScriptResolver();
auto battleLib = new PkmnLib::Battling::BattleLibrary(
staticLibrary, new PkmnLib::Battling::StatCalculator(), new PkmnLib::Battling::DamageLibrary(),
new PkmnLib::Battling::ExperienceLibrary(), scriptResolver, new PkmnLib::Battling::MiscLibrary(GetTime));
scriptResolver->Initialize(battleLib);
auto asScriptResolver = dynamic_cast<AngelScriptResolver*>(scriptResolver);
for (const auto& dirEntry : std::filesystem::recursive_directory_iterator(scriptsPath)) {
if (dirEntry.is_directory())
continue;
if (dirEntry.path().parent_path().stem() == "Interfaces")
continue;
if (dirEntry.path().extension() != ".as")
continue;
std::ifstream in(dirEntry.path());
std::string contents((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
asScriptResolver->CreateScript(dirEntry.path().c_str(), contents.c_str());
}
asScriptResolver->FinalizeModule();
return battleLib;
}
};
#endif // PKMNLIB_AI_BUILDLIBRARY_HPP