Adds Angelscript wrappers for Party.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-05-08 12:12:36 +02:00
parent 1c66aa8696
commit 6def68cf72
7 changed files with 87 additions and 11 deletions

View File

@@ -13,6 +13,7 @@
#include "TypeRegistry/Battling/RegisterBattleClass.hpp"
#include "TypeRegistry/Battling/RegisterBattleLibrary.hpp"
#include "TypeRegistry/Battling/RegisterExecutingAttack.hpp"
#include "TypeRegistry/Battling/RegisterParty.hpp"
#include "TypeRegistry/Battling/RegisterPokemonClass.hpp"
#include "TypeRegistry/Battling/RegisterTurnChoices.hpp"
#include "TypeRegistry/ConstString.hpp"
@@ -120,6 +121,7 @@ void AngelScriptResolver::RegisterTypes() {
Ensure(r >= 0);
RegisterPokemonClass::Register(_engine);
RegisterParty::Register(_engine);
RegisterExecutingAttack::Register(_engine);
RegisterTurnChoices::Register(_engine);
RegisterBattleLibrary::Register(_engine);

View File

@@ -49,11 +49,22 @@ void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) {
}
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Battle, CreatureLib::Battling::ChoiceQueue, GetCurrentTurnQueue);
CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battle* battle, u8 index) {
return battle->GetSides()[index];
}
CreatureLib::Battling::BattleParty* GetPartyWrapper(PkmnLib::Battling::Battle* battle, u8 index) {
return battle->GetParties()[index];
}
CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle* battle, PkmnLib::Battling::Pokemon* p) {
auto v = battle->FindPartyForCreature(p);
if (v.HasValue()) {
return v.GetValue();
}
return {};
}
static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
@@ -117,4 +128,10 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Battle", "BattleSide@ GetBattleSide(uint8 index)",
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "Party@ GetParty(uint8 index)", asFUNCTION(GetPartyWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "Party@ FindPartyForPokemon(Pokemon@ pokemon)",
asFUNCTION(FindPartyWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
}

View File

@@ -0,0 +1,36 @@
#include "RegisterParty.hpp"
#include "../../../../Battling/Pokemon/PokemonParty.hpp"
#include "../HelperFile.hpp"
#include <CreatureLib/Battling/Models/BattleParty.hpp>
void RegisterParty::Register(asIScriptEngine* engine) {
RegisterPartyClass(engine);
RegisterBattleParty(engine);
}
static PkmnLib::Battling::Pokemon* GetAtIndexWrapper(PkmnLib::Battling::PokemonParty* obj, size_t i) {
auto v = obj->GetAtIndex(i);
if (v.HasValue()) {
return v.GetValue();
}
return {};
}
void RegisterParty::RegisterPartyClass(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("Party", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Party", "Pokemon@ GetAtIndex(int index) const", asFUNCTION(GetAtIndexWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Party", "int get_Length() const property",
asMETHOD(PkmnLib::Battling::PokemonParty, GetLength), asCALL_THISCALL);
Ensure(r >= 0);
}
void RegisterParty::RegisterBattleParty(asIScriptEngine* engine) {
auto r = engine->RegisterObjectType("BattleParty", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleParty", "Party@ get_Party() const property",
asMETHOD(CreatureLib::Battling::BattleParty, GetParty), asCALL_THISCALL);
Ensure(r >= 0);
}

View File

@@ -0,0 +1,13 @@
#ifndef PKMNLIB_REGISTERPARTY_HPP
#define PKMNLIB_REGISTERPARTY_HPP
#include <angelscript.h>
class RegisterParty {
static void RegisterPartyClass(asIScriptEngine* engine);
static void RegisterBattleParty(asIScriptEngine* engine);
public:
static void Register(asIScriptEngine* engine);
};
#endif // PKMNLIB_REGISTERPARTY_HPP