From bee917060350d7ae3fe15b1b15d8ecc97c8a2527 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 26 Mar 2021 23:05:51 +0100 Subject: [PATCH] Adds some more Angelscript functionality for the BattleSide. --- .../AngelScript/AngelScriptResolver.cpp | 10 ++++++---- .../Battling/RegisterBattleClass.cpp | 18 +++++++++++------- .../Battling/RegisterPokemonClass.cpp | 9 +++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp index 5a44c43..0e7acb0 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptResolver.cpp @@ -91,7 +91,6 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg, _contextPool = new ContextPool(_engine); } -OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle); void AngelScriptResolver::RegisterTypes() { // Register static library types @@ -104,14 +103,17 @@ void AngelScriptResolver::RegisterTypes() { RegisterEffectParameter::Register(_engine); // Register battle types + // Predeclare these two types, and declare their implementation later. + [[maybe_unused]] int r = _engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT); + Ensure(r >= 0); + r = _engine->RegisterObjectType("BattleSide", 0, asOBJ_REF | asOBJ_NOCOUNT); + Ensure(r >= 0); + RegisterPokemonClass::Register(_engine); RegisterExecutingAttack::Register(_engine); RegisterTurnChoices::Register(_engine); RegisterBattleLibrary::Register(_engine); RegisterBattleClass::Register(_engine); - [[maybe_unused]] int r = _engine->RegisterObjectMethod("Pokemon", "const Battle@ get_Battle() const property", - asFUNCTION(GetBattleWrapper), asCALL_CDECL_OBJFIRST); - Ensure(r >= 0); // Register base script BasicScriptClass::Register(_engine); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index f9d3c53..2b48291 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -51,19 +51,23 @@ CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battl } void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) { - int r = engine->RegisterObjectType("BattleSide", 0, asOBJ_REF | asOBJ_NOCOUNT); + int r = engine->RegisterObjectMethod( + "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", "bool SwapPositions(uint8 a, uint8 b)", - asMETHODPR(CreatureLib::Battling::BattleSide, SwapPositions, (u8 a, u8 b), bool), + r = engine->RegisterObjectMethod("BattleSide", "uint8 get_SideIndex() const property", + asMETHOD(CreatureLib::Battling::BattleSide, GetSideIndex), asCALL_THISCALL); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("BattleSide", "uint8 GetPokemonIndex(const Pokemon@ pokemon) const", + asMETHODPR(CreatureLib::Battling::BattleSide, GetCreatureIndex, + (const ArbUt::BorrowedPtr& c), u8), asCALL_THISCALL); Ensure(r >= 0); } void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { - [[maybe_unused]] int r = engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT); - Ensure(r >= 0); - r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property", - asMETHOD(PkmnLib::Battling::Battle, GetLibrary), asCALL_THISCALL); + int r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property", + asMETHOD(PkmnLib::Battling::Battle, GetLibrary), asCALL_THISCALL); Ensure(r >= 0); r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)", asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index 8c48b08..4b12a99 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -84,6 +84,8 @@ static std::string NicknameWrapper(const PkmnLib::Battling::Pokemon* obj) { retu BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies); BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme); OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem); +OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle); +OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::BattleSide, GetBattleSide); void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { [[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT); @@ -184,4 +186,11 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ArbUt::BasicStringView&), void), asCALL_THISCALL); Ensure(r >= 0); + + r = engine->RegisterObjectMethod("Pokemon", "const Battle@ get_Battle() const property", + asFUNCTION(GetBattleWrapper), asCALL_CDECL_OBJFIRST); + Ensure(r >= 0); + r = engine->RegisterObjectMethod("Pokemon", "const BattleSide@ get_BattleSide() const property", + asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST); + Ensure(r >= 0); } \ No newline at end of file