From 34fb528da46b1d05e189cebc8ec5683011cbc834 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 5 Jun 2020 16:54:57 +0200 Subject: [PATCH] Update CreatureLib. --- .../Battling/RegisterPokemonClass.cpp | 18 ------------- .../ScriptTypeTests/Battle/PokemonTests.cpp | 25 ++----------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index 9091c28..8603020 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -61,21 +61,6 @@ void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) { ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender) -CScriptArray* GetTypes(const PkmnLib::Battling::Pokemon* obj) { - asIScriptContext* ctx = asGetActiveContext(); - if (ctx) { - asIScriptEngine* engine = ctx->GetEngine(); - asITypeInfo* t = engine->GetTypeInfoByDecl("array"); - auto a = obj->GetTypes(); - CScriptArray* arr = CScriptArray::Create(t, a.Count()); - for (size_t i = 0; i < a.Count(); i++) { - arr->SetValue(i, &a[i]); - } - return arr; - } - return nullptr; -} - CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) { asIScriptContext* ctx = asGetActiveContext(); if (ctx) { @@ -150,9 +135,6 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property", asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL); Assert(r >= 0); - r = engine->RegisterObjectMethod("Pokemon", "uint8[]@ GetTypes() const", asFUNCTION(GetTypes), - asCALL_CDECL_OBJLAST); - Assert(r >= 0); r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const", asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL); Assert(r >= 0); diff --git a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp index 7f21966..1a1a9c7 100644 --- a/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp +++ b/tests/ScriptTests/ScriptTypeTests/Battle/PokemonTests.cpp @@ -20,7 +20,6 @@ class testScript1 { bool testNickname(Pokemon@ p, const string& name){ return p.Nickname == name; } bool testActiveAbility(Pokemon@ p, const constString &in ability){ return p.ActiveAbility == ability; } bool testIsFainted(Pokemon@ p, bool b){ return p.IsFainted == b; } - bool testType(Pokemon@ p, uint index, uint8 type){ return p.GetTypes()[index] == type; } bool testHasType(Pokemon@ p, uint8 type){ return p.HasType(type); } void testDamage(Pokemon@ p, uint32 damage, DamageSource source){ p.Damage(damage, source); } void testHeal(Pokemon@ p, uint32 amount){ p.Heal(amount); } @@ -235,26 +234,6 @@ TEST_CASE("Validate Pokemon IsFainted in Script") { delete mon; } -TEST_CASE("Validate Pokemon GetTypes in Script") { - auto mainLib = TestLibrary::GetLibrary(); - - auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3"_cnc, 30) - .WithForme("default"_cnc) - .WithGender(CreatureLib::Library::Gender::Male) - .Build(); - for (size_t i = 0; i < mon->GetTypes().Count(); i++) { - auto data = GetScript(mainLib, "testType"_cnc); - - data.Context->SetArgObject(0, const_cast(mon)); - data.Context->SetArgDWord(1, i); - data.Context->SetArgByte(2, mon->GetTypes()[i]); - - REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); - REQUIRE((bool)data.Context->GetReturnWord()); - } - delete mon; -} - TEST_CASE("Validate Pokemon HasType in Script") { auto mainLib = TestLibrary::GetLibrary(); @@ -262,11 +241,11 @@ TEST_CASE("Validate Pokemon HasType in Script") { .WithForme("default"_cnc) .WithGender(CreatureLib::Library::Gender::Male) .Build(); - for (size_t i = 0; i < mon->GetTypes().Count(); i++) { + for (auto t : mon->GetTypes()) { auto data = GetScript(mainLib, "testHasType"_cnc); data.Context->SetArgObject(0, const_cast(mon)); - data.Context->SetArgByte(1, mon->GetTypes()[i]); + data.Context->SetArgByte(1, t); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE((bool)data.Context->GetReturnWord());