2021-08-22 10:10:26 +00:00
|
|
|
#ifndef PKMNLIB_AI_BUILDLIBRARY_HPP
|
|
|
|
#define PKMNLIB_AI_BUILDLIBRARY_HPP
|
|
|
|
|
|
|
|
#include <PkmnLib/Battling/Library/BattleLibrary.hpp>
|
|
|
|
#include <filesystem>
|
2021-08-22 10:45:00 +00:00
|
|
|
#include "BuildItems.hpp"
|
2021-08-22 10:10:26 +00:00
|
|
|
#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:
|
2021-08-22 17:03:03 +00:00
|
|
|
static PkmnLib::Battling::BattleLibrary*
|
|
|
|
Build(const std::string& pathString,
|
|
|
|
std::function<void(PkmnLib::Battling::ScriptResolver*)> onScriptInitialize = {}) {
|
2021-08-22 10:10:26 +00:00
|
|
|
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);
|
|
|
|
|
2021-08-22 17:03:03 +00:00
|
|
|
if (onScriptInitialize) {
|
|
|
|
onScriptInitialize(scriptResolver);
|
|
|
|
}
|
2021-08-22 10:10:26 +00:00
|
|
|
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
|