Implements new standard macro/function for registering getters in Angelscript, to reduce the amount of errors there.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-09-21 22:37:13 +02:00
parent a43dc45665
commit 2e8cf4379b
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
5 changed files with 128 additions and 142 deletions

View File

@ -1,5 +1,6 @@
#include "RegisterBattleLibrary.hpp" #include "RegisterBattleLibrary.hpp"
#include "../../../../Battling/Library/BattleLibrary.hpp" #include "../../../../Battling/Library/BattleLibrary.hpp"
#include "../HelperFile.hpp"
void RegisterBattleLibrary::Register(asIScriptEngine* engine) { void RegisterBattleLibrary::Register(asIScriptEngine* engine) {
RegisterDamageLibrary(engine); RegisterDamageLibrary(engine);
@ -14,24 +15,18 @@ void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) {
} }
void RegisterBattleLibrary::RegisterLibrary(asIScriptEngine* engine) { void RegisterBattleLibrary::RegisterLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BattleLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(engine->RegisterObjectType("BattleLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
assert(r >= 0);
r = engine->RegisterObjectMethod("BattleLibrary", "const LibrarySettings@ get_Settings() const property", REGISTER_GETTER("BattleLibrary", "const LibrarySettings@ get_Settings() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetSettings), asCALL_THISCALL); PkmnLib::Battling::BattleLibrary, GetSettings);
assert(r >= 0); REGISTER_GETTER("BattleLibrary", "const StaticLibrary@ get_StaticLibrary() const property",
r = engine->RegisterObjectMethod("BattleLibrary", "const StaticLibrary@ get_StaticLibrary() const property", PkmnLib::Battling::BattleLibrary, GetStaticLib);
asMETHOD(PkmnLib::Battling::BattleLibrary, GetStaticLib), asCALL_THISCALL); REGISTER_GETTER("BattleLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
assert(r >= 0); PkmnLib::Battling::BattleLibrary, GetSpeciesLibrary);
r = engine->RegisterObjectMethod("BattleLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property", REGISTER_GETTER("BattleLibrary", "const MoveLibrary@ get_MoveLibrary() const property",
asMETHOD(PkmnLib::Battling::BattleLibrary, GetSpeciesLibrary), asCALL_THISCALL); PkmnLib::Battling::BattleLibrary, GetMoveLibrary);
assert(r >= 0); REGISTER_GETTER("BattleLibrary", "const ItemLibrary@ get_ItemLibrary() const property",
r = engine->RegisterObjectMethod("BattleLibrary", "const MoveLibrary@ get_MoveLibrary() const property", PkmnLib::Battling::BattleLibrary, GetItemLibrary);
asMETHOD(PkmnLib::Battling::BattleLibrary, GetMoveLibrary), asCALL_THISCALL); REGISTER_GETTER("BattleLibrary", "const DamageLibrary@ get_DamageLibrary() const property",
assert(r >= 0); CreatureLib::Battling::BattleLibrary, GetDamageLibrary);
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

@ -88,17 +88,6 @@ static std::string NicknameWrapper(const PkmnLib::Battling::Pokemon* obj) {
return std::string(obj->GetNickname().value()); return std::string(obj->GetNickname().value());
} }
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::CreatureSpecies, GetSpecies);
BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const PkmnLib::Library::PokemonForme, GetForme);
OPTIONAL_BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::Creature, const CreatureLib::Library::CreatureSpecies,
GetDisplaySpecies);
OPTIONAL_BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::Creature, const CreatureLib::Library::SpeciesVariant,
GetDisplayVariant);
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib::Library::Item, GetHeldItem);
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle);
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::BattleSide, GetBattleSide);
static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& name) { static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& name) {
auto handle = CScriptHandle(); auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get()); auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
@ -108,32 +97,36 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const A
} }
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) { void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT); int r;
Ensure(r >= 0); Ensure(engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_Species() const property", REGISTER_GETTER("Pokemon", "const Species@ get_Species() const property", CreatureLib::Battling::Creature,
asFUNCTION(GetSpeciesWrapper), asCALL_CDECL_OBJLAST); GetSpecies);
Ensure(r >= 0); REGISTER_GETTER("Pokemon", "const Forme@ get_Forme() const property", CreatureLib::Battling::Creature, GetVariant);
r = engine->RegisterObjectMethod("Pokemon", "const Forme@ get_Forme() const property", asFUNCTION(GetFormeWrapper), REGISTER_GETTER("Pokemon", "uint8 get_Level() const property", CreatureLib::Battling::Creature, GetLevel);
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0); REGISTER_GETTER("Pokemon", "uint32 get_Experience() const property", CreatureLib::Battling::Creature,
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Level() const property", GetExperience);
asMETHOD(PkmnLib::Battling::Pokemon, GetLevel), asCALL_THISCALL); REGISTER_GETTER("Pokemon", "Gender get_Gender() const property", CreatureLib::Battling::Creature, GetGender);
Ensure(r >= 0); REGISTER_GETTER("Pokemon", "uint8 get_Coloring() const property", CreatureLib::Battling::Creature, GetColoring);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_Experience() const property", REGISTER_GETTER("Pokemon", "bool get_Shiny() const property", PkmnLib::Battling::Pokemon, IsShiny);
asMETHOD(PkmnLib::Battling::Pokemon, GetExperience), asCALL_THISCALL); REGISTER_GETTER("Pokemon", "const Item@ get_HeldItem() const property", CreatureLib::Battling::Creature,
Ensure(r >= 0); GetHeldItem);
r = engine->RegisterObjectMethod("Pokemon", "Gender get_Gender() const property", asFUNCTION(Pkmn_GenderWrapper), REGISTER_GETTER("Pokemon", "uint32 get_CurrentHealth() const property", CreatureLib::Battling::Creature,
asCALL_CDECL_OBJFIRST); GetCurrentHealth);
Ensure(r >= 0); REGISTER_GETTER("Pokemon", "const constString& get_ActiveAbility() const property", CreatureLib::Battling::Creature,
r = engine->RegisterObjectMethod("Pokemon", "uint8 get_Coloring() const property", GetActiveTalent);
asMETHOD(PkmnLib::Battling::Pokemon, GetColoring), asCALL_THISCALL); REGISTER_GETTER("Pokemon", "bool get_IsFainted() const property", CreatureLib::Battling::Creature, IsFainted);
Ensure(r >= 0); REGISTER_GETTER("Pokemon", "uint32 get_MaxHealth() const property", CreatureLib::Battling::Creature, GetMaxHealth);
r = engine->RegisterObjectMethod("Pokemon", "bool get_Shiny() const property", REGISTER_GETTER("Pokemon", "const Species@ get_DisplaySpecies() const property", CreatureLib::Battling::Creature,
asMETHOD(PkmnLib::Battling::Pokemon, IsShiny), asCALL_THISCALL); GetDisplaySpecies);
Ensure(r >= 0); REGISTER_GETTER("Pokemon", "const Species@ get_DisplayForme() const property", CreatureLib::Battling::Creature,
r = engine->RegisterObjectMethod("Pokemon", "const Item@ get_HeldItem() const property", GetDisplayVariant);
asFUNCTION(GetHeldItemWrapper), asCALL_CDECL_OBJFIRST); REGISTER_GETTER("Pokemon", "Battle@ get_Battle() const property", CreatureLib::Battling::Creature, GetBattle);
Ensure(r >= 0); REGISTER_GETTER("Pokemon", "BattleSide@ get_BattleSide() const property", CreatureLib::Battling::Creature,
GetBattleSide);
REGISTER_GETTER("Pokemon", "const constString& get_Status() const property", CreatureLib::Battling::Creature,
GetStatusName);
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_OBJFIRST); asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0); Ensure(r >= 0);
@ -145,24 +138,12 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
(const ArbUt::BorrowedPtr<const CreatureLib::Library::Item>&), void), (const ArbUt::BorrowedPtr<const CreatureLib::Library::Item>&), void),
asCALL_THISCALL); asCALL_THISCALL);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_CurrentHealth() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetCurrentHealth), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "string get_Nickname() const property", asFUNCTION(NicknameWrapper), r = engine->RegisterObjectMethod("Pokemon", "string get_Nickname() const property", asFUNCTION(NicknameWrapper),
asCALL_CDECL_OBJFIRST); asCALL_CDECL_OBJFIRST);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const constString& get_ActiveAbility() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetActiveTalent), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "bool get_IsFainted() const property",
asMETHOD(PkmnLib::Battling::Pokemon, IsFainted), asCALL_THISCALL);
Ensure(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);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 get_MaxHealth() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetMaxHealth), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)", r = engine->RegisterObjectMethod("Pokemon", "void Damage(uint32 type, DamageSource source)",
asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, Damage), asCALL_THISCALL);
Ensure(r >= 0); Ensure(r >= 0);
@ -178,12 +159,6 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)", r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)",
asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplaySpecies() const property",
asFUNCTION(GetDisplaySpeciesWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Species@ get_DisplayForme() const property",
asFUNCTION(GetDisplayVariantWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "uint32 GetFlatStat(Statistic stat) const", r = engine->RegisterObjectMethod("Pokemon", "uint32 GetFlatStat(Statistic stat) const",
asMETHOD(PkmnLib::Battling::Pokemon, GetFlatStat), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, GetFlatStat), asCALL_THISCALL);
Ensure(r >= 0); Ensure(r >= 0);
@ -205,15 +180,6 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asCALL_THISCALL); asCALL_THISCALL);
Ensure(r >= 0); Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "Battle@ get_Battle() const property", asFUNCTION(GetBattleWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "BattleSide@ get_BattleSide() const property",
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const constString& get_Status() const property",
asMETHOD(PkmnLib::Battling::Pokemon, GetStatusName), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void ClearStatus() const", r = engine->RegisterObjectMethod("Pokemon", "void ClearStatus() const",
asMETHOD(PkmnLib::Battling::Pokemon, ClearStatus), asCALL_THISCALL); asMETHOD(PkmnLib::Battling::Pokemon, ClearStatus), asCALL_THISCALL);
Ensure(r >= 0); Ensure(r >= 0);

