Adds a GetOwner pattern to ItemUseScript
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
09638c8d14
commit
c0e7f905a9
|
@ -1,7 +1,16 @@
|
||||||
#include "AngelScriptItemUseScript.hpp"
|
#include "AngelScriptItemUseScript.hpp"
|
||||||
#include "AngelScriptFunctionCall.hpp"
|
#include "AngelScriptFunctionCall.hpp"
|
||||||
#include "AngelScriptResolver.hpp"
|
#include "AngelScriptResolver.hpp"
|
||||||
#include "AngelscriptUserdata.hpp"
|
|
||||||
|
AngelScriptItemUseScript::AngelScriptItemUseScript(asIScriptObject* scriptObject, AngelScriptResolver* resolver,
|
||||||
|
const CreatureLib::Library::Item* item)
|
||||||
|
: _scriptObject(scriptObject), _resolver(resolver) {
|
||||||
|
if (__SetOwner.Exists) {
|
||||||
|
AngelScriptUtils::AngelscriptFunctionCall(
|
||||||
|
__SetOwner.Function, _resolver->GetContextPool(), _scriptObject, _resolver, ""_cnc,
|
||||||
|
[&](asIScriptContext* ctx) { ctx->SetArgObject(0, (void*)item); }, [&](asIScriptContext*) {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
|
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
|
||||||
AngelScriptItemUseScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
|
AngelScriptItemUseScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
|
#define PKMNLIB_ANGELSCRIPTITEMUSESCRIPT_HPP
|
||||||
|
|
||||||
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
|
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
|
||||||
|
#include <CreatureLib/Library/Items/Item.hpp>
|
||||||
#include <scriptarray/scriptarray.h>
|
#include <scriptarray/scriptarray.h>
|
||||||
#include "../../Battling/PkmnItemUseScript.hpp"
|
#include "../../Battling/PkmnItemUseScript.hpp"
|
||||||
#include "TypeRegistry/NativeArray.hpp"
|
#include "TypeRegistry/NativeArray.hpp"
|
||||||
|
@ -10,8 +11,8 @@ class AngelScriptResolver;
|
||||||
|
|
||||||
class AngelScriptItemUseScript final : public PkmnLib::Battling::PkmnItemUseScript {
|
class AngelScriptItemUseScript final : public PkmnLib::Battling::PkmnItemUseScript {
|
||||||
public:
|
public:
|
||||||
AngelScriptItemUseScript(asIScriptObject* scriptObject, AngelScriptResolver* resolver)
|
AngelScriptItemUseScript(asIScriptObject* scriptObject, AngelScriptResolver* resolver,
|
||||||
: _scriptObject(scriptObject), _resolver(resolver) {}
|
const CreatureLib::Library::Item* item);
|
||||||
|
|
||||||
~AngelScriptItemUseScript() {
|
~AngelScriptItemUseScript() {
|
||||||
if (_scriptObject != nullptr) {
|
if (_scriptObject != nullptr) {
|
||||||
|
@ -50,6 +51,25 @@ private:
|
||||||
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
|
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
|
||||||
GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
|
GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
|
||||||
|
|
||||||
|
FunctionInfo InitializeGetOwner() {
|
||||||
|
auto val = _scriptObject->GetObjectType()->GetMethodByDecl("const Item@ GetOwner()", true);
|
||||||
|
if (val != nullptr) {
|
||||||
|
return FunctionInfo{.Exists = true, .Function = val};
|
||||||
|
}
|
||||||
|
return FunctionInfo{.Exists = false, .Function = nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionInfo InitializeSetOwner() {
|
||||||
|
auto val = _scriptObject->GetObjectType()->GetMethodByDecl("void SetOwner(ref@ owner)", true);
|
||||||
|
if (val != nullptr) {
|
||||||
|
return FunctionInfo{.Exists = true, .Function = val};
|
||||||
|
}
|
||||||
|
return FunctionInfo{.Exists = false, .Function = nullptr};
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionInfo __GetOwner = InitializeGetOwner();
|
||||||
|
FunctionInfo __SetOwner = InitializeSetOwner();
|
||||||
|
|
||||||
#define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
|
#define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
|
||||||
|
|
||||||
ITEM_USE_SCRIPT_HOOK_FUNCTION(
|
ITEM_USE_SCRIPT_HOOK_FUNCTION(
|
||||||
|
|
|
@ -216,7 +216,7 @@ PkmnLib::Battling::PkmnItemUseScript* AngelScriptResolver::LoadItemScript(const
|
||||||
}
|
}
|
||||||
asIScriptObject* obj = *(asIScriptObject**)ctx->GetAddressOfReturnValue();
|
asIScriptObject* obj = *(asIScriptObject**)ctx->GetAddressOfReturnValue();
|
||||||
obj->AddRef();
|
obj->AddRef();
|
||||||
auto scriptObject = new AngelScriptItemUseScript(obj, this);
|
auto scriptObject = new AngelScriptItemUseScript(obj, this, item);
|
||||||
scriptObject->OnInitialize(item->GetEffect().GetValue()->GetParameters());
|
scriptObject->OnInitialize(item->GetEffect().GetValue()->GetParameters());
|
||||||
_itemUseScripts.Insert(item, scriptObject);
|
_itemUseScripts.Insert(item, scriptObject);
|
||||||
_contextPool->ReturnContextToPool(ctx);
|
_contextPool->ReturnContextToPool(ctx);
|
||||||
|
|
|
@ -80,6 +80,11 @@ shared abstract class PkmnScript {
|
||||||
Ensure(r >= 0);
|
Ensure(r >= 0);
|
||||||
r = engine->GetModuleByIndex(0)->AddScriptSection("ItemUseScript", R"(
|
r = engine->GetModuleByIndex(0)->AddScriptSection("ItemUseScript", R"(
|
||||||
shared abstract class ItemUseScript {
|
shared abstract class ItemUseScript {
|
||||||
|
private Item@ __owner;
|
||||||
|
|
||||||
|
protected const Item@ GetOwner() { return __owner; };
|
||||||
|
protected void SetOwner(Item@ o) { @__owner = @o; };
|
||||||
|
|
||||||
void OnInitialize(const narray<EffectParameter@>@ parameters){};
|
void OnInitialize(const narray<EffectParameter@>@ parameters){};
|
||||||
bool IsItemUsable() { return false; };
|
bool IsItemUsable() { return false; };
|
||||||
bool IsPokemonUseItem() { return false; };
|
bool IsPokemonUseItem() { return false; };
|
||||||
|
|
Loading…
Reference in New Issue