#include "ScriptCompiler.hpp" #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::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()); 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); 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::cout << dirEntry.path().stem() << std::endl; std::ifstream t(dirEntry.path().c_str()); std::string str((std::istreambuf_iterator(t)), std::istreambuf_iterator()); resolver->CreateScript(dirEntry.path().stem().c_str(), str.c_str()); } } resolver->FinalizeModule(); std::filesystem::path dir(outPath); std::cout << dir << std::endl; resolver->WriteByteCodeToFile(outPath.c_str()); delete library; }