View File

@ -17,3 +17,51 @@
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it. // Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
#define ENUM__SIZE_WRAPPER(name, type, func) \ #define ENUM__SIZE_WRAPPER(name, type, func) \
int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); } int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); }
template <typename Test, template <typename...> class Ref> struct is_specialization : std::false_type {};
template <template <typename...> class Ref, typename... Args>
struct is_specialization<Ref<Args...>, Ref> : std::true_type {};
template <template <typename...> class Ref, typename... Args>
struct is_specialization<const Ref<Args...>&, Ref> : std::true_type {};
template <template <typename...> class Ref, typename... Args>
struct is_specialization<Ref<Args...>&, Ref> : std::true_type {};
template <typename T, typename R, R (T::*Method)() const>
void RegisterGetter(asIScriptEngine* engine, const char* asType, const char* asDef) {
if constexpr (std::is_enum<R>()) {
auto l = [](const T* p) { return (i32)(p->*Method)(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (const T*), i32), asCALL_CDECL_OBJFIRST) >=
0);
} else if constexpr (is_specialization<R, ArbUt::BorrowedPtr>::value) {
auto l = [](const T* p) { return (void*)(p->*Method)().GetRaw(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (const T*), void*), asCALL_CDECL_OBJFIRST) >=
0);
} else if constexpr (is_specialization<R, std::unique_ptr>::value) {
auto l = [](const T* p) { return (void*)(p->*Method)().get(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (const T*), void*), asCALL_CDECL_OBJFIRST) >=
0);
} else if constexpr (is_specialization<R, ArbUt::OptionalBorrowedPtr>::value) {
auto l = [](const T* p) {
auto v = (p->*Method)();
if (v.HasValue()) {
return (void*)v.GetValue();
}
return (void*)nullptr;
};
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (const T*), void*), asCALL_CDECL_OBJFIRST) >=
0);
} else if constexpr (std::is_reference<R>::value) {
static_assert(!std::is_enum<R>());
auto l = [](const T* p) { return (void*)&(p->*Method)(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (const T*), void*), asCALL_CDECL_OBJFIRST) >=
0);
} else {
static_assert(!std::is_enum<R>());
auto l = [](const T* p) { return (p->*Method)(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (const T*), R), asCALL_CDECL_OBJFIRST) >= 0);
}
}
#define REGISTER_GETTER(asType, asDef, cType, cFunc) \
RegisterGetter<cType, std::result_of<decltype (&cType::cFunc)(cType)>::type, &cType::cFunc>(engine, asType, asDef);

