Fix for Pokemon.HasHeldItem in AngelScript, added tests.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
d2573fe959
commit
0700f7cfbd
|
@ -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)",
|
||||
|
|
|
@ -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<PkmnLib::Battling::Pokemon*>(mon));
|
||||
std::string item = "testItem";
|
||||
data.Context->SetArgAddress(1, &item);
|
||||
|
||||
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
|
||||
REQUIRE((bool)data.Context->GetReturnDWord());
|
||||
|
||||
|
||||
delete mon;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue