From 94de1d4dca6ec7e6f4b0b87b4b5e678cc6a10b20 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 27 Nov 2021 11:48:49 +0100 Subject: [PATCH] Update for PkmnLib. --- CMakeLists.txt.in | 2 + src/Tools/ScriptCompiler.cpp | 2 +- src/Tools/ScriptHeadersExporter.cpp | 62 +++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in index dad6d68..d72f939 100644 --- a/CMakeLists.txt.in +++ b/CMakeLists.txt.in @@ -40,6 +40,8 @@ function(include_pkmnlib) execute_process(COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include) execute_process(COMMAND ln -s ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/src/pkmnlib/src ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include/PkmnLib) + execute_process(COMMAND ln -s ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/src/pkmnlib/extern + ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include/extern) include_directories(${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/include ${CMAKE_CURRENT_BINARY_DIR}/PkmnLib/src/pkmnlib/extern/AngelscriptDebuggerServer/extern/asio-1.18.2/include diff --git a/src/Tools/ScriptCompiler.cpp b/src/Tools/ScriptCompiler.cpp index 3ce501e..e6134e9 100644 --- a/src/Tools/ScriptCompiler.cpp +++ b/src/Tools/ScriptCompiler.cpp @@ -8,7 +8,7 @@ static PkmnLib::Library::PokemonLibrary* BuildStaticLibrary() { 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()); + new CreatureLib::Library::TalentLibrary(), new PkmnLib::Library::NatureLibrary()); } static PkmnLib::Library::TimeOfDay GetTime() { return PkmnLib::Library::TimeOfDay::Morning; } diff --git a/src/Tools/ScriptHeadersExporter.cpp b/src/Tools/ScriptHeadersExporter.cpp index b85d34b..afad439 100644 --- a/src/Tools/ScriptHeadersExporter.cpp +++ b/src/Tools/ScriptHeadersExporter.cpp @@ -67,11 +67,35 @@ static void PrintObjectTypeDef(asITypeInfo* type, const std::filesystem::path& d auto name = std::string(method->GetName()); auto decl = std::string(method->GetDeclaration(false, true, false)); auto realName = name.substr(4); - replace(decl, name, realName); - replace(decl, "() const", " { get const; }"); - replace(decl, "()", " { get; }"); + if (method->GetParamCount() > 0 && !name.starts_with("set_")) { + fs << " " << decl << " property;" << std::endl; + } else if (name.starts_with("get_")) { + replace(decl, name, realName); + replace(decl, "() const", " { get const; "); + replace(decl, "()", " { get; "); - fs << " " << decl << ";" << std::endl; + fs << " " << decl; + auto setMethod = type->GetMethodByName(("set_" + realName).c_str()); + if (setMethod != nullptr) { + auto setDecl = std::string(setMethod->GetDeclaration(false, true, false)); + if (setDecl.find("const") != std::string::npos) { + fs << "set const; "; + } else { + fs << "set; "; + } + } + + fs << "};" << std::endl; + } else if (name.starts_with("set")) { + auto getMethod = type->GetMethodByName(("get_" + realName).c_str()); + if (getMethod != nullptr) { + continue; + } + replace(decl, name, realName); + replace(decl, "() const", " { set const; }"); + replace(decl, "()", " { set; }"); + fs << "\t" << decl << ";" << std::endl; + } } else { auto name = std::string(method->GetName()); auto decl = std::string(method->GetDeclaration(false, true, true)); @@ -107,11 +131,33 @@ static void PrintScriptObject(asITypeInfo* type, const std::filesystem::path& di auto name = std::string(method->GetName()); auto decl = std::string(method->GetDeclaration(false, true, false)); auto realName = name.substr(4); - replace(decl, name, realName); - replace(decl, "() const", " { get const; }"); - replace(decl, "()", " { get; }"); + if (name.starts_with("get_")) { + replace(decl, name, realName); + replace(decl, "() const", " get const; "); + replace(decl, "()", " get; "); - fs << "\t" << decl << std::endl; + fs << "\t" + << "{" << decl; + auto setMethod = type->GetMethodByName(("set_" + realName).c_str()); + if (setMethod != nullptr) { + auto setDecl = replace(decl, name, realName); + replace(decl, "() const", " set const; "); + replace(decl, "()", " set; "); + fs << setDecl; + } + + fs << "}" << std::endl; + } else if (name.starts_with("set")) { + auto getMethod = type->GetMethodByName(("get_" + realName).c_str()); + if (getMethod != nullptr) { + continue; + } + replace(decl, name, realName); + replace(decl, "() const", " set const; "); + replace(decl, "()", " set; "); + fs << "\t" + << "{" << decl << "}" << std::endl; + } } else { auto name = std::string(method->GetName()); if (name == "opAssign")