Update CreatureLib.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-06-05 16:54:57 +02:00
parent 12066e1dfe
commit 34fb528da4
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 2 additions and 41 deletions

View File

@ -61,21 +61,6 @@ void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender) 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<uint8>");
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) { CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) {
asIScriptContext* ctx = asGetActiveContext(); asIScriptContext* ctx = asGetActiveContext();
if (ctx) { if (ctx) {
@ -150,9 +135,6 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property", r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property",
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
Assert(r >= 0); 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", r = engine->RegisterObjectMethod("Pokemon", "bool HasType(uint8 type) const",
asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, HasType), asCALL_THISCALL);
Assert(r >= 0); Assert(r >= 0);

View File

@ -20,7 +20,6 @@ class testScript1 {
bool testNickname(Pokemon@ p, const string& name){ return p.Nickname == name; } bool testNickname(Pokemon@ p, const string& name){ return p.Nickname == name; }
bool testActiveAbility(Pokemon@ p, const constString &in ability){ return p.ActiveAbility == ability; } bool testActiveAbility(Pokemon@ p, const constString &in ability){ return p.ActiveAbility == ability; }
bool testIsFainted(Pokemon@ p, bool b){ return p.IsFainted == b; } 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); } bool testHasType(Pokemon@ p, uint8 type){ return p.HasType(type); }
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); }
@ -235,26 +234,6 @@ TEST_CASE("Validate Pokemon IsFainted in Script") {
delete mon; 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<PkmnLib::Battling::Pokemon*>(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") { TEST_CASE("Validate Pokemon HasType in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
@ -262,11 +241,11 @@ TEST_CASE("Validate Pokemon HasType in Script") {
.WithForme("default"_cnc) .WithForme("default"_cnc)
.WithGender(CreatureLib::Library::Gender::Male) .WithGender(CreatureLib::Library::Gender::Male)
.Build(); .Build();
for (size_t i = 0; i < mon->GetTypes().Count(); i++) { for (auto t : mon->GetTypes()) {
auto data = GetScript(mainLib, "testHasType"_cnc); auto data = GetScript(mainLib, "testHasType"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon)); data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
data.Context->SetArgByte(1, mon->GetTypes()[i]); data.Context->SetArgByte(1, t);
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED); REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)data.Context->GetReturnWord()); REQUIRE((bool)data.Context->GetReturnWord());