54 lines
2.3 KiB
C++
54 lines
2.3 KiB
C++
#include "ScriptCompiler.hpp"
|
|
#include <PkmnLib/Battling/PkmnScriptCategory.hpp>
|
|
#include <PkmnLib/ScriptResolving/AngelScript/AngelScriptResolver.hpp>
|
|
#include <filesystem>
|
|
|
|
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 CreatureLib::Library::TalentLibrary(), 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),
|
|
new PkmnLib::Battling::CaptureLibrary());
|
|
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<char>(t)), std::istreambuf_iterator<char>());
|
|
resolver->CreateScript(
|
|
(dirEntry.path().parent_path().stem().string() + "/" + dirEntry.path().stem().string()), str);
|
|
}
|
|
}
|
|
resolver->FinalizeModule();
|
|
|
|
std::filesystem::path dir(outPath);
|
|
std::cout << dir << std::endl;
|
|
resolver->WriteByteCodeToFile(outPath.c_str());
|
|
|
|
delete library;
|
|
}
|