From 0700f7cfbd86a1e029fdf53c3f5d93af7b3caf7d Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 10 Apr 2020 16:03:15 +0200 Subject: [PATCH] Fix for Pokemon.HasHeldItem in AngelScript, added tests. --- .../Battling/RegisterPokemonClass.cpp | 6 +++--- .../ScriptTypeTests/Battle/PokemonTests.cpp | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index d946cf5..920d7c8 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -82,8 +82,8 @@ CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) { } return nullptr; } -static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const Arbutils::CaseInsensitiveConstString& str) { - return obj->HasHeldItem(str); +static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString& str) { + return obj->HasHeldItem(str.GetHash()); } @@ -115,7 +115,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL); assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", - asFUNCTION(HasHeldItem), asCALL_CDECL_OBJLAST); + asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST); assert(r >= 0); r = engine->RegisterObjectMethod( "Pokemon", "void SetHeldItem(const string &in name)", diff --git a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp index f568b05..eceddb1 100644 --- a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp @@ -25,6 +25,7 @@ class testScript1 { void testDamage(Pokemon@ p, uint32 damage, DamageSource source){ p.Damage(damage, source); } void testHeal(Pokemon@ p, uint32 amount){ p.Heal(amount); } bool testMove(Pokemon@ p, uint index, LearnedMove@ move){ return p.GetMoves()[index] is move; } + bool testHasHeldItem(Pokemon@ p, const string &in item){ return p.HasHeldItem(item); } }} )"}}; @@ -334,6 +335,25 @@ TEST_CASE("Validate Pokemon GetMoves in Script") { delete mon; } +TEST_CASE("Validate Pokemon HasHeldItem in Script") { + auto mainLib = TestLibrary::GetLibrary(); + + auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3"_cnc, 30) + .WithForme("default"_cnc) + ->WithHeldItem("testItem"_cnc) + ->Build(); + auto data = GetScript(mainLib, "testHasHeldItem"_cnc); + + data.Context->SetArgObject(0, const_cast(mon)); + std::string item = "testItem"; + data.Context->SetArgAddress(1, &item); + + REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); + REQUIRE((bool)data.Context->GetReturnDWord()); + + + delete mon; +} #endif \ No newline at end of file