From 6cc4206292c02da4ddbadd4a937a89f005778512 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 30 Oct 2021 16:35:23 +0200 Subject: [PATCH] Adds Angelscript functions for getting a volatile script from a Battle or BattleSide. --- .../Battling/RegisterBattleClass.cpp | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index ad2887a..ada8852 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -75,6 +75,18 @@ static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* obj, c return handle; } +static CScriptHandle Battle_GetVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { + auto handle = CScriptHandle(); + auto* resolver = static_cast(obj->GetLibrary()->GetScriptResolver().get()); + auto* s = static_cast(obj->GetVolatileScript(name).GetValue()); + if (s == nullptr) { + return handle; + } + auto* script = s->GetRawAngelscriptObject(); + handle.Set(script, resolver->GetBaseType("PkmnScript")); + return handle; +} + static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::BattleSide* obj, const ArbUt::StringView& name) { auto handle = CScriptHandle(); @@ -84,6 +96,19 @@ static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::Battle return handle; } +static CScriptHandle BattleSide_GetVolatileWrapper(CreatureLib::Battling::BattleSide* obj, + const ArbUt::StringView& name) { + auto handle = CScriptHandle(); + auto* resolver = static_cast(obj->GetBattle()->GetLibrary()->GetScriptResolver().get()); + auto* s = static_cast(obj->GetVolatileScript(name).GetValue()); + if (s == nullptr) { + return handle; + } + auto* script = s->GetRawAngelscriptObject(); + handle.Set(script, resolver->GetBaseType("PkmnScript")); + return handle; +} + static bool Battle_HasVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { return obj->HasVolatileScript(name); } @@ -122,6 +147,9 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("BattleSide", "ref@ AddVolatile(const constString &in name)", asFUNCTION(BattleSide_AddVolatileWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); + r = engine->RegisterObjectMethod("BattleSide", "ref@ GetVolatile(const constString &in name)", + asFUNCTION(BattleSide_GetVolatileWrapper), asCALL_CDECL_OBJFIRST); + Ensure(r >= 0); r = engine->RegisterObjectMethod( "BattleSide", "void RemoveVolatile(const constString &in name) const", asMETHODPR(CreatureLib::Battling::BattleSide, RemoveVolatileScript, (const ArbUt::BasicStringView&), void), @@ -154,6 +182,9 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)", asFUNCTION(Battle_AddVolatileWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); + r = engine->RegisterObjectMethod("Battle", "ref@ GetVolatile(const constString &in name)", + asFUNCTION(Battle_GetVolatileWrapper), asCALL_CDECL_OBJFIRST); + Ensure(r >= 0); r = engine->RegisterObjectMethod( "Battle", "void RemoveVolatile(const constString &in name) const", asMETHODPR(PkmnLib::Battling::Battle, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),