diff --git a/CInterface/Library/EvolutionData.cpp b/CInterface/Library/EvolutionData.cpp index 20dd054..b5a5af1 100644 --- a/CInterface/Library/EvolutionData.cpp +++ b/CInterface/Library/EvolutionData.cpp @@ -73,7 +73,7 @@ export const PokemonSpecies* PkmnLib_EvolutionData_GetNewSpecies(const Evolution return data->GetNewSpecies().GetRaw(); } export size_t PkmnLib_EvolutionData_GetDataCount(const EvolutionData* data) { return data->GetDataCount(); } -export uint8_t PkmnLib_EvolutionData_GetData(const EvolutionData* data, size_t index, +export uint8_t PkmnLib_EvolutionData_GetDataAt(const EvolutionData* data, size_t index, const CreatureLib::Library::EffectParameter*& out) { - Try(out = data->GetData(index).GetRaw()); + Try(out = data->GetDataAt(index).GetRaw()); } diff --git a/src/Battling/Library/MiscLibrary.cpp b/src/Battling/Library/MiscLibrary.cpp index cc72c3f..6f3bfb1 100644 --- a/src/Battling/Library/MiscLibrary.cpp +++ b/src/Battling/Library/MiscLibrary.cpp @@ -38,15 +38,15 @@ bool PkmnLib::Battling::MiscLibrary::CanEvolveFromLevelUp( auto time = GetTime(); switch (evolution->GetMethod()) { - case Library::EvolutionMethod::Level: return pokemon->GetLevel() >= evolution->GetData(0)->AsInt(); + case Library::EvolutionMethod::Level: return pokemon->GetLevel() >= evolution->GetDataAt(0)->AsInt(); case Library::EvolutionMethod::HighFriendship: - return pokemon->GetFriendship() >= evolution->GetData(0)->AsInt(); + return pokemon->GetFriendship() >= evolution->GetDataAt(0)->AsInt(); case Library::EvolutionMethod::HighFriendshipTime: - return pokemon->GetFriendship() >= evolution->GetData(0)->AsInt() && - time >= (TimeOfDay)evolution->GetData(1)->AsInt() && - time <= (TimeOfDay)evolution->GetData(2)->AsInt(); + return pokemon->GetFriendship() >= evolution->GetDataAt(0)->AsInt() && + time >= (TimeOfDay)evolution->GetDataAt(1)->AsInt() && + time <= (TimeOfDay)evolution->GetDataAt(2)->AsInt(); case Library::EvolutionMethod::KnownMove: { - auto v = evolution->GetData(0)->AsString(); + auto v = evolution->GetDataAt(0)->AsString(); return std::any_of(pokemon->GetMoves().begin(), pokemon->GetMoves().end(), [v](const auto& move) { return move.HasValue() && move.GetValue()->GetMoveData()->GetName() == v; }); @@ -55,19 +55,19 @@ bool PkmnLib::Battling::MiscLibrary::CanEvolveFromLevelUp( // TODO: Implement this return false; case Library::EvolutionMethod::TimeBased: - return time >= (TimeOfDay)evolution->GetData(0)->AsInt() && - time <= (TimeOfDay)evolution->GetData(1)->AsInt(); - case Library::EvolutionMethod::HoldsItem: return pokemon->HasHeldItem(evolution->GetData(0)->AsString()); + return time >= (TimeOfDay)evolution->GetDataAt(0)->AsInt() && + time <= (TimeOfDay)evolution->GetDataAt(1)->AsInt(); + case Library::EvolutionMethod::HoldsItem: return pokemon->HasHeldItem(evolution->GetDataAt(0)->AsString()); case Library::EvolutionMethod::HoldsItemTime: - return pokemon->HasHeldItem(evolution->GetData(0)->AsString()) && - time >= (TimeOfDay)evolution->GetData(0)->AsInt() && - time <= (TimeOfDay)evolution->GetData(1)->AsInt(); + return pokemon->HasHeldItem(evolution->GetDataAt(0)->AsString()) && + time >= (TimeOfDay)evolution->GetDataAt(0)->AsInt() && + time <= (TimeOfDay)evolution->GetDataAt(1)->AsInt(); case Library::EvolutionMethod::IsGenderAndLevel: - return pokemon->GetLevel() >= evolution->GetData(1)->AsInt() && - pokemon->GetGender() == (CreatureLib::Library::Gender)evolution->GetData(0)->AsInt(); + return pokemon->GetLevel() >= evolution->GetDataAt(1)->AsInt() && + pokemon->GetGender() == (CreatureLib::Library::Gender)evolution->GetDataAt(0)->AsInt(); case Library::EvolutionMethod::Custom: { auto script = dynamic_cast(pokemon->GetLibrary()->GetScriptResolver().get()) - ->LoadEvolutionScript(evolution->GetData(0)->AsString()); + ->LoadEvolutionScript(evolution->GetDataAt(0)->AsString()); if (!script.HasValue()) { return false; } diff --git a/src/Library/Evolutions/EvolutionData.hpp b/src/Library/Evolutions/EvolutionData.hpp index f8aa7f7..79562d8 100644 --- a/src/Library/Evolutions/EvolutionData.hpp +++ b/src/Library/Evolutions/EvolutionData.hpp @@ -87,8 +87,11 @@ namespace PkmnLib::Library { } [[nodiscard]] inline EvolutionMethod GetMethod() const noexcept { return _method; } [[nodiscard]] inline size_t GetDataCount() const noexcept { return _evolutionData.Count(); } + [[nodiscard]] inline const ArbUt::UniquePtrList& GetData() const { + return _evolutionData; + } [[nodiscard]] inline ArbUt::BorrowedPtr - GetData(size_t index) const { + GetDataAt(size_t index) const { return _evolutionData.At(index); } }; diff --git a/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.cpp index 8e34c0f..5ea8b71 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.cpp @@ -3,28 +3,20 @@ #include "AngelScriptResolver.hpp" #include "AngelscriptUserdata.hpp" -CScriptArray* +NativeArray>* AngelScriptItemUseScript::GetEffectParameters(const ArbUt::List& ls) { - auto* ud = _resolver->GetUserdata(); - auto* arr = ud->CreateArray("array"_cnc, ls.Count()); - for (size_t i = 0; i < ls.Count(); i++) { - arr->SetValue(i, (void**)&ls[i]); - } - return arr; + return new NativeArray>(&ls); } void AngelScriptItemUseScript::OnInitialize(const ArbUt::List& parameters) { if (__OnInitialize.Exists) { - CScriptArray* arr = nullptr; AngelScriptUtils::AngelscriptFunctionCall( __OnInitialize.Function, _resolver->GetContextPool(), _scriptObject, _resolver, ""_cnc, [&]([[maybe_unused]] asIScriptContext* ctx) { - arr = GetEffectParameters(parameters); + auto* arr = GetEffectParameters(parameters); ctx->SetArgAddress(0, arr); }, [&]([[maybe_unused]] asIScriptContext* ctx) {}); - - arr->Release(); } } diff --git a/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp index 8b90d26..5c2dd6f 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp @@ -3,6 +3,7 @@ #include #include "../../../extern/angelscript_addons/scriptarray/scriptarray.h" +#include "TypeRegistry/NativeArray.hpp" class AngelScriptResolver; @@ -44,11 +45,12 @@ private: return FunctionInfo{.Exists = true, .Function = val}; } - CScriptArray* GetEffectParameters(const ArbUt::List& ls); + NativeArray>* + GetEffectParameters(const ArbUt::List& ls); #define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl); - ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const array &in parameters)"); + ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray@ parameters)"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsItemUsable, "bool IsItemUsable()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsPokemonUseItem, "bool IsPokemonUseItem()"); ITEM_USE_SCRIPT_HOOK_FUNCTION(IsUseValidForPokemon, "bool IsUseValidForPokemon(Pokemon@ target)"); diff --git a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp index 7cba5b5..e66313e 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp @@ -29,6 +29,7 @@ #include "TypeRegistry/Library/RegisterSpeciesTypes.hpp" #include "TypeRegistry/Library/RegisterStaticLibraryTypes.hpp" #include "TypeRegistry/Library/RegisterTypeLibrary.hpp" +#include "TypeRegistry/NativeArray.hpp" PkmnLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver() { return new AngelScriptResolver(); @@ -94,6 +95,7 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg, if (includeStandard) { RegisterStdString(_engine); ConstStringRegister::Register(_engine); + NativeArray>>::Register(_engine); // Register Script Array type RegisterScriptArray(_engine, true); diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index 6fb18a2..3998090 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -1,7 +1,6 @@ #include "AngelScriptScript.hpp" #include "AngelScriptFunctionCall.hpp" #include "AngelScriptResolver.hpp" -#include "AngelscriptUserdata.hpp" #define CALL_HOOK(name, setup) \ auto s = _type->Get##name(); \ @@ -11,23 +10,16 @@ s.Function, _ctxPool, _obj, _resolver, GetName(), [&]([[maybe_unused]] asIScriptContext* ctx) { setup }, \ [&]([[maybe_unused]] asIScriptContext* ctx) {}); -CScriptArray* AngelScriptScript::GetEffectParameters(const ArbUt::List& ls) { - auto arr = _resolver->GetUserdata()->CreateArray("array"_cnc, ls.Count()); - for (size_t i = 0; i < ls.Count(); i++) { - arr->SetValue(i, (void**)&ls[i]); - } - return arr; +NativeArray>* +AngelScriptScript::GetEffectParameters(const ArbUt::List& ls) { + return new NativeArray>(&ls); } void AngelScriptScript::OnInitialize(const ArbUt::List& parameters) { - CScriptArray* arr = nullptr; CALL_HOOK(OnInitialize, { - arr = GetEffectParameters(parameters); + auto arr = GetEffectParameters(parameters); ctx->SetArgAddress(0, arr); }) - if (arr != nullptr) { - arr->Release(); - } } void AngelScriptScript::Stack() { CALL_HOOK(Stack, ); } void AngelScriptScript::OnRemove() { CALL_HOOK(OnRemove, ); } diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index b70f3eb..e9721a4 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -6,6 +6,7 @@ #include "../../../extern/angelscript_addons/scriptarray/scriptarray.h" #include "../../Battling/PkmnScript.hpp" #include "AngelScriptTypeInfo.hpp" +#include "TypeRegistry/NativeArray.hpp" class AngelScriptResolver; class ContextPool; @@ -17,7 +18,8 @@ private: ContextPool* _ctxPool = nullptr; asIScriptObject* _obj = nullptr; - CScriptArray* GetEffectParameters(const ArbUt::List& ls); + NativeArray>* + GetEffectParameters(const ArbUt::List& ls); public: AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj, diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index 23edd50..c9178a2 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -70,7 +70,7 @@ private: public: \ const FunctionInfo& Get##name() const { return __##name; } - SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const array &in parameters)"); + SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray@ parameters)"); SCRIPT_HOOK_FUNCTION(Stack, "void Stack()"); SCRIPT_HOOK_FUNCTION(OnRemove, "void OnRemove()"); SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)"); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp index 1d85f20..a97e60b 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -6,7 +6,7 @@ void BasicScriptClass::Register(asIScriptEngine* engine) { int r = engine->GetModuleByIndex(0)->AddScriptSection("PkmnScript", R"( shared abstract class PkmnScript { // CreatureLib methods - void OnInitialize(const array &in parameters){}; + void OnInitialize(const narray@ parameters){}; void Stack(){}; void OnRemove(){}; void OnBeforeTurn(BaseTurnChoice@ choice){}; @@ -58,7 +58,7 @@ shared abstract class PkmnScript { Ensure(r >= 0); r = engine->GetModuleByIndex(0)->AddScriptSection("ItemUseScript", R"( shared abstract class ItemUseScript { - void OnInitialize(const array &in parameters){}; + void OnInitialize(const narray@ parameters){}; bool IsItemUsable() { return false; }; bool IsPokemonUseItem() { return false; }; bool IsUseValidForPokemon(Pokemon@ target) { return false; }; diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index 809adb1..080f40b 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -1,6 +1,7 @@ #include "RegisterBattleClass.hpp" #include #include +#include #include "../../../../../extern/angelscript_addons/scripthandle/scripthandle.h" #include "../../../../Battling/Battle/Battle.hpp" #include "../../../../Battling/Pokemon/Pokemon.hpp" @@ -8,6 +9,7 @@ #include "../../AngelScriptScript.hpp" #include "../../AngelscriptUserdata.hpp" #include "../HelperFile.hpp" +#include "../NativeArray.hpp" void RegisterBattleClass::Register(asIScriptEngine* engine) { RegisterChoiceQueue(engine); @@ -86,9 +88,10 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) { "BattleSide", "bool SwapPositions(uint8 a, uint8 b)", asMETHODPR(CreatureLib::Battling::BattleSide, SwapPositions, (u8 a, u8 b), bool), asCALL_THISCALL); Ensure(r >= 0); - r = engine->RegisterObjectMethod("BattleSide", "uint8 get_SideIndex() const property", - asMETHOD(CreatureLib::Battling::BattleSide, GetSideIndex), asCALL_THISCALL); - Ensure(r >= 0); + + REGISTER_GETTER("BattleSide", "uint8 get_SideIndex() const property", CreatureLib::Battling::BattleSide, + GetSideIndex); + r = engine->RegisterObjectMethod("BattleSide", "uint8 GetPokemonIndex(const Pokemon@ pokemon) const", asFUNCTION(GetPokemonIndexWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); @@ -105,21 +108,10 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { REGISTER_GETTER("Battle", "BattleRandom@ get_Random() const property", CreatureLib::Battling::Battle, GetRandom); REGISTER_GETTER("Battle", "ChoiceQueue@ get_TurnQueue() const property", CreatureLib::Battling::Battle, GetCurrentTurnQueue); - { - auto l = [](const CreatureLib::Battling::Battle* b) { - const auto& ls = b->GetSides(); - auto* ctx = asGetActiveContext(); - auto* ud = (AngelscriptUserdata*)ctx->GetUserData(); - auto* arr = ud->CreateArray("array"_cnc, ls.Count()); - for (size_t i = 0; i < ls.Count(); i++) { - arr->SetValue(i, ls[i].GetRaw()); - } - return arr; - }; - Ensure(engine->RegisterObjectMethod("Battle", "const array& get_Sides() const property", - asFUNCTIONPR(l, (const CreatureLib::Battling::Battle*), CScriptArray*), - asCALL_CDECL_OBJFIRST) >= 0); - } + REGISTER_GETTER("Battle", "narray@ get_Sides() const property", CreatureLib::Battling::Battle, + GetSides); + REGISTER_GETTER("Battle", "narray@ get_Parties() const property", CreatureLib::Battling::Battle, + GetParties); auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)", asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleLibrary.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleLibrary.cpp index abb174b..932f79b 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleLibrary.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleLibrary.cpp @@ -7,11 +7,7 @@ void RegisterBattleLibrary::Register(asIScriptEngine* engine) { RegisterLibrary(engine); } void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterObjectType("DamageLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT); - assert(r >= 0); - r = engine->RegisterObjectMethod("DamageLibrary", "int GetDamage() const", - asMETHOD(PkmnLib::Battling::DamageLibrary, GetDamage), asCALL_THISCALL); - assert(r >= 0); + Ensure(engine->RegisterObjectType("DamageLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0) } void RegisterBattleLibrary::RegisterLibrary(asIScriptEngine* engine) { diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp index b72fc52..3f42091 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterExecutingAttack.cpp @@ -6,9 +6,6 @@ void RegisterExecutingAttack::Register(asIScriptEngine* engine) { RegisterHitData(engine); RegisterExecutingAttackType(engine); } -BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::ExecutingAttack, CreatureLib::Battling::Creature, GetUser); -BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::ExecutingAttack, CreatureLib::Battling::LearnedAttack, GetAttack); -BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::ExecutingAttack, const CreatureLib::Library::AttackData, GetUseAttack); static CreatureLib::Battling::ExecutingAttack::HitData* GetHitDataWrapper(CreatureLib::Battling::ExecutingAttack* obj, CreatureLib::Battling::Creature* c, uint8_t hit) { return &obj->GetHitData(c, hit); @@ -17,51 +14,38 @@ GetHitDataWrapper(CreatureLib::Battling::ExecutingAttack* obj, CreatureLib::Batt void RegisterExecutingAttack::RegisterHitData(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("HitData", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(r >= 0); - r = engine->RegisterObjectMethod("HitData", "bool get_IsCritical() const property", - asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, IsCritical), - asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("HitData", "uint8 get_BasePower() const property", - asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetBasePower), - asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("HitData", "float get_Effectiveness() const property", - asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness), - asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("HitData", "uint get_Damage() const property", - asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetDamage), - asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("HitData", "uint8 get_Type() const property", - asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetType), - asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("HitData", "bool get_HasFailed() const property", - asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, HasFailed), - asCALL_THISCALL); - Ensure(r >= 0); + + REGISTER_GETTER("HitData", "bool get_IsCritical() const property", CreatureLib::Battling::ExecutingAttack::HitData, + IsCritical); + REGISTER_GETTER("HitData", "uint8 get_BasePower() const property", CreatureLib::Battling::ExecutingAttack::HitData, + GetBasePower); + REGISTER_GETTER("HitData", "float get_Effectiveness() const property", + CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness); + REGISTER_GETTER("HitData", "uint get_Damage() const property", CreatureLib::Battling::ExecutingAttack::HitData, + GetDamage); + REGISTER_GETTER("HitData", "uint8 get_Type() const property", CreatureLib::Battling::ExecutingAttack::HitData, + GetType); + REGISTER_GETTER("HitData", "bool get_HasFailed() const property", CreatureLib::Battling::ExecutingAttack::HitData, + HasFailed); + r = engine->RegisterObjectMethod("HitData", "void Fail()", asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, Fail), asCALL_THISCALL); Ensure(r >= 0); } void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const", - asFUNCTION(GetHitDataWrapper), asCALL_CDECL_OBJFIRST); + Ensure(engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0); + REGISTER_GETTER("ExecutingMove", "Pokemon@ get_User() const property", CreatureLib::Battling::ExecutingAttack, + GetUser); + REGISTER_GETTER("ExecutingMove", "LearnedMove@ get_Move() const property", CreatureLib::Battling::ExecutingAttack, + GetAttack); + REGISTER_GETTER("ExecutingMove", "MoveData@ get_UseMove() const property", CreatureLib::Battling::ExecutingAttack, + GetUseAttack); + + auto r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const", + asFUNCTION(GetHitDataWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const", asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget), asCALL_THISCALL); Ensure(r >= 0); - r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property", asFUNCTION(GetUserWrapper), - asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property", - asFUNCTION(GetAttackWrapper), asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("ExecutingMove", "MoveData@ get_UseMove() const property", - asFUNCTION(GetUseAttackWrapper), asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterParty.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterParty.cpp index 9b462ea..6847b3b 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterParty.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterParty.cpp @@ -17,22 +17,18 @@ static PkmnLib::Battling::Pokemon* GetAtIndexWrapper(PkmnLib::Battling::PokemonP } void RegisterParty::RegisterPartyClass(asIScriptEngine* engine) { - auto r = engine->RegisterObjectType("Party", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("Party", "Pokemon@ GetAtIndex(int index) const", asFUNCTION(GetAtIndexWrapper), - asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("Party", "int get_Length() const property", - asMETHOD(PkmnLib::Battling::PokemonParty, GetLength), asCALL_THISCALL); + Ensure(engine->RegisterObjectType("Party", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0); + // GetParty() has both a const and a non const variant, so we need to explicitly mention its return type. + REGISTER_EXPLICIT_GETTER("Party", "const narray@ get_Pokemon() const property", + CreatureLib::Battling::CreatureParty, GetParty, + const ArbUt::OptionalUniquePtrList&); + + auto r = engine->RegisterObjectMethod("Party", "Pokemon@ GetAtIndex(int index) const", + asFUNCTION(GetAtIndexWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); } -BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::BattleParty, CreatureLib::Battling::CreatureParty, GetParty); - void RegisterParty::RegisterBattleParty(asIScriptEngine* engine) { - auto r = engine->RegisterObjectType("BattleParty", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("BattleParty", "Party@ get_Party() const property", asFUNCTION(GetPartyWrapper), - asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); + Ensure(engine->RegisterObjectType("BattleParty", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0); + REGISTER_GETTER("BattleParty", "Party@ get_Party() const property", CreatureLib::Battling::BattleParty, GetParty); } diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index 4a72de1..0962565 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -39,41 +39,15 @@ void RegisterPokemonClass::RegisterMoveLearnMethod(asIScriptEngine* engine) { Ensure(r >= 0); } -ENUM__SIZE_WRAPPER(LearnedMove_LearnMethodWrapper, CreatureLib::Battling::LearnedAttack, GetLearnMethod) -BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::LearnedAttack, const CreatureLib::Library::AttackData, GetAttack); - void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("LearnedMove", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(r >= 0); - r = engine->RegisterObjectMethod("LearnedMove", "const MoveData@ get_MoveData() const property", - asFUNCTION(GetAttackWrapper), asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_MaxUses() const property", - asMETHOD(CreatureLib::Battling::LearnedAttack, GetMaxUses), asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_RemainingUses() const property", - asMETHOD(CreatureLib::Battling::LearnedAttack, GetRemainingUses), asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("LearnedMove", "Gender get_LearnMethod() const property", - asFUNCTION(LearnedMove_LearnMethodWrapper), asCALL_CDECL_OBJLAST); - Ensure(r >= 0); + REGISTER_GETTER("LearnedMove", "const MoveData@ get_MoveData() const property", CreatureLib::Battling::LearnedAttack, GetAttack); + REGISTER_GETTER("LearnedMove", "uint8 get_MaxUses() const property", CreatureLib::Battling::LearnedAttack, GetMaxUses); + REGISTER_GETTER("LearnedMove", "uint8 get_RemainingUses() const property", CreatureLib::Battling::LearnedAttack, GetRemainingUses); + REGISTER_GETTER("LearnedMove", "Gender get_LearnMethod() const property", CreatureLib::Battling::LearnedAttack, GetLearnMethod); } -ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender) - -CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) { - asIScriptContext* ctx = asGetActiveContext(); - if (ctx) { - auto a = obj->GetMoves(); - auto ud = (AngelscriptUserdata*)ctx->GetUserData(); - CScriptArray* arr = ud->CreateArray("array"_cnc, a.Count()); - for (size_t i = 0; i < a.Count(); i++) { - arr->SetValue(i, &a[i]); - } - return arr; - } - return nullptr; -} static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& str) { return obj->HasHeldItem(str.GetHash()); } @@ -97,7 +71,6 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const A } void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { - int r; Ensure(engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0); REGISTER_GETTER("Pokemon", "const Species@ get_Species() const property", CreatureLib::Battling::Creature, GetSpecies); @@ -126,8 +99,10 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { GetBattleSide); REGISTER_GETTER("Pokemon", "const constString& get_Status() const property", CreatureLib::Battling::Creature, GetStatusName); + REGISTER_GETTER("Pokemon", "const narray@ get_Moves() const property", PkmnLib::Battling::Pokemon, + GetMoves); - r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", + auto r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const constString &in name)", @@ -153,9 +128,6 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)", asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL); Ensure(r >= 0); - r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const", asFUNCTION(GetMoves), - asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)", asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL); Ensure(r >= 0); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp index 5659d1b..679d66b 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterTurnChoices.cpp @@ -5,8 +5,6 @@ #include "../HelperFile.hpp" #include "../RefCast.hpp" -BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::Creature, GetUser); - void RegisterTurnChoices::Register(asIScriptEngine* engine) { RegisterTurnChoiceKindEnum(engine); RegisterBaseTurnChoice(engine); @@ -14,47 +12,34 @@ void RegisterTurnChoices::Register(asIScriptEngine* engine) { RegisterSwitchTurnChoice(engine); RegisterFleeTurnChoice(engine); } + void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind"); - Ensure(r >= 0); - r = engine->RegisterEnumValue("TurnChoiceKind", "Pass", (int)CreatureLib::Battling::TurnChoiceKind::Pass); - Ensure(r >= 0); - r = engine->RegisterEnumValue("TurnChoiceKind", "Attack", (int)CreatureLib::Battling::TurnChoiceKind::Attack); - Ensure(r >= 0); - r = engine->RegisterEnumValue("TurnChoiceKind", "Item", (int)CreatureLib::Battling::TurnChoiceKind::Item); - Ensure(r >= 0); - r = engine->RegisterEnumValue("TurnChoiceKind", "Switch", (int)CreatureLib::Battling::TurnChoiceKind::Switch); - Ensure(r >= 0); - r = engine->RegisterEnumValue("TurnChoiceKind", "Flee", (int)CreatureLib::Battling::TurnChoiceKind::Flee); - Ensure(r >= 0); + REGISTER_ENUM(CreatureLib::Battling::TurnChoiceKind, "TurnChoiceKind"); } + void RegisterTurnChoices::RegisterBaseTurnChoice(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterObjectType("BaseTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("BaseTurnChoice", "TurnChoiceKind get_Kind() const property", - asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetKind), asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("BaseTurnChoice", "const Pokemon@ get_User() const property", - asFUNCTION(GetUserWrapper), asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); + Ensure(engine->RegisterObjectType("BaseTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0); + REGISTER_EXPLICIT_GETTER("BaseTurnChoice", "TurnChoiceKind get_Kind() const property", + CreatureLib::Battling::BaseTurnChoice, GetKind, CreatureLib::Battling::TurnChoiceKind); + REGISTER_EXPLICIT_GETTER("BaseTurnChoice", "const Pokemon@ get_User() const property", + CreatureLib::Battling::BaseTurnChoice, GetUser, + const ArbUt::BorrowedPtr&); } void RegisterTurnChoices::RegisterMoveTurnChoice(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterObjectType("MoveTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("MoveTurnChoice", "TurnChoiceKind get_Kind() const property", - asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetKind), asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("MoveTurnChoice", "Pokemon@ get_User() const property", asFUNCTION(GetUserWrapper), - asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("MoveTurnChoice", "LearnedMove@ get_Move() const property", - asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetAttack), asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("MoveTurnChoice", "int8 get_Priority() const property", - asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetPriority), asCALL_THISCALL); + int r = engine->RegisterObjectType("MoveTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(r >= 0); + REGISTER_GETTER("MoveTurnChoice", "TurnChoiceKind get_Kind() const property", + CreatureLib::Battling::AttackTurnChoice, GetKind); + REGISTER_EXPLICIT_GETTER("MoveTurnChoice", "Pokemon@ get_User() const property", + CreatureLib::Battling::BaseTurnChoice, GetUser, + const ArbUt::BorrowedPtr&); + REGISTER_GETTER("MoveTurnChoice", "LearnedMove@ get_Move() const property", + CreatureLib::Battling::AttackTurnChoice, GetAttack); + REGISTER_GETTER("MoveTurnChoice", "int8 get_Priority() const property", + CreatureLib::Battling::AttackTurnChoice, GetPriority); + r = engine->RegisterObjectMethod( "BaseTurnChoice", "MoveTurnChoice@ opCast()", asFUNCTION((refCast)), @@ -68,19 +53,15 @@ void RegisterTurnChoices::RegisterMoveTurnChoice(asIScriptEngine* engine) { } void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterObjectType("SwitchTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("SwitchTurnChoice", "TurnChoiceKind get_Kind() const property", - asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetKind), asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("SwitchTurnChoice", "const Pokemon@ get_User() const property", - asFUNCTION(GetUserWrapper), asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property", - asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature), - asCALL_THISCALL); + int r = engine->RegisterObjectType("SwitchTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(r >= 0); + REGISTER_GETTER("SwitchTurnChoice", "TurnChoiceKind get_Kind() const property", CreatureLib::Battling::SwitchTurnChoice, GetKind); + REGISTER_EXPLICIT_GETTER("SwitchTurnChoice", "const Pokemon@ get_User() const property", + CreatureLib::Battling::BaseTurnChoice, GetUser, + const ArbUt::BorrowedPtr&); + REGISTER_GETTER("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property", CreatureLib::Battling::SwitchTurnChoice, GetNewCreature); + r = engine->RegisterObjectMethod( "BaseTurnChoice", "SwitchTurnChoice@ opCast()", asFUNCTION((refCast)), @@ -93,14 +74,12 @@ void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) { Ensure(r >= 0); } void RegisterTurnChoices::RegisterFleeTurnChoice(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterObjectType("FleeTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("FleeTurnChoice", "TurnChoiceKind get_Kind() const property", - asMETHOD(CreatureLib::Battling::FleeTurnChoice, GetKind), asCALL_THISCALL); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("FleeTurnChoice", "const Pokemon@ get_User() const property", - asFUNCTION(GetUserWrapper), asCALL_CDECL_OBJFIRST); + int r = engine->RegisterObjectType("FleeTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(r >= 0); + REGISTER_GETTER("FleeTurnChoice", "TurnChoiceKind get_Kind() const property", CreatureLib::Battling::FleeTurnChoice, GetKind); + REGISTER_EXPLICIT_GETTER("FleeTurnChoice", "const Pokemon@ get_User() const property", + CreatureLib::Battling::BaseTurnChoice, GetUser, + const ArbUt::BorrowedPtr&); r = engine->RegisterObjectMethod( "BaseTurnChoice", "FleeTurnChoice@ opCast()", diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp b/src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp index ef9b547..1d12dea 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/HelperFile.hpp @@ -1,3 +1,7 @@ +#ifndef PKMNLIB_HELPERFILE_HPP +#define PKMNLIB_HELPERFILE_HPP +#include "NativeArray.hpp" + #define BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \ static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetRaw(); } #define OPTIONAL_BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \ @@ -27,72 +31,65 @@ struct is_specialization&, Ref> : std::true_type {}; template