Register many new types and properties in AngelScript.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
0147515ffb
commit
98c3bdea1a
|
@ -44,7 +44,7 @@ class PkmnLibConan(ConanFile):
|
||||||
self.options["AngelScript"].link_std_statically = True
|
self.options["AngelScript"].link_std_statically = True
|
||||||
|
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
self.requires("CreatureLib/54e366fc1b3a44b200de41421707bfe4802aaecb@creaturelib/master")
|
self.requires("CreatureLib/f3b5f9e8f929a10867512f71f54ff02448b58f5c@creaturelib/master")
|
||||||
if self.options.script_handler == "angelscript":
|
if self.options.script_handler == "angelscript":
|
||||||
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
self.requires("AngelScript/2.34@AngelScript/Deukhoofd")
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
#include "AngelScripResolver.hpp"
|
#include "AngelScripResolver.hpp"
|
||||||
|
#include <CreatureLib/Battling/Models/Creature.hpp>
|
||||||
|
#include <cassert>
|
||||||
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||||
#include "../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
#include "../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
||||||
#include "../../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
#include "../../../extern/angelscript_addons/scripthelper/scripthelper.h"
|
||||||
#include "../../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h"
|
#include "../../../extern/angelscript_addons/scriptstdstring/scriptstdstring.h"
|
||||||
#include <cassert>
|
|
||||||
#include "TypeRegistry/BasicScriptClass.hpp"
|
#include "TypeRegistry/BasicScriptClass.hpp"
|
||||||
|
#include "TypeRegistry/Battling/RegisterBattleClass.hpp"
|
||||||
|
#include "TypeRegistry/Battling/RegisterBattleLibrary.hpp"
|
||||||
#include "TypeRegistry/Battling/RegisterExecutingAttack.hpp"
|
#include "TypeRegistry/Battling/RegisterExecutingAttack.hpp"
|
||||||
#include "TypeRegistry/Battling/RegisterPokemonClass.hpp"
|
#include "TypeRegistry/Battling/RegisterPokemonClass.hpp"
|
||||||
|
#include "TypeRegistry/Battling/RegisterTurnChoices.hpp"
|
||||||
#include "TypeRegistry/Library/RegisterGrowthRateTypes.hpp"
|
#include "TypeRegistry/Library/RegisterGrowthRateTypes.hpp"
|
||||||
#include "TypeRegistry/Library/RegisterItemTypes.hpp"
|
#include "TypeRegistry/Library/RegisterItemTypes.hpp"
|
||||||
#include "TypeRegistry/Library/RegisterMoveTypes.hpp"
|
#include "TypeRegistry/Library/RegisterMoveTypes.hpp"
|
||||||
|
@ -35,7 +39,6 @@ void AngelScripResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg) {
|
||||||
_engine->SetEngineProperty(asEP_PROPERTY_ACCESSOR_MODE, 2);
|
_engine->SetEngineProperty(asEP_PROPERTY_ACCESSOR_MODE, 2);
|
||||||
_engine->SetEngineProperty(asEP_COMPILER_WARNINGS, 2);
|
_engine->SetEngineProperty(asEP_COMPILER_WARNINGS, 2);
|
||||||
|
|
||||||
|
|
||||||
RegisterStdString(_engine);
|
RegisterStdString(_engine);
|
||||||
|
|
||||||
// Register Script Array type
|
// Register Script Array type
|
||||||
|
@ -69,6 +72,13 @@ void AngelScripResolver::RegisterTypes() {
|
||||||
// Register battle types
|
// Register battle types
|
||||||
RegisterPokemonClass::Register(_engine);
|
RegisterPokemonClass::Register(_engine);
|
||||||
RegisterExecutingAttack::Register(_engine);
|
RegisterExecutingAttack::Register(_engine);
|
||||||
|
RegisterTurnChoices::Register(_engine);
|
||||||
|
RegisterBattleLibrary::Register(_engine);
|
||||||
|
RegisterBattleClass::Register(_engine);
|
||||||
|
[[maybe_unused]] int r =
|
||||||
|
_engine->RegisterObjectMethod("Pokemon", "const Battle@ get_Battle() const property",
|
||||||
|
asMETHOD(CreatureLib::Battling::Creature, GetBattle), asCALL_THISCALL);
|
||||||
|
assert(r >= 0);
|
||||||
|
|
||||||
// Register base script
|
// Register base script
|
||||||
BasicScriptClass::Register(_engine);
|
BasicScriptClass::Register(_engine);
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
|
@ -1,9 +1,10 @@
|
||||||
#include "RegisterBattleLibrary.hpp"
|
#include "RegisterBattleLibrary.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include "../../../../Battling/Library/DamageLibrary.hpp"
|
#include "../../../../Battling/Library/BattleLibrary.hpp"
|
||||||
|
|
||||||
void RegisterBattleLibrary::Register(asIScriptEngine* engine) {
|
void RegisterBattleLibrary::Register(asIScriptEngine* engine) {
|
||||||
RegisterDamageLibrary(engine);
|
RegisterDamageLibrary(engine);
|
||||||
|
RegisterLibrary(engine);
|
||||||
}
|
}
|
||||||
void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) {
|
void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) {
|
||||||
[[maybe_unused]] int r = engine->RegisterObjectType("DamageLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
[[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);
|
asMETHOD(PkmnLib::Battling::DamageLibrary, GetDamage), asCALL_THISCALL);
|
||||||
assert(r >= 0);
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <angelscript.h>
|
#include <angelscript.h>
|
||||||
class RegisterBattleLibrary {
|
class RegisterBattleLibrary {
|
||||||
static void RegisterDamageLibrary(asIScriptEngine* engine);
|
static void RegisterDamageLibrary(asIScriptEngine* engine);
|
||||||
|
static void RegisterLibrary(asIScriptEngine* engine);
|
||||||
public:
|
public:
|
||||||
static void Register(asIScriptEngine* engine);
|
static void Register(asIScriptEngine* engine);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue