Adds proper AddVolatile wrapper for battle.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-03-28 17:55:45 +02:00
parent 76053af77f
commit 4e215895b7
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 9 additions and 5 deletions

View File

@ -1,8 +1,10 @@
#include "RegisterBattleClass.hpp" #include "RegisterBattleClass.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp> #include <CreatureLib/Battling/Models/Battle.hpp>
#include <CreatureLib/Battling/Models/BattleSide.hpp> #include <CreatureLib/Battling/Models/BattleSide.hpp>
#include "../../../../../extern/angelscript_addons/scripthandle/scripthandle.h"
#include "../../../../Battling/Battle/Battle.hpp" #include "../../../../Battling/Battle/Battle.hpp"
#include "../../../../Battling/Pokemon/Pokemon.hpp" #include "../../../../Battling/Pokemon/Pokemon.hpp"
#include "../../AngelScriptResolver.hpp"
#include "../../AngelScriptScript.hpp" #include "../../AngelScriptScript.hpp"
#include "../HelperFile.hpp" #include "../HelperFile.hpp"
@ -52,9 +54,12 @@ CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battl
return battle->GetSides()[index]; return battle->GetSides()[index];
} }
static asIScriptObject* AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
auto* scriptObject = (AngelScriptScript*)obj->AddVolatileScript(name); auto handle = CScriptHandle();
return scriptObject->GetRawAngelscriptObject(); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
handle.Set(script, resolver->GetBaseType("PkmnScript"));
return handle;
} }
static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* obj, PkmnLib::Battling::Pokemon* pokemon) { static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* obj, PkmnLib::Battling::Pokemon* pokemon) {
@ -90,7 +95,7 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Battle", "ChoiceQueue@ get_TurnQueue() const property", r = engine->RegisterObjectMethod("Battle", "ChoiceQueue@ get_TurnQueue() const property",
asFUNCTION(GetCurrentTurnQueueWrapper), asCALL_CDECL_OBJFIRST); asFUNCTION(GetCurrentTurnQueueWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name) const", r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)",
asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST); asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod( r = engine->RegisterObjectMethod(

View File

@ -94,7 +94,6 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const A
auto handle = CScriptHandle(); auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get()); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
script->AddRef();
handle.Set(script, resolver->GetBaseType("PkmnScript")); handle.Set(script, resolver->GetBaseType("PkmnScript"));
return handle; return handle;
} }