View File

@ -8,44 +8,27 @@ void RegisterStaticLibraryTypes::Register(asIScriptEngine* engine) {
} }
void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* engine) { void RegisterStaticLibraryTypes::RegisterLibrarySettingsType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("LibrarySettings", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(engine->RegisterObjectType("LibrarySettings", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
r = engine->RegisterObjectMethod("LibrarySettings", "uint8 get_MaximalLevel() const property", REGISTER_GETTER("LibrarySettings", "uint8 get_MaximalLevel() const property", CreatureLib::Library::LibrarySettings,
asMETHOD(PkmnLib::Library::LibrarySettings, GetMaximalLevel), asCALL_THISCALL); GetMaximalLevel);
assert(r >= 0); REGISTER_GETTER("LibrarySettings", "uint8 get_MaximalMoves() const property", CreatureLib::Library::LibrarySettings,
r = engine->RegisterObjectMethod("LibrarySettings", "uint8 get_MaximalMoves() const property", GetMaximalAttacks);
asMETHOD(PkmnLib::Library::LibrarySettings, GetMaximalAttacks), asCALL_THISCALL); REGISTER_GETTER("LibrarySettings", "uint16 get_ShinyRate() const property", PkmnLib::Library::LibrarySettings,
assert(r >= 0); GetShinyRate);
r = engine->RegisterObjectMethod("LibrarySettings", "uint16 get_ShinyRate() const property",
asMETHOD(PkmnLib::Library::LibrarySettings, GetShinyRate), asCALL_THISCALL);
assert(r >= 0);
} }
UNIQUE_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::LibrarySettings, GetSettings);
UNIQUE_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::SpeciesLibrary, GetSpeciesLibrary);
UNIQUE_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::MoveLibrary, GetMoveLibrary);
UNIQUE_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const PkmnLib::Library::ItemLibrary, GetItemLibrary);
UNIQUE_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const CreatureLib::Library::GrowthRateLibrary, GetGrowthRates);
UNIQUE_PTR_GETTER_FUNC(PkmnLib::Library::PokemonLibrary, const CreatureLib::Library::TypeLibrary, GetTypeLibrary);
void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) { void RegisterStaticLibraryTypes::RegisterLibraryType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT); Ensure(engine->RegisterObjectType("StaticLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
assert(r >= 0); REGISTER_GETTER("StaticLibrary", "const LibrarySettings@ get_Settings() const property",
r = engine->RegisterObjectMethod("StaticLibrary", "const LibrarySettings@ get_Settings() const property", CreatureLib::Library::DataLibrary, GetSettings);
asFUNCTION(GetSettingsWrapper), asCALL_CDECL_OBJLAST); REGISTER_GETTER("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property",
assert(r >= 0); CreatureLib::Library::DataLibrary, GetSpeciesLibrary);
r = engine->RegisterObjectMethod("StaticLibrary", "const SpeciesLibrary@ get_SpeciesLibrary() const property", REGISTER_GETTER("StaticLibrary", "const MoveLibrary@ get_MoveLibrary() const property",
asFUNCTION(GetSpeciesLibraryWrapper), asCALL_CDECL_OBJLAST); CreatureLib::Library::DataLibrary, GetAttackLibrary);
assert(r >= 0); REGISTER_GETTER("StaticLibrary", "const ItemLibrary@ get_ItemLibrary() const property",
r = engine->RegisterObjectMethod("StaticLibrary", "const MoveLibrary@ get_MoveLibrary() const property", CreatureLib::Library::DataLibrary, GetItemLibrary);
asFUNCTION(GetMoveLibraryWrapper), asCALL_CDECL_OBJLAST); REGISTER_GETTER("StaticLibrary", "const GrowthRateLibrary@ get_GrowthRateLibrary() const property",
assert(r >= 0); CreatureLib::Library::DataLibrary, GetGrowthRates);
r = engine->RegisterObjectMethod("StaticLibrary", "const ItemLibrary@ get_ItemLibrary() const property", REGISTER_GETTER("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property",
asFUNCTION(GetItemLibraryWrapper), asCALL_CDECL_OBJLAST); CreatureLib::Library::DataLibrary, GetTypeLibrary);
assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const GrowthRateLibrary@ get_GrowthRateLibrary() const property",
asFUNCTION(GetGrowthRatesWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0);
r = engine->RegisterObjectMethod("StaticLibrary", "const TypeLibrary@ get_TypeLibrary() const property",
asFUNCTION(GetTypeLibraryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0);
} }

View File

@ -339,9 +339,7 @@ TEST_CASE("Validate Pokemon HasHeldItem in Script") {
TEST_CASE("Test Pokemon SetHeldItem in Script") { TEST_CASE("Test Pokemon SetHeldItem in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3"_cnc, 30) auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3"_cnc, 30).WithForme("default"_cnc).Build();
.WithForme("default"_cnc)
.Build();
auto data = GetScript(mainLib, "testSetHeldItem"_cnc); auto data = GetScript(mainLib, "testSetHeldItem"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon)); data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
@ -357,9 +355,7 @@ TEST_CASE("Test Pokemon SetHeldItem in Script") {
TEST_CASE("Test Pokemon SetHeldItem2 in Script") { TEST_CASE("Test Pokemon SetHeldItem2 in Script") {
auto mainLib = TestLibrary::GetLibrary(); auto mainLib = TestLibrary::GetLibrary();
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3"_cnc, 30) auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies3"_cnc, 30).WithForme("default"_cnc).Build();
.WithForme("default"_cnc)
.Build();
auto data = GetScript(mainLib, "testSetHeldItem2"_cnc); auto data = GetScript(mainLib, "testSetHeldItem2"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon)); data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));
@ -369,6 +365,4 @@ TEST_CASE("Test Pokemon SetHeldItem2 in Script") {
delete mon; delete mon;
} }
#endif #endif