#include "ScriptCompiler.hpp" #include #include #include static PkmnLib::Library::PokemonLibrary* BuildStaticLibrary() { return new PkmnLib::Library::PokemonLibrary( new PkmnLib::Library::LibrarySettings(100, 4, 4096), new PkmnLib::Library::SpeciesLibrary(), new PkmnLib::Library::MoveLibrary(), new PkmnLib::Library::ItemLibrary(), new CreatureLib::Library::GrowthRateLibrary(), new CreatureLib::Library::TypeLibrary(), new PkmnLib::Library::NatureLibrary()); } static PkmnLib::Library::TimeOfDay GetTime() { return PkmnLib::Library::TimeOfDay::Morning; } static PkmnLib::Battling::BattleLibrary* BuildLibrary(AngelScriptResolver* scriptResolver) { auto statCalc = new PkmnLib::Battling::StatCalculator(); auto lib = new PkmnLib::Battling::BattleLibrary( BuildStaticLibrary(), statCalc, new PkmnLib::Battling::DamageLibrary(), new PkmnLib::Battling::ExperienceLibrary(), scriptResolver, new PkmnLib::Battling::MiscLibrary(&GetTime)); return lib; } using recursive_directory_iterator = std::filesystem::recursive_directory_iterator; void ScriptCompiler::Compile(const std::string& inPath, const std::string& outPath) { auto resolver = new AngelScriptResolver(); auto library = BuildLibrary(resolver); resolver->Initialize(library); resolver->SetSourceDirectory(inPath); for (const auto& dirEntry : recursive_directory_iterator(inPath)) { if (dirEntry.is_regular_file()) { if (dirEntry.path().extension() != ".as") { continue; } if (dirEntry.path().parent_path().stem() == "Interfaces") { continue; } std::ifstream t(dirEntry.path().c_str()); std::string str((std::istreambuf_iterator(t)), std::istreambuf_iterator()); resolver->CreateScript( (dirEntry.path().parent_path().stem().string() + "/" + dirEntry.path().stem().string()).c_str(), str.c_str()); } } resolver->FinalizeModule(); auto scripts = resolver->GetTypeDatabase(); for (const auto& type : scripts) { std::cout << "=== "; if ((uint8_t)type.first < 128) { std::cout << ScriptCategoryHelper::ToString(type.first); } else { std::cout << PkmnScriptCategoryHelper::ToString((PkmnScriptCategory)type.first); } std::cout << "\t===" << std::endl; for (const auto& s : type.second) { std::cout << s.first << std::endl; } } std::filesystem::path dir(outPath); std::cout << dir << std::endl; resolver->WriteByteCodeToFile(outPath.c_str()); delete library; }