Fix for Pokemon.HasHeldItem in AngelScript, added tests.
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		| @@ -82,8 +82,8 @@ CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) { | |||||||
|     } |     } | ||||||
|     return nullptr; |     return nullptr; | ||||||
| } | } | ||||||
| static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const Arbutils::CaseInsensitiveConstString& str) { | static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ConstString& str) { | ||||||
|     return obj->HasHeldItem(str); |     return obj->HasHeldItem(str.GetHash()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -115,7 +115,7 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { | |||||||
|                                      asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL); |                                      asMETHOD(PkmnLib::Battling::Pokemon, GetHeldItem), asCALL_THISCALL); | ||||||
|     assert(r >= 0); |     assert(r >= 0); | ||||||
|     r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", |     r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const", | ||||||
|                                      asFUNCTION(HasHeldItem), asCALL_CDECL_OBJLAST); |                                      asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST); | ||||||
|     assert(r >= 0); |     assert(r >= 0); | ||||||
|     r = engine->RegisterObjectMethod( |     r = engine->RegisterObjectMethod( | ||||||
|         "Pokemon", "void SetHeldItem(const string &in name)", |         "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 testDamage(Pokemon@ p, uint32 damage, DamageSource source){ p.Damage(damage, source); } | ||||||
|     void testHeal(Pokemon@ p, uint32 amount){ p.Heal(amount); } |     void testHeal(Pokemon@ p, uint32 amount){ p.Heal(amount); } | ||||||
|     bool testMove(Pokemon@ p, uint index, LearnedMove@ move){ return p.GetMoves()[index] is move; } |     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; |     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 | #endif | ||||||
		Reference in New Issue
	
	Block a user