From e1d5a12ce03103c04d6565fd63f5fdae9f44b607 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 12 Feb 2022 17:27:39 +0100 Subject: [PATCH] Reworks OnInitialize to have battlelibrary as parameter --- .../AngelScript/AngelScriptItemUseScript.hpp | 2 +- src/ScriptResolving/AngelScript/AngelScriptScript.cpp | 7 ++++--- src/ScriptResolving/AngelScript/AngelScriptScript.hpp | 3 ++- src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp | 3 ++- .../AngelScript/TypeRegistry/BasicScriptClass.cpp | 2 +- tests/ScriptTests/BaseScriptClassTests.cpp | 4 ++-- tests/ScriptTests/ScriptResolverTests.cpp | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp index 26b7c27..4ee17ea 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptItemUseScript.hpp @@ -50,7 +50,7 @@ private: #define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl); - ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray@ parameters)"); + ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const BattleLibrary@ library, 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/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index 9feacc8..09177a9 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -36,10 +36,12 @@ CScriptHandle* AngelScriptScript::GetAngelscriptOwner() { return handle; } -void AngelScriptScript::OnInitialize(const ArbUt::List& parameters) { +void AngelScriptScript::OnInitialize(const CreatureLib::Battling::BattleLibrary* library, + const ArbUt::List& parameters) { CALL_HOOK(OnInitialize, { auto arr = GetEffectParameters(parameters); - ctx->SetArgAddress(0, arr); + ctx->SetArgObject(0, (void*)library); + ctx->SetArgAddress(1, arr); }) } void AngelScriptScript::Stack() { CALL_HOOK(Stack, ); } @@ -420,7 +422,6 @@ void AngelScriptScript::ModifyOffensiveStatValue(CreatureLib::Battling::Executin ctx->SetArgByte(2, hitIndex); ctx->SetArgAddress(3, modifier); }) - } void AngelScriptScript::ModifyDefensiveStatValue(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, u8 hitIndex, diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index af3d4cf..cf43a94 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -47,7 +47,8 @@ public: ContextPool* GetContextPool() { return _ctxPool; } CScriptHandle* GetAngelscriptOwner(); - void OnInitialize(const ArbUt::List& parameters) override; + void OnInitialize(const CreatureLib::Battling::BattleLibrary*, + const ArbUt::List& parameters) override; void Stack() override; void OnRemove() override; diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index 96614bb..a581f11 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -90,7 +90,8 @@ private: public: const FunctionInfo& GetGetOwner() const { return __GetOwner; } - SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray@ parameters)"); + SCRIPT_HOOK_FUNCTION(OnInitialize, + "void OnInitialize(const BattleLibrary@ library, 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 5ed07b9..bd492be 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -11,7 +11,7 @@ shared abstract class PkmnScript { protected ref@& GetOwner() { return __owner; }; // CreatureLib methods - void OnInitialize(const narray@ parameters){}; + void OnInitialize(const BattleLibrary@ library, const narray@ parameters){}; void Stack(){}; void OnRemove(){}; void OnBeforeTurn(BaseTurnChoice@ choice){}; diff --git a/tests/ScriptTests/BaseScriptClassTests.cpp b/tests/ScriptTests/BaseScriptClassTests.cpp index 7392cd6..9e890d6 100644 --- a/tests/ScriptTests/BaseScriptClassTests.cpp +++ b/tests/ScriptTests/BaseScriptClassTests.cpp @@ -15,7 +15,7 @@ uint64 length = 0; bool boolValue = false; int64 intValue = 0; constString stringValue; -void OnInitialize(const narray@ parameters) override { +void OnInitialize(const BattleLibrary@ library, const narray@ parameters) override { length = parameters.Length; boolValue = parameters[0].AsBool(); intValue = parameters[1].AsInt(); @@ -135,7 +135,7 @@ TEST_CASE("Invoke OnInitialize script function") { new CreatureLib::Library::EffectParameter((int64_t)684), new CreatureLib::Library::EffectParameter(ArbUt::StringView("foobar"))}; - script->OnInitialize(parameters); + script->OnInitialize(mainLib, parameters); auto ctxPool = script->GetContextPool(); diff --git a/tests/ScriptTests/ScriptResolverTests.cpp b/tests/ScriptTests/ScriptResolverTests.cpp index b0f9037..aec388d 100644 --- a/tests/ScriptTests/ScriptResolverTests.cpp +++ b/tests/ScriptTests/ScriptResolverTests.cpp @@ -19,7 +19,7 @@ class testScript1 : PkmnScript { } } - void OnInitialize(const narray@ parameters) override{ } + void OnInitialize(const BattleLibrary@ library, const narray@ parameters) override { } } } )"}};