#include "BuildLibrary.hpp" #include #include "BuildAbilities.hpp" using namespace PkmnLib::Battling; size_t TypeTimeMs; size_t NaturesTimeMs; size_t MovesTimeMs; size_t AbilitiesTimeMs; size_t SpeciesTimeMs; size_t ItemsTimeMs; size_t GrowthRateTimeMs; size_t ScriptsTimeMs; void BuildLibrary::LogBuildTimes() { std::cout << "\tType Library Time: " << TypeTimeMs << "ms" << std::endl; std::cout << "\tNatures Library Time: " << NaturesTimeMs << "ms" << std::endl; std::cout << "\tMoves Library Time: " << MovesTimeMs << "ms" << std::endl; std::cout << "\tSpecies Library Time: " << SpeciesTimeMs << "ms" << std::endl; std::cout << "\tItems Library Time: " << ItemsTimeMs << "ms" << std::endl; std::cout << "\tGrowth rates Library Time: " << GrowthRateTimeMs << "ms" << std::endl; std::cout << "\tScripts Time: " << ScriptsTimeMs << "ms" << std::endl; } BattleLibrary* BuildLibrary::Build(const std::string& pathString, std::function onScriptInitialize) { auto path = std::filesystem::path(pathString); std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); auto* typesLibrary = BuildTypes::Build((path / "Types.csv").generic_string()); TypeTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); begin = std::chrono::steady_clock::now(); auto* natureLibrary = BuildNatures::Build((path / "Natures.csv").generic_string()); NaturesTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); begin = std::chrono::steady_clock::now(); auto* movesLibrary = BuildMoves::Build((path / "Moves.json").generic_string(), typesLibrary); MovesTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); begin = std::chrono::steady_clock::now(); auto* talentsLibraries = BuildAbilities::Build((path / "Abilities.json").generic_string()); AbilitiesTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); auto* speciesLibrary = BuildSpecies::BuildLibrary((path / "Pokemon.json").generic_string(), typesLibrary, talentsLibraries, movesLibrary); SpeciesTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); begin = std::chrono::steady_clock::now(); auto* itemsLibrary = BuildItems::Build((path / "Items.json").generic_string()); ItemsTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); begin = std::chrono::steady_clock::now(); auto* growthRates = GrowthRatesBuilder::Build((path / "GrowthRates.json").generic_string()); GrowthRateTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); 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, talentsLibraries, natureLibrary); begin = std::chrono::steady_clock::now(); auto scriptResolver = BattleLibrary::CreateScriptResolver(); auto battleLib = new BattleLibrary(staticLibrary, new StatCalculator(), new DamageLibrary(false), new ExperienceLibrary(), scriptResolver, new MiscLibrary(GetTime)); scriptResolver->Initialize(battleLib); if (onScriptInitialize) { onScriptInitialize(scriptResolver); } auto asScriptResolver = dynamic_cast(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(in)), std::istreambuf_iterator()); asScriptResolver->CreateScript((const char*)dirEntry.path().c_str(), contents.c_str()); } asScriptResolver->FinalizeModule(); ScriptsTimeMs = std::chrono::duration_cast(std::chrono::steady_clock::now() - begin).count(); return battleLib; }