Register many new types and properties in AngelScript.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-02-16 16:43:37 +01:00
parent 0147515ffb
commit 98c3bdea1a
9 changed files with 186 additions and 7 deletions

View File

@@ -0,0 +1,46 @@
#include "RegisterBattleClass.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp>
#include <cassert>
#include <cstdint>
void RegisterBattleClass::Register(asIScriptEngine* engine) {
RegisterBattleRandom(engine);
RegisterBattle(engine);
}
void RegisterBattleClass::RegisterBattleRandom(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BattleRandom", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom",
"bool EffectChance(int16 chance, ExecutingMove@ move, Pokemon@ target )",
asMETHOD(CreatureLib::Battling::BattleRandom, EffectChance), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom", "int Get()",
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (), int32_t),
asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom", "int Get(int max)",
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (int32_t), int32_t),
asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleRandom", "int Get(int min, int max)",
asMETHODPR(CreatureLib::Battling::BattleRandom, Get, (int32_t, int32_t), int32_t),
asCALL_THISCALL);
assert(r >= 0);
}
void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property",
asMETHOD(CreatureLib::Battling::Battle, GetLibrary), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
asMETHOD(CreatureLib::Battling::Battle, CanUse), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Battle", "bool get_CanFlee() const property",
asMETHOD(CreatureLib::Battling::Battle, CanFlee), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Battle", "BattleRandom& get_Random() const property",
asMETHOD(CreatureLib::Battling::Battle, GetRandom), asCALL_THISCALL);
assert(r >= 0);
}

View File

@@ -0,0 +1,12 @@
#ifndef PKMNLIB_REGISTERBATTLECLASS_HPP
#define PKMNLIB_REGISTERBATTLECLASS_HPP
#include <angelscript.h>
class RegisterBattleClass {
static void RegisterBattle(asIScriptEngine* engine);
static void RegisterBattleRandom(asIScriptEngine* engine);
public:
static void Register(asIScriptEngine* engine);
};
#endif // PKMNLIB_REGISTERBATTLECLASS_HPP

View File

@@ -1,9 +1,10 @@
#include "RegisterBattleLibrary.hpp"
#include <cassert>
#include "../../../../Battling/Library/DamageLibrary.hpp"
#include "../../../../Battling/Library/BattleLibrary.hpp"
void RegisterBattleLibrary::Register(asIScriptEngine* engine) {
RegisterDamageLibrary(engine);
RegisterLibrary(engine);
}
void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("DamageLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
@@ -12,3 +13,26 @@ void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) {
asMETHOD(PkmnLib::Battling::DamageLibrary, GetDamage), asCALL_THISCALL);
assert(r >= 0);
}
void RegisterBattleLibrary::RegisterLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BattleLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleLibrary", "const LibrarySettings@ get_Settings() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetSettings), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleLibrary", "const StaticLibrary@ get_StaticLibrary() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetStaticLib), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetSpeciesLibrary), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleLibrary", "const MoveLibrary@ get_MoveLibrary() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetMoveLibrary), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleLibrary", "const ItemLibrary@ get_ItemLibrary() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetItemLibrary), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleLibrary", "const DamageLibrary@ get_DamageLibrary() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetDamageLibrary), asCALL_THISCALL);
assert(r >= 0);
}

View File

@@ -4,6 +4,7 @@
#include <angelscript.h>
class RegisterBattleLibrary {
static void RegisterDamageLibrary(asIScriptEngine* engine);
static void RegisterLibrary(asIScriptEngine* engine);
public:
static void Register(asIScriptEngine* engine);
};

View File

@@ -0,0 +1,63 @@
#include "RegisterTurnChoices.hpp"
#include <CreatureLib/Battling/TurnChoices/AttackTurnChoice.hpp>
#include <CreatureLib/Battling/TurnChoices/BaseTurnChoice.hpp>
#include <cassert>
#include "../RefCast.hpp"
void RegisterTurnChoices::Register(asIScriptEngine* engine) {
RegisterTurnChoiceKindEnum(engine);
RegisterBaseTurnChoice(engine);
RegisterMoveTurnChoice(engine);
}
void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind");
assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Pass", (int)CreatureLib::Battling::TurnChoiceKind::Pass);
assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Attack", (int)CreatureLib::Battling::TurnChoiceKind::Attack);
assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Item", (int)CreatureLib::Battling::TurnChoiceKind::Item);
assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Switch", (int)CreatureLib::Battling::TurnChoiceKind::Switch);
assert(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Flee", (int)CreatureLib::Battling::TurnChoiceKind::Flee);
assert(r >= 0);
}
void RegisterTurnChoices::RegisterBaseTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BaseTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetKind), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetUser), asCALL_THISCALL);
assert(r >= 0);
}
void RegisterTurnChoices::RegisterMoveTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetKind), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "Pokemon@ get_User() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetUser), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "LearnedMove@ get_Move() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetAttack), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "int8 get_Priority() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetPriority), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod(
"BaseTurnChoice", "MoveTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::AttackTurnChoice>)),
asCALL_CDECL_OBJLAST);
assert(r >= 0);
r = engine->RegisterObjectMethod(
"MoveTurnChoice", "BaseTurnChoice@ opImplCast()",
asFUNCTION((refCast<CreatureLib::Battling::AttackTurnChoice, CreatureLib::Battling::BaseTurnChoice>)),
asCALL_CDECL_OBJLAST);
assert(r >= 0);
}

View File

@@ -0,0 +1,13 @@
#ifndef PKMNLIB_REGISTERTURNCHOICES_HPP
#define PKMNLIB_REGISTERTURNCHOICES_HPP
#include <angelscript.h>
class RegisterTurnChoices {
static void RegisterTurnChoiceKindEnum(asIScriptEngine* engine);
static void RegisterBaseTurnChoice(asIScriptEngine* engine);
static void RegisterMoveTurnChoice(asIScriptEngine* engine);
public:
static void Register(asIScriptEngine* engine);
};
#endif // PKMNLIB_REGISTERTURNCHOICES_HPP

View File

@@ -0,0 +1,10 @@
#ifndef PKMNLIB_REFCAST_HPP
#define PKMNLIB_REFCAST_HPP
template<class A, class B>
B* refCast(A* a)
{
if( !a ) return 0;
B* b = dynamic_cast<B*>(a);
return b;
}
#endif // PKMNLIB_REFCAST_HPP