Large cleanup of type registration, added new "NativeArray" (or narray in angelscript) type that simply holds a pointer to a native list, to prevent copies we don't need
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Deukhoofd 2021-09-25 17:56:31 +02:00
parent e5ea2bbc90
commit 8005ad1232
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
27 changed files with 329 additions and 410 deletions

View File

@ -73,7 +73,7 @@ export const PokemonSpecies* PkmnLib_EvolutionData_GetNewSpecies(const Evolution
return data->GetNewSpecies().GetRaw();
}
export size_t PkmnLib_EvolutionData_GetDataCount(const EvolutionData* data) { return data->GetDataCount(); }
export uint8_t PkmnLib_EvolutionData_GetData(const EvolutionData* data, size_t index,
export uint8_t PkmnLib_EvolutionData_GetDataAt(const EvolutionData* data, size_t index,
const CreatureLib::Library::EffectParameter*& out) {
Try(out = data->GetData(index).GetRaw());
Try(out = data->GetDataAt(index).GetRaw());
}

View File

@ -38,15 +38,15 @@ bool PkmnLib::Battling::MiscLibrary::CanEvolveFromLevelUp(
auto time = GetTime();
switch (evolution->GetMethod()) {
case Library::EvolutionMethod::Level: return pokemon->GetLevel() >= evolution->GetData(0)->AsInt();
case Library::EvolutionMethod::Level: return pokemon->GetLevel() >= evolution->GetDataAt(0)->AsInt();
case Library::EvolutionMethod::HighFriendship:
return pokemon->GetFriendship() >= evolution->GetData(0)->AsInt();
return pokemon->GetFriendship() >= evolution->GetDataAt(0)->AsInt();
case Library::EvolutionMethod::HighFriendshipTime:
return pokemon->GetFriendship() >= evolution->GetData(0)->AsInt() &&
time >= (TimeOfDay)evolution->GetData(1)->AsInt() &&
time <= (TimeOfDay)evolution->GetData(2)->AsInt();
return pokemon->GetFriendship() >= evolution->GetDataAt(0)->AsInt() &&
time >= (TimeOfDay)evolution->GetDataAt(1)->AsInt() &&
time <= (TimeOfDay)evolution->GetDataAt(2)->AsInt();
case Library::EvolutionMethod::KnownMove: {
auto v = evolution->GetData(0)->AsString();
auto v = evolution->GetDataAt(0)->AsString();
return std::any_of(pokemon->GetMoves().begin(), pokemon->GetMoves().end(), [v](const auto& move) {
return move.HasValue() && move.GetValue()->GetMoveData()->GetName() == v;
});
@ -55,19 +55,19 @@ bool PkmnLib::Battling::MiscLibrary::CanEvolveFromLevelUp(
// TODO: Implement this
return false;
case Library::EvolutionMethod::TimeBased:
return time >= (TimeOfDay)evolution->GetData(0)->AsInt() &&
time <= (TimeOfDay)evolution->GetData(1)->AsInt();
case Library::EvolutionMethod::HoldsItem: return pokemon->HasHeldItem(evolution->GetData(0)->AsString());
return time >= (TimeOfDay)evolution->GetDataAt(0)->AsInt() &&
time <= (TimeOfDay)evolution->GetDataAt(1)->AsInt();
case Library::EvolutionMethod::HoldsItem: return pokemon->HasHeldItem(evolution->GetDataAt(0)->AsString());
case Library::EvolutionMethod::HoldsItemTime:
return pokemon->HasHeldItem(evolution->GetData(0)->AsString()) &&
time >= (TimeOfDay)evolution->GetData(0)->AsInt() &&
time <= (TimeOfDay)evolution->GetData(1)->AsInt();
return pokemon->HasHeldItem(evolution->GetDataAt(0)->AsString()) &&
time >= (TimeOfDay)evolution->GetDataAt(0)->AsInt() &&
time <= (TimeOfDay)evolution->GetDataAt(1)->AsInt();
case Library::EvolutionMethod::IsGenderAndLevel:
return pokemon->GetLevel() >= evolution->GetData(1)->AsInt() &&
pokemon->GetGender() == (CreatureLib::Library::Gender)evolution->GetData(0)->AsInt();
return pokemon->GetLevel() >= evolution->GetDataAt(1)->AsInt() &&
pokemon->GetGender() == (CreatureLib::Library::Gender)evolution->GetDataAt(0)->AsInt();
case Library::EvolutionMethod::Custom: {
auto script = dynamic_cast<ScriptResolver*>(pokemon->GetLibrary()->GetScriptResolver().get())
->LoadEvolutionScript(evolution->GetData(0)->AsString());
->LoadEvolutionScript(evolution->GetDataAt(0)->AsString());
if (!script.HasValue()) {
return false;
}

View File

@ -87,8 +87,11 @@ namespace PkmnLib::Library {
}
[[nodiscard]] inline EvolutionMethod GetMethod() const noexcept { return _method; }
[[nodiscard]] inline size_t GetDataCount() const noexcept { return _evolutionData.Count(); }
[[nodiscard]] inline const ArbUt::UniquePtrList<const CreatureLib::Library::EffectParameter>& GetData() const {
return _evolutionData;
}
[[nodiscard]] inline ArbUt::BorrowedPtr<const CreatureLib::Library::EffectParameter>
GetData(size_t index) const {
GetDataAt(size_t index) const {
return _evolutionData.At(index);
}
};

View File

@ -3,28 +3,20 @@
#include "AngelScriptResolver.hpp"
#include "AngelscriptUserdata.hpp"
CScriptArray*
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
AngelScriptItemUseScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
auto* ud = _resolver->GetUserdata();
auto* arr = ud->CreateArray("array<EffectParameter@>"_cnc, ls.Count());
for (size_t i = 0; i < ls.Count(); i++) {
arr->SetValue(i, (void**)&ls[i]);
}
return arr;
return new NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>(&ls);
}
void AngelScriptItemUseScript::OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
if (__OnInitialize.Exists) {
CScriptArray* arr = nullptr;
AngelScriptUtils::AngelscriptFunctionCall(
__OnInitialize.Function, _resolver->GetContextPool(), _scriptObject, _resolver, ""_cnc,
[&]([[maybe_unused]] asIScriptContext* ctx) {
arr = GetEffectParameters(parameters);
auto* arr = GetEffectParameters(parameters);
ctx->SetArgAddress(0, arr);
},
[&]([[maybe_unused]] asIScriptContext* ctx) {});
arr->Release();
}
}

View File

@ -3,6 +3,7 @@
#include <CreatureLib/Battling/ScriptHandling/ItemUseScript.hpp>
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
#include "TypeRegistry/NativeArray.hpp"
class AngelScriptResolver;
@ -44,11 +45,12 @@ private:
return FunctionInfo{.Exists = true, .Function = val};
}
CScriptArray* GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
#define ITEM_USE_SCRIPT_HOOK_FUNCTION(name, decl) FunctionInfo __##name = Initialize(decl);
ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const array<EffectParameter@> &in parameters)");
ITEM_USE_SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray<EffectParameter@>@ parameters)");
ITEM_USE_SCRIPT_HOOK_FUNCTION(IsItemUsable, "bool IsItemUsable()");
ITEM_USE_SCRIPT_HOOK_FUNCTION(IsPokemonUseItem, "bool IsPokemonUseItem()");
ITEM_USE_SCRIPT_HOOK_FUNCTION(IsUseValidForPokemon, "bool IsUseValidForPokemon(Pokemon@ target)");

View File

@ -29,6 +29,7 @@
#include "TypeRegistry/Library/RegisterSpeciesTypes.hpp"
#include "TypeRegistry/Library/RegisterStaticLibraryTypes.hpp"
#include "TypeRegistry/Library/RegisterTypeLibrary.hpp"
#include "TypeRegistry/NativeArray.hpp"
PkmnLib::Battling::ScriptResolver* PkmnLib::Battling::BattleLibrary::CreateScriptResolver() {
return new AngelScriptResolver();
@ -94,6 +95,7 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg,
if (includeStandard) {
RegisterStdString(_engine);
ConstStringRegister::Register(_engine);
NativeArray<ArbUt::List<ArbUt::BorrowedPtr<void>>>::Register(_engine);
// Register Script Array type
RegisterScriptArray(_engine, true);

View File

@ -1,7 +1,6 @@
#include "AngelScriptScript.hpp"
#include "AngelScriptFunctionCall.hpp"
#include "AngelScriptResolver.hpp"
#include "AngelscriptUserdata.hpp"
#define CALL_HOOK(name, setup) \
auto s = _type->Get##name(); \
@ -11,23 +10,16 @@
s.Function, _ctxPool, _obj, _resolver, GetName(), [&]([[maybe_unused]] asIScriptContext* ctx) { setup }, \
[&]([[maybe_unused]] asIScriptContext* ctx) {});
CScriptArray* AngelScriptScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
auto arr = _resolver->GetUserdata()->CreateArray("array<EffectParameter@>"_cnc, ls.Count());
for (size_t i = 0; i < ls.Count(); i++) {
arr->SetValue(i, (void**)&ls[i]);
}
return arr;
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
AngelScriptScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls) {
return new NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>(&ls);
}
void AngelScriptScript::OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
CScriptArray* arr = nullptr;
CALL_HOOK(OnInitialize, {
arr = GetEffectParameters(parameters);
auto arr = GetEffectParameters(parameters);
ctx->SetArgAddress(0, arr);
})
if (arr != nullptr) {
arr->Release();
}
}
void AngelScriptScript::Stack() { CALL_HOOK(Stack, ); }
void AngelScriptScript::OnRemove() { CALL_HOOK(OnRemove, ); }

View File

@ -6,6 +6,7 @@
#include "../../../extern/angelscript_addons/scriptarray/scriptarray.h"
#include "../../Battling/PkmnScript.hpp"
#include "AngelScriptTypeInfo.hpp"
#include "TypeRegistry/NativeArray.hpp"
class AngelScriptResolver;
class ContextPool;
@ -17,7 +18,8 @@ private:
ContextPool* _ctxPool = nullptr;
asIScriptObject* _obj = nullptr;
CScriptArray* GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>*
GetEffectParameters(const ArbUt::List<CreatureLib::Library::EffectParameter*>& ls);
public:
AngelScriptScript(AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,

View File

@ -70,7 +70,7 @@ private:
public: \
const FunctionInfo& Get##name() const { return __##name; }
SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const array<EffectParameter@> &in parameters)");
SCRIPT_HOOK_FUNCTION(OnInitialize, "void OnInitialize(const narray<EffectParameter@>@ parameters)");
SCRIPT_HOOK_FUNCTION(Stack, "void Stack()");
SCRIPT_HOOK_FUNCTION(OnRemove, "void OnRemove()");
SCRIPT_HOOK_FUNCTION(OnBeforeTurn, "void OnBeforeTurn(BaseTurnChoice@ choice)");

View File

@ -6,7 +6,7 @@ void BasicScriptClass::Register(asIScriptEngine* engine) {
int r = engine->GetModuleByIndex(0)->AddScriptSection("PkmnScript", R"(
shared abstract class PkmnScript {
// CreatureLib methods
void OnInitialize(const array<EffectParameter@> &in parameters){};
void OnInitialize(const narray<EffectParameter@>@ parameters){};
void Stack(){};
void OnRemove(){};
void OnBeforeTurn(BaseTurnChoice@ choice){};
@ -58,7 +58,7 @@ shared abstract class PkmnScript {
Ensure(r >= 0);
r = engine->GetModuleByIndex(0)->AddScriptSection("ItemUseScript", R"(
shared abstract class ItemUseScript {
void OnInitialize(const array<EffectParameter@> &in parameters){};
void OnInitialize(const narray<EffectParameter@>@ parameters){};
bool IsItemUsable() { return false; };
bool IsPokemonUseItem() { return false; };
bool IsUseValidForPokemon(Pokemon@ target) { return false; };

View File

@ -1,6 +1,7 @@
#include "RegisterBattleClass.hpp"
#include <CreatureLib/Battling/Models/Battle.hpp>
#include <CreatureLib/Battling/Models/BattleSide.hpp>
#include <type_traits>
#include "../../../../../extern/angelscript_addons/scripthandle/scripthandle.h"
#include "../../../../Battling/Battle/Battle.hpp"
#include "../../../../Battling/Pokemon/Pokemon.hpp"
@ -8,6 +9,7 @@
#include "../../AngelScriptScript.hpp"
#include "../../AngelscriptUserdata.hpp"
#include "../HelperFile.hpp"
#include "../NativeArray.hpp"
void RegisterBattleClass::Register(asIScriptEngine* engine) {
RegisterChoiceQueue(engine);
@ -86,9 +88,10 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
"BattleSide", "bool SwapPositions(uint8 a, uint8 b)",
asMETHODPR(CreatureLib::Battling::BattleSide, SwapPositions, (u8 a, u8 b), bool), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleSide", "uint8 get_SideIndex() const property",
asMETHOD(CreatureLib::Battling::BattleSide, GetSideIndex), asCALL_THISCALL);
Ensure(r >= 0);
REGISTER_GETTER("BattleSide", "uint8 get_SideIndex() const property", CreatureLib::Battling::BattleSide,
GetSideIndex);
r = engine->RegisterObjectMethod("BattleSide", "uint8 GetPokemonIndex(const Pokemon@ pokemon) const",
asFUNCTION(GetPokemonIndexWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
@ -105,21 +108,10 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
REGISTER_GETTER("Battle", "BattleRandom@ get_Random() const property", CreatureLib::Battling::Battle, GetRandom);
REGISTER_GETTER("Battle", "ChoiceQueue@ get_TurnQueue() const property", CreatureLib::Battling::Battle,
GetCurrentTurnQueue);
{
auto l = [](const CreatureLib::Battling::Battle* b) {
const auto& ls = b->GetSides();
auto* ctx = asGetActiveContext();
auto* ud = (AngelscriptUserdata*)ctx->GetUserData();
auto* arr = ud->CreateArray("array<BattleSide@>"_cnc, ls.Count());
for (size_t i = 0; i < ls.Count(); i++) {
arr->SetValue(i, ls[i].GetRaw());
}
return arr;
};
Ensure(engine->RegisterObjectMethod("Battle", "const array<BattleSide@>& get_Sides() const property",
asFUNCTIONPR(l, (const CreatureLib::Battling::Battle*), CScriptArray*),
asCALL_CDECL_OBJFIRST) >= 0);
}
REGISTER_GETTER("Battle", "narray<BattleSide>@ get_Sides() const property", CreatureLib::Battling::Battle,
GetSides);
REGISTER_GETTER("Battle", "narray<BattleParty>@ get_Parties() const property", CreatureLib::Battling::Battle,
GetParties);
auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);

View File

@ -7,11 +7,7 @@ void RegisterBattleLibrary::Register(asIScriptEngine* engine) {
RegisterLibrary(engine);
}
void RegisterBattleLibrary::RegisterDamageLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("DamageLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("DamageLibrary", "int GetDamage() const",
asMETHOD(PkmnLib::Battling::DamageLibrary, GetDamage), asCALL_THISCALL);
assert(r >= 0);
Ensure(engine->RegisterObjectType("DamageLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0)
}
void RegisterBattleLibrary::RegisterLibrary(asIScriptEngine* engine) {

View File

@ -6,9 +6,6 @@ void RegisterExecutingAttack::Register(asIScriptEngine* engine) {
RegisterHitData(engine);
RegisterExecutingAttackType(engine);
}
BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::ExecutingAttack, CreatureLib::Battling::Creature, GetUser);
BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::ExecutingAttack, CreatureLib::Battling::LearnedAttack, GetAttack);
BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::ExecutingAttack, const CreatureLib::Library::AttackData, GetUseAttack);
static CreatureLib::Battling::ExecutingAttack::HitData*
GetHitDataWrapper(CreatureLib::Battling::ExecutingAttack* obj, CreatureLib::Battling::Creature* c, uint8_t hit) {
return &obj->GetHitData(c, hit);
@ -17,51 +14,38 @@ GetHitDataWrapper(CreatureLib::Battling::ExecutingAttack* obj, CreatureLib::Batt
void RegisterExecutingAttack::RegisterHitData(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("HitData", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "bool get_IsCritical() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, IsCritical),
asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint8 get_BasePower() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetBasePower),
asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "float get_Effectiveness() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness),
asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint get_Damage() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetDamage),
asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "uint8 get_Type() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, GetType),
asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("HitData", "bool get_HasFailed() const property",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, HasFailed),
asCALL_THISCALL);
Ensure(r >= 0);
REGISTER_GETTER("HitData", "bool get_IsCritical() const property", CreatureLib::Battling::ExecutingAttack::HitData,
IsCritical);
REGISTER_GETTER("HitData", "uint8 get_BasePower() const property", CreatureLib::Battling::ExecutingAttack::HitData,
GetBasePower);
REGISTER_GETTER("HitData", "float get_Effectiveness() const property",
CreatureLib::Battling::ExecutingAttack::HitData, GetEffectiveness);
REGISTER_GETTER("HitData", "uint get_Damage() const property", CreatureLib::Battling::ExecutingAttack::HitData,
GetDamage);
REGISTER_GETTER("HitData", "uint8 get_Type() const property", CreatureLib::Battling::ExecutingAttack::HitData,
GetType);
REGISTER_GETTER("HitData", "bool get_HasFailed() const property", CreatureLib::Battling::ExecutingAttack::HitData,
HasFailed);
r = engine->RegisterObjectMethod("HitData", "void Fail()",
asMETHOD(CreatureLib::Battling::ExecutingAttack::HitData, Fail), asCALL_THISCALL);
Ensure(r >= 0);
}
void RegisterExecutingAttack::RegisterExecutingAttackType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const",
asFUNCTION(GetHitDataWrapper), asCALL_CDECL_OBJFIRST);
Ensure(engine->RegisterObjectType("ExecutingMove", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
REGISTER_GETTER("ExecutingMove", "Pokemon@ get_User() const property", CreatureLib::Battling::ExecutingAttack,
GetUser);
REGISTER_GETTER("ExecutingMove", "LearnedMove@ get_Move() const property", CreatureLib::Battling::ExecutingAttack,
GetAttack);
REGISTER_GETTER("ExecutingMove", "MoveData@ get_UseMove() const property", CreatureLib::Battling::ExecutingAttack,
GetUseAttack);
auto r = engine->RegisterObjectMethod("ExecutingMove", "HitData@ GetHitData(Pokemon@ target, uint8 hit) const",
asFUNCTION(GetHitDataWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "bool IsPokemonTarget(Pokemon@ pkmn) const",
asMETHOD(CreatureLib::Battling::ExecutingAttack, IsCreatureTarget),
asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "Pokemon@ get_User() const property", asFUNCTION(GetUserWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "LearnedMove@ get_Move() const property",
asFUNCTION(GetAttackWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ExecutingMove", "MoveData@ get_UseMove() const property",
asFUNCTION(GetUseAttackWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
}

View File

@ -17,22 +17,18 @@ static PkmnLib::Battling::Pokemon* GetAtIndexWrapper(PkmnLib::Battling::PokemonP
}
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(engine->RegisterObjectType("Party", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
// GetParty() has both a const and a non const variant, so we need to explicitly mention its return type.
REGISTER_EXPLICIT_GETTER("Party", "const narray<Pokemon@>@ get_Pokemon() const property",
CreatureLib::Battling::CreatureParty, GetParty,
const ArbUt::OptionalUniquePtrList<CreatureLib::Battling::Creature>&);
auto r = engine->RegisterObjectMethod("Party", "Pokemon@ GetAtIndex(int index) const",
asFUNCTION(GetAtIndexWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
}
BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::BattleParty, CreatureLib::Battling::CreatureParty, GetParty);
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", asFUNCTION(GetPartyWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
Ensure(engine->RegisterObjectType("BattleParty", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
REGISTER_GETTER("BattleParty", "Party@ get_Party() const property", CreatureLib::Battling::BattleParty, GetParty);
}

View File

@ -39,41 +39,15 @@ void RegisterPokemonClass::RegisterMoveLearnMethod(asIScriptEngine* engine) {
Ensure(r >= 0);
}
ENUM__SIZE_WRAPPER(LearnedMove_LearnMethodWrapper, CreatureLib::Battling::LearnedAttack, GetLearnMethod)
BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::LearnedAttack, const CreatureLib::Library::AttackData, GetAttack);
void RegisterPokemonClass::RegisterLearnedAttack(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("LearnedMove", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "const MoveData@ get_MoveData() const property",
asFUNCTION(GetAttackWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_MaxUses() const property",
asMETHOD(CreatureLib::Battling::LearnedAttack, GetMaxUses), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "uint8 get_RemainingUses() const property",
asMETHOD(CreatureLib::Battling::LearnedAttack, GetRemainingUses), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("LearnedMove", "Gender get_LearnMethod() const property",
asFUNCTION(LearnedMove_LearnMethodWrapper), asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
REGISTER_GETTER("LearnedMove", "const MoveData@ get_MoveData() const property", CreatureLib::Battling::LearnedAttack, GetAttack);
REGISTER_GETTER("LearnedMove", "uint8 get_MaxUses() const property", CreatureLib::Battling::LearnedAttack, GetMaxUses);
REGISTER_GETTER("LearnedMove", "uint8 get_RemainingUses() const property", CreatureLib::Battling::LearnedAttack, GetRemainingUses);
REGISTER_GETTER("LearnedMove", "Gender get_LearnMethod() const property", CreatureLib::Battling::LearnedAttack, GetLearnMethod);
}
ENUM__SIZE_WRAPPER(Pkmn_GenderWrapper, PkmnLib::Battling::Pokemon, GetGender)
CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) {
asIScriptContext* ctx = asGetActiveContext();
if (ctx) {
auto a = obj->GetMoves();
auto ud = (AngelscriptUserdata*)ctx->GetUserData();
CScriptArray* arr = ud->CreateArray("array<LearnedMove@>"_cnc, a.Count());
for (size_t i = 0; i < a.Count(); i++) {
arr->SetValue(i, &a[i]);
}
return arr;
}
return nullptr;
}
static bool HasHeldItem(const PkmnLib::Battling::Pokemon* obj, const ArbUt::StringView& str) {
return obj->HasHeldItem(str.GetHash());
}
@ -97,7 +71,6 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const A
}
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
int r;
Ensure(engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
REGISTER_GETTER("Pokemon", "const Species@ get_Species() const property", CreatureLib::Battling::Creature,
GetSpecies);
@ -126,8 +99,10 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
GetBattleSide);
REGISTER_GETTER("Pokemon", "const constString& get_Status() const property", CreatureLib::Battling::Creature,
GetStatusName);
REGISTER_GETTER("Pokemon", "const narray<LearnedMove@>@ get_Moves() const property", PkmnLib::Battling::Pokemon,
GetMoves);
r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const",
auto r = engine->RegisterObjectMethod("Pokemon", "bool HasHeldItem(const constString &in name) const",
asFUNCTION(HasHeldItem), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void SetHeldItem(const constString &in name)",
@ -153,9 +128,6 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Pokemon", "void OverrideActiveAbility(const string &in ability)",
asMETHOD(PkmnLib::Battling::Pokemon, OverrideActiveTalent), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "LearnedMove@[]@ GetMoves() const", asFUNCTION(GetMoves),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "void ChangeStatBoost(Statistic stat, int8 amount)",
asMETHOD(PkmnLib::Battling::Pokemon, ChangeStatBoost), asCALL_THISCALL);
Ensure(r >= 0);

View File

@ -5,8 +5,6 @@
#include "../HelperFile.hpp"
#include "../RefCast.hpp"
BORROWED_PTR_GETTER_FUNC(CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::Creature, GetUser);
void RegisterTurnChoices::Register(asIScriptEngine* engine) {
RegisterTurnChoiceKindEnum(engine);
RegisterBaseTurnChoice(engine);
@ -14,47 +12,34 @@ void RegisterTurnChoices::Register(asIScriptEngine* engine) {
RegisterSwitchTurnChoice(engine);
RegisterFleeTurnChoice(engine);
}
void RegisterTurnChoices::RegisterTurnChoiceKindEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("TurnChoiceKind");
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Pass", (int)CreatureLib::Battling::TurnChoiceKind::Pass);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Attack", (int)CreatureLib::Battling::TurnChoiceKind::Attack);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Item", (int)CreatureLib::Battling::TurnChoiceKind::Item);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Switch", (int)CreatureLib::Battling::TurnChoiceKind::Switch);
Ensure(r >= 0);
r = engine->RegisterEnumValue("TurnChoiceKind", "Flee", (int)CreatureLib::Battling::TurnChoiceKind::Flee);
Ensure(r >= 0);
REGISTER_ENUM(CreatureLib::Battling::TurnChoiceKind, "TurnChoiceKind");
}
void RegisterTurnChoices::RegisterBaseTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("BaseTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::BaseTurnChoice, GetKind), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BaseTurnChoice", "const Pokemon@ get_User() const property",
asFUNCTION(GetUserWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
Ensure(engine->RegisterObjectType("BaseTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT) >= 0);
REGISTER_EXPLICIT_GETTER("BaseTurnChoice", "TurnChoiceKind get_Kind() const property",
CreatureLib::Battling::BaseTurnChoice, GetKind, CreatureLib::Battling::TurnChoiceKind);
REGISTER_EXPLICIT_GETTER("BaseTurnChoice", "const Pokemon@ get_User() const property",
CreatureLib::Battling::BaseTurnChoice, GetUser,
const ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>&);
}
void RegisterTurnChoices::RegisterMoveTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetKind), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "Pokemon@ get_User() const property", asFUNCTION(GetUserWrapper),
asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "LearnedMove@ get_Move() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetAttack), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveTurnChoice", "int8 get_Priority() const property",
asMETHOD(CreatureLib::Battling::AttackTurnChoice, GetPriority), asCALL_THISCALL);
int r = engine->RegisterObjectType("MoveTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
REGISTER_GETTER("MoveTurnChoice", "TurnChoiceKind get_Kind() const property",
CreatureLib::Battling::AttackTurnChoice, GetKind);
REGISTER_EXPLICIT_GETTER("MoveTurnChoice", "Pokemon@ get_User() const property",
CreatureLib::Battling::BaseTurnChoice, GetUser,
const ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>&);
REGISTER_GETTER("MoveTurnChoice", "LearnedMove@ get_Move() const property",
CreatureLib::Battling::AttackTurnChoice, GetAttack);
REGISTER_GETTER("MoveTurnChoice", "int8 get_Priority() const property",
CreatureLib::Battling::AttackTurnChoice, GetPriority);
r = engine->RegisterObjectMethod(
"BaseTurnChoice", "MoveTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::AttackTurnChoice>)),
@ -68,19 +53,15 @@ void RegisterTurnChoices::RegisterMoveTurnChoice(asIScriptEngine* engine) {
}
void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("SwitchTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetKind), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "const Pokemon@ get_User() const property",
asFUNCTION(GetUserWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property",
asMETHOD(CreatureLib::Battling::SwitchTurnChoice, GetNewCreature),
asCALL_THISCALL);
int r = engine->RegisterObjectType("SwitchTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
REGISTER_GETTER("SwitchTurnChoice", "TurnChoiceKind get_Kind() const property", CreatureLib::Battling::SwitchTurnChoice, GetKind);
REGISTER_EXPLICIT_GETTER("SwitchTurnChoice", "const Pokemon@ get_User() const property",
CreatureLib::Battling::BaseTurnChoice, GetUser,
const ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>&);
REGISTER_GETTER("SwitchTurnChoice", "Pokemon@ get_NewPokemon() const property", CreatureLib::Battling::SwitchTurnChoice, GetNewCreature);
r = engine->RegisterObjectMethod(
"BaseTurnChoice", "SwitchTurnChoice@ opCast()",
asFUNCTION((refCast<CreatureLib::Battling::BaseTurnChoice, CreatureLib::Battling::SwitchTurnChoice>)),
@ -93,14 +74,12 @@ void RegisterTurnChoices::RegisterSwitchTurnChoice(asIScriptEngine* engine) {
Ensure(r >= 0);
}
void RegisterTurnChoices::RegisterFleeTurnChoice(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("FleeTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("FleeTurnChoice", "TurnChoiceKind get_Kind() const property",
asMETHOD(CreatureLib::Battling::FleeTurnChoice, GetKind), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("FleeTurnChoice", "const Pokemon@ get_User() const property",
asFUNCTION(GetUserWrapper), asCALL_CDECL_OBJFIRST);
int r = engine->RegisterObjectType("FleeTurnChoice", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
REGISTER_GETTER("FleeTurnChoice", "TurnChoiceKind get_Kind() const property", CreatureLib::Battling::FleeTurnChoice, GetKind);
REGISTER_EXPLICIT_GETTER("FleeTurnChoice", "const Pokemon@ get_User() const property",
CreatureLib::Battling::BaseTurnChoice, GetUser,
const ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>&);
r = engine->RegisterObjectMethod(
"BaseTurnChoice", "FleeTurnChoice@ opCast()",

View File

@ -1,3 +1,7 @@
#ifndef PKMNLIB_HELPERFILE_HPP
#define PKMNLIB_HELPERFILE_HPP
#include "NativeArray.hpp"
#define BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
static returns* funcName##Wrapper(o* obj) { return obj->funcName().GetRaw(); }
#define OPTIONAL_BORROWED_PTR_GETTER_FUNC(o, returns, funcName) \
@ -27,72 +31,65 @@ 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 {};
#define __GETTER \
if constexpr (std::is_enum<R>()) { \
auto l = [](T* p) { return (i32)(p->*Method)(); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), i32), asCALL_CDECL_OBJFIRST) >= 0); \
} else if constexpr (is_specialization<R, ArbUt::BorrowedPtr>::value) { \
auto l = [](T* p) { return (void*)(p->*Method)().GetRaw(); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0); \
} else if constexpr (is_specialization<R, std::unique_ptr>::value) { \
auto l = [](T* p) { return (void*)(p->*Method)().get(); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0); \
} else if constexpr (is_specialization<R, ArbUt::OptionalBorrowedPtr>::value) { \
auto l = [](T* p) { \
auto v = (p->*Method)(); \
if (v.HasValue()) { \
return (void*)v.GetValue(); \
} \
return (void*)nullptr; \
}; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0); \
} else if constexpr (is_specialization<R, ArbUt::List>::value) { \
using base_type = typename std::remove_cv<typename std::remove_reference<R>::type>::type; \
auto l = [](T* p) { return (void*)new NativeArray<base_type>(&((p->*Method)())); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0); \
} else if constexpr (is_specialization<R, ArbUt::UniquePtrList>::value) { \
using base_type = typename std::remove_cv<typename std::remove_reference<R>::type>::type; \
auto l = [](T* p) { return (void*)new NativeArray<base_type>(&((p->*Method)())); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0); \
} else if constexpr (is_specialization<R, ArbUt::OptionalUniquePtrList>::value) { \
using base_type = typename std::remove_cv<typename std::remove_reference<R>::type>::type; \
auto l = [](T* p) { return (void*)new NativeArray<base_type>(&((p->*Method)())); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0); \
} else if constexpr (std::is_reference<R>::value) { \
static_assert(!std::is_enum<R>()); \
static_assert(!is_specialization<R, ArbUt::List>::value); \
static_assert(!is_specialization<R, ArbUt::UniquePtrList>::value); \
auto l = [](T* p) { return (void*)&(p->*Method)(); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0); \
} else { \
static_assert(!std::is_enum<R>()); \
static_assert(!is_specialization<R, ArbUt::List>::value); \
static_assert(!is_specialization<R, ArbUt::UniquePtrList>::value); \
auto l = [](T* p) { return (p->*Method)(); }; \
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), R), asCALL_CDECL_OBJFIRST) >= 0); \
}
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);
}
__GETTER
}
template <typename T, typename R, R (T::*Method)()>
void RegisterGetter(asIScriptEngine* engine, const char* asType, const char* asDef) {
if constexpr (std::is_enum<R>()) {
auto l = [](T* p) { return (i32)(p->*Method)(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), i32), asCALL_CDECL_OBJFIRST) >= 0);
} else if constexpr (is_specialization<R, ArbUt::BorrowedPtr>::value) {
auto l = [](T* p) { return (void*)(p->*Method)().GetRaw(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0);
} else if constexpr (is_specialization<R, std::unique_ptr>::value) {
auto l = [](T* p) { return (void*)(p->*Method)().get(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (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, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0);
} else if constexpr (std::is_reference<R>::value) {
static_assert(!std::is_enum<R>());
auto l = [](T* p) { return (void*)&(p->*Method)(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), void*), asCALL_CDECL_OBJFIRST) >= 0);
} else {
static_assert(!std::is_enum<R>());
auto l = [](T* p) { return (p->*Method)(); };
Ensure(engine->RegisterObjectMethod(asType, asDef, asFUNCTIONPR(l, (T*), R), asCALL_CDECL_OBJFIRST) >= 0);
}
__GETTER
}
#define REGISTER_GETTER(asType, asDef, cType, cFunc) \
RegisterGetter<cType, std::result_of<decltype (&cType::cFunc)(cType)>::type, &cType::cFunc>(engine, asType, asDef);
#define REGISTER_EXPLICIT_GETTER(asType, asDef, cType, cFunc, returnType) \
RegisterGetter<cType, returnType, &cType::cFunc>(engine, asType, asDef);
#endif

View File

@ -1,6 +1,7 @@
#include "RegisterItemTypes.hpp"
#include "../../../../Library/Items/Item.hpp"
#include "../../../../Library/Items/ItemLibrary.hpp"
#include "../HelperFile.hpp"
void RegisterItemTypes::Register(asIScriptEngine* engine) {
RegisterItemCategoryEnum(engine);
@ -11,77 +12,65 @@ void RegisterItemTypes::Register(asIScriptEngine* engine) {
void RegisterItemTypes::RegisterItemCategoryEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("ItemCategory");
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "Misc", (int)CreatureLib::Library::ItemCategory::MiscItem);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "Pokeball", (int)CreatureLib::Library::ItemCategory::CaptureDevice);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "Medicine", (int)CreatureLib::Library::ItemCategory::Medicine);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "Berry", (int)CreatureLib::Library::ItemCategory::Berry);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "TM", (int)CreatureLib::Library::ItemCategory::MoveLearner);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "VariantChanger",
(int)CreatureLib::Library::ItemCategory::VariantChanger);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "KeyItem", (int)CreatureLib::Library::ItemCategory::KeyItem);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("ItemCategory", "Mail", (int)CreatureLib::Library::ItemCategory::Mail);
assert(r >= 0);
Ensure(r >= 0);
}
void RegisterItemTypes::RegisterBattleItemCategoryEnum(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterEnum("BattleItemCategory");
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "None", (int)CreatureLib::Library::BattleItemCategory::None);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "Healing",
(int)CreatureLib::Library::BattleItemCategory::Healing);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "StatusHealing",
(int)CreatureLib::Library::BattleItemCategory::StatusHealing);
assert(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "CaptureDevice",
Ensure(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "Pokeball",
(int)CreatureLib::Library::BattleItemCategory::CaptureDevice);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterEnumValue("BattleItemCategory", "Misc",
(int)CreatureLib::Library::BattleItemCategory::MiscBattleItem);
assert(r >= 0);
Ensure(r >= 0);
}
// 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) \
int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); }
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::Item, GetCategory)
ENUM__SIZE_WRAPPER(Move_BattleCategoryWrapper, PkmnLib::Library::Item, GetBattleCategory)
static bool HasFlag(const PkmnLib::Library::Item* obj, const ArbUt::BasicStringView& str) { return obj->HasFlag(str); }
void RegisterItemTypes::RegisterItemType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::Item, GetName), asCALL_THISCALL);
assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "ItemCategory get_Category() const property",
asFUNCTION(Move_CategoryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "BattleItemCategory get_BattleCategory() const property",
asFUNCTION(Move_BattleCategoryWrapper), asCALL_CDECL_OBJLAST);
assert(r >= 0);
r = engine->RegisterObjectMethod("Item", "int get_Price() const property",
asMETHOD(PkmnLib::Library::Item, GetPrice), asCALL_THISCALL);
assert(r >= 0);
int r = engine->RegisterObjectType("Item", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
REGISTER_GETTER("Item", "const constString& get_Name() const property", CreatureLib::Library::Item, GetName);
REGISTER_GETTER("Item", "ItemCategory get_Category() const property", CreatureLib::Library::Item, GetCategory);
REGISTER_GETTER("Item", "BattleItemCategory get_BattleCategory() const property", CreatureLib::Library::Item,
GetBattleCategory);
REGISTER_GETTER("Item", "int get_Price() const property", CreatureLib::Library::Item, GetPrice);
r = engine->RegisterObjectMethod("Item", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
asCALL_CDECL_OBJLAST);
assert(r >= 0);
Ensure(r >= 0);
}
void RegisterItemTypes::RegisterItemLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("ItemLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
assert(r >= 0);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("ItemLibrary", "const Item@ Get(const constString &in name) const",
asMETHOD(PkmnLib::Library::ItemLibrary, Get), asCALL_THISCALL);
assert(r >= 0);
Ensure(r >= 0);
}

View File

@ -18,50 +18,32 @@ void RegisterMoveTypes::RegisterMoveTarget(asIScriptEngine* engine) {
REGISTER_ENUM(CreatureLib::Library::AttackTarget, "MoveTarget");
}
// 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) \
int32_t name(type* obj) { return static_cast<int32_t>(obj->func()); }
ENUM__SIZE_WRAPPER(Move_CategoryWrapper, PkmnLib::Library::MoveData, GetCategory)
ENUM__SIZE_WRAPPER(Move_TargetWrapper, PkmnLib::Library::MoveData, GetTarget)
static bool HasFlag(const PkmnLib::Library::MoveData* obj, const ArbUt::BasicStringView& str) {
return obj->HasFlag(str);
}
void RegisterMoveTypes::RegisterMoveType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveData", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::MoveData, GetName), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Type() const property",
asMETHOD(PkmnLib::Library::MoveData, GetType), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "MoveCategory get_Category() const property",
asFUNCTION(Move_CategoryWrapper), asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BasePower() const property",
asMETHOD(PkmnLib::Library::MoveData, GetBasePower), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_Accuracy() const property",
asMETHOD(PkmnLib::Library::MoveData, GetAccuracy), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "uint8 get_BaseUsages() const property",
asMETHOD(PkmnLib::Library::MoveData, GetBaseUsages), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "MoveTarget get_Target() const property",
asFUNCTION(Move_TargetWrapper), asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveData", "int8 get_Priority() const property",
asMETHOD(PkmnLib::Library::MoveData, GetPriority), asCALL_THISCALL);
int r = engine->RegisterObjectType("MoveData", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
REGISTER_GETTER("MoveData", "const constString& get_Name() const property", CreatureLib::Library::AttackData,
GetName);
REGISTER_GETTER("MoveData", "uint8 get_Type() const property", CreatureLib::Library::AttackData, GetType);
REGISTER_GETTER("MoveData", "MoveCategory get_Category() const property", CreatureLib::Library::AttackData,
GetCategory);
REGISTER_GETTER("MoveData", "uint8 get_BasePower() const property", CreatureLib::Library::AttackData, GetBasePower);
REGISTER_GETTER("MoveData", "uint8 get_Accuracy() const property", CreatureLib::Library::AttackData, GetAccuracy);
REGISTER_GETTER("MoveData", "uint8 get_BaseUsages() const property", CreatureLib::Library::AttackData,
GetBaseUsages);
REGISTER_GETTER("MoveData", "MoveTarget get_Target() const property", CreatureLib::Library::AttackData, GetTarget);
REGISTER_GETTER("MoveData", "int8 get_Priority() const property", CreatureLib::Library::AttackData, GetPriority);
r = engine->RegisterObjectMethod("MoveData", "bool HasFlag(const constString &in flag) const", asFUNCTION(HasFlag),
asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
}
void RegisterMoveTypes::RegisterMoveLibrary(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("MoveLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
int r = engine->RegisterObjectType("MoveLibrary", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("MoveLibrary", "const MoveData@ Get(const constString &in name) const",
asMETHOD(PkmnLib::Library::MoveLibrary, Get), asCALL_THISCALL);

View File

@ -14,14 +14,7 @@ void RegisterSpeciesTypes::Register(asIScriptEngine* engine) {
}
void RegisterSpeciesTypes::RegisterGenderEnum(asIScriptEngine* engine) {
int r = engine->RegisterEnum("Gender");
Ensure(r >= 0);
r = engine->RegisterEnumValue("Gender", "Male", (int)CreatureLib::Library::Gender::Male);
Ensure(r >= 0);
r = engine->RegisterEnumValue("Gender", "Female", (int)CreatureLib::Library::Gender::Female);
Ensure(r >= 0);
r = engine->RegisterEnumValue("Gender", "Genderless", (int)CreatureLib::Library::Gender::Genderless);
Ensure(r >= 0);
REGISTER_ENUM(CreatureLib::Library::Gender, "Gender");
}
void RegisterSpeciesTypes::RegisterStatisticEnum(asIScriptEngine* engine) {
@ -47,32 +40,22 @@ static const PkmnLib::Library::PokemonForme* GetFormeWrapper(const std::string&
.As<const PkmnLib::Library::PokemonForme>()
.GetRaw();
}
BORROWED_PTR_GETTER_FUNC(PkmnLib::Library::PokemonSpecies, const PkmnLib::Library::PokemonForme, GetDefaultForme);
void RegisterSpeciesTypes::RegisterSpeciesType(asIScriptEngine* engine) {
int r = engine->RegisterObjectType("Species", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Species", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetName), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Species", "uint16 get_Id() const property",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetId), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Species", "float get_GenderRate() const property",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetGenderRate), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Species", "uint8 get_CaptureRate() const property",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetCaptureRate), asCALL_THISCALL);
Ensure(r >= 0);
REGISTER_GETTER("Species", "const constString& get_Name() const property", CreatureLib::Library::CreatureSpecies, GetName);
REGISTER_GETTER("Species", "uint16 get_Id() const property", CreatureLib::Library::CreatureSpecies, GetId);
REGISTER_GETTER("Species", "float get_GenderRate() const property", CreatureLib::Library::CreatureSpecies, GetGenderRate);
REGISTER_GETTER("Species", "uint8 get_CaptureRate() const property", CreatureLib::Library::CreatureSpecies, GetCaptureRate);
REGISTER_GETTER("Species", "const Forme@ get_DefaultForme() const property", PkmnLib::Library::PokemonSpecies, GetDefaultForme);
r = engine->RegisterObjectMethod("Species", "Gender GetRandomGender() const",
asMETHOD(PkmnLib::Library::PokemonSpecies, GetRandomGender), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Species", "const Forme@ GetForme(string key) const", asFUNCTION(GetFormeWrapper),
asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Species", "const Forme@ get_DefaultForme() const property",
asFUNCTION(GetDefaultFormeWrapper), asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
}
const ArbUt::StringView& GetAbility(PkmnLib::Library::PokemonForme* p, bool hidden, uint8_t index) {
@ -82,21 +65,12 @@ const ArbUt::StringView& GetAbility(PkmnLib::Library::PokemonForme* p, bool hidd
void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
int r = engine->RegisterObjectType("Forme", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Forme", "const constString& get_Name() const property",
asMETHOD(PkmnLib::Library::PokemonForme, GetName), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Forme", "float get_Weight() const property",
asMETHOD(PkmnLib::Library::PokemonForme, GetWeight), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Forme", "float get_Height() const property",
asMETHOD(PkmnLib::Library::PokemonForme, GetHeight), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Forme", "uint get_BaseExperience() const property",
asMETHOD(PkmnLib::Library::PokemonForme, GetBaseExperience), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Forme", "int get_TypeCount() const property",
asMETHOD(PkmnLib::Library::PokemonForme, GetTypeCount), asCALL_THISCALL);
Ensure(r >= 0);
REGISTER_GETTER("Forme", "const constString& get_Name() const property", CreatureLib::Library::SpeciesVariant, GetName);
REGISTER_GETTER("Forme", "float get_Weight() const property", CreatureLib::Library::SpeciesVariant, GetWeight);
REGISTER_GETTER("Forme", "float get_Height() const property", CreatureLib::Library::SpeciesVariant, GetHeight);
REGISTER_GETTER("Forme", "uint get_BaseExperience() const property", CreatureLib::Library::SpeciesVariant, GetBaseExperience);
REGISTER_GETTER("Forme", "int get_TypeCount() const property", CreatureLib::Library::SpeciesVariant, GetTypeCount);
r = engine->RegisterObjectMethod("Forme", "uint8 GetType(int index) const",
asMETHOD(PkmnLib::Library::PokemonForme, GetType), asCALL_THISCALL);
Ensure(r >= 0);
@ -113,21 +87,21 @@ void RegisterSpeciesTypes::RegisterFormeType(asIScriptEngine* engine) {
ENUM__SIZE_WRAPPER(EvolutionData_GetMethodWrapper, PkmnLib::Library::EvolutionData, GetMethod);
void RegisterSpeciesTypes::RegisterEvolutionData(asIScriptEngine* engine) {
REGISTER_ENUM(PkmnLib::Library::EvolutionMethod, "EvolutionMethod");
int r = engine->RegisterObjectType("EvolutionData", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("EvolutionData", "const Species& get_NewSpecies() const property",
asMETHOD(PkmnLib::Library::EvolutionData, GetNewSpecies), asCALL_THISCALL);
Ensure(r >= 0);
REGISTER_ENUM(PkmnLib::Library::EvolutionMethod, "EvolutionMethod");
r = engine->RegisterObjectMethod("EvolutionData", "EvolutionMethod get_Method() const property",
asFUNCTION(EvolutionData_GetMethodWrapper), asCALL_CDECL_OBJLAST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("EvolutionData", "uint64 get_DataCount() const property",
asMETHOD(PkmnLib::Library::EvolutionData, GetDataCount), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("EvolutionData", "EffectParameter@ GetData(uint64 index) const",
asMETHOD(PkmnLib::Library::EvolutionData, GetData), asCALL_THISCALL);
REGISTER_GETTER("EvolutionData", "const Species& get_NewSpecies() const property", PkmnLib::Library::EvolutionData, GetNewSpecies);
REGISTER_GETTER("EvolutionData", "EvolutionMethod get_Method() const property", PkmnLib::Library::EvolutionData, GetMethod);
REGISTER_GETTER("EvolutionData", "uint64 get_DataCount() const property", PkmnLib::Library::EvolutionData, GetDataCount);
REGISTER_GETTER("EvolutionData", "const narray<EffectParameter@>@ get_Data() const property", PkmnLib::Library::EvolutionData, GetData);
r = engine->RegisterObjectMethod("EvolutionData", "EffectParameter@ GetDataAt(uint64 index) const",
asMETHOD(PkmnLib::Library::EvolutionData, GetDataAt), asCALL_THISCALL);
Ensure(r >= 0);
}
void RegisterSpeciesTypes::RegisterSpeciesLibrary(asIScriptEngine* engine) {

View File

@ -0,0 +1 @@
#include "NativeArray.hpp"

View File

@ -0,0 +1,47 @@
#ifndef PKMNLIB_NATIVEARRAY_HPP
#define PKMNLIB_NATIVEARRAY_HPP
#include <angelscript.h>
#include <atomic>
template <typename T> class NativeArray {
private:
const T* _array;
std::atomic<ulong> _refCount;
void AddRef() {
_refCount++;
}
void Release() {
if (--_refCount <= 0){
delete this;
}
}
~NativeArray() = default;
public:
explicit NativeArray(const T* array) : _array(array), _refCount(1) {}
size_t Length() const { return _array->Count(); }
[[nodiscard]] void* At(size_t index) { return _array->At(index).GetRaw(); }
static void Register(asIScriptEngine* engine) {
Ensure(engine->RegisterObjectType("narray<class T>", sizeof(NativeArray),
asOBJ_REF | asOBJ_TEMPLATE) >= 0);
Ensure(engine->RegisterObjectBehaviour("narray<T>", asBEHAVE_ADDREF, "void f()",
asMETHOD(NativeArray, AddRef), asCALL_THISCALL));
Ensure(engine->RegisterObjectBehaviour("narray<T>", asBEHAVE_RELEASE, "void f()",
asMETHOD(NativeArray, Release), asCALL_THISCALL));
Ensure(engine->RegisterObjectMethod("narray<T>", "uint64 Length() const", asMETHOD(NativeArray, Length),
asCALL_THISCALL) >= 0);
Ensure(engine->RegisterObjectMethod("narray<T>", "const T@ At(uint64 index) const", asMETHOD(NativeArray, At),
asCALL_THISCALL) >= 0);
Ensure(engine->RegisterObjectMethod("narray<T>", "const T@ get_opIndex(uint64 index) const property", asMETHOD(NativeArray, At),
asCALL_THISCALL) >= 0);
}
};
#endif // PKMNLIB_NATIVEARRAY_HPP

View File

@ -147,8 +147,8 @@ TEST_CASE("Able to set and get evolution") {
auto evo = evolutions[0];
CHECK(evo->GetMethod() == PkmnLib::Library::EvolutionMethod::Level);
CHECK(evo->GetNewSpecies() == species2);
INFO(CreatureLib::Library::EffectParameterTypeHelper::ToString(evo->GetData(0)->GetType()));
CHECK(evo->GetData(0)->AsInt() == 16);
INFO(CreatureLib::Library::EffectParameterTypeHelper::ToString(evo->GetDataAt(0)->GetType()));
CHECK(evo->GetDataAt(0)->AsInt() == 16);
delete species;
delete species2;

View File

@ -14,7 +14,7 @@ static std::unordered_map<const char*, const char*> _scripts = std::unordered_ma
bool boolValue = false;
int64 intValue = 0;
constString stringValue;
void OnInitialize(const array<EffectParameter@> &in parameters) override {
void OnInitialize(const narray<EffectParameter@>@ parameters) override {
boolValue = parameters[0].AsBool();
intValue = parameters[1].AsInt();
stringValue = parameters[2].AsString();

View File

@ -19,7 +19,7 @@ class testScript1 : PkmnScript {
}
}
void OnInitialize(const array<EffectParameter@> &in parameters) override{ }
void OnInitialize(const narray<EffectParameter@>@ parameters) override{ }
}
}
)"}};

View File

@ -12,6 +12,10 @@ namespace Pokemon{
[Pokemon effect=testScript1]
class testScript1 : PkmnScript {
bool testGetPokemonIndex(BattleSide@ b, const Pokemon@ pokemon){ return b.GetPokemonIndex(pokemon) == 0; }
bool testGetSides(BattleSide@ a, BattleSide@ b, Battle@ battle) {
return battle.Sides.At(0) is a;
}
}}
)"}};
@ -59,25 +63,38 @@ TEST_CASE("Validate Battle Side GetPokemonIndex") {
auto mon = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).Build();
auto mon2 = PkmnLib::Battling::CreatePokemon(mainLib, "testSpecies"_cnc, 30).Build();
auto userParty = new CreatureLib::Battling::CreatureParty({mon});
auto targetParty = new CreatureLib::Battling::CreatureParty({mon2});
auto battle = new PkmnLib::Battling::Battle(
auto userParty = CreatureLib::Battling::CreatureParty({mon});
auto targetParty = CreatureLib::Battling::CreatureParty({mon2});
auto battle = PkmnLib::Battling::Battle(
mainLib, {
new CreatureLib::Battling::BattleParty(userParty, {CreatureLib::Battling::CreatureIndex(0, 0)}),
new CreatureLib::Battling::BattleParty(targetParty, {CreatureLib::Battling::CreatureIndex(1, 0)}),
new CreatureLib::Battling::BattleParty(&userParty, {CreatureLib::Battling::CreatureIndex(0, 0)}),
new CreatureLib::Battling::BattleParty(&targetParty, {CreatureLib::Battling::CreatureIndex(1, 0)}),
});
battle->SwitchCreature(0, 0, mon);
battle->SwitchCreature(1, 0, mon2);
battle.SwitchCreature(0, 0, mon);
battle.SwitchCreature(1, 0, mon2);
auto data = GetScript(mainLib, "testGetPokemonIndex"_cnc);
data.Context->SetArgObject(0, battle->GetSides()[0]);
data.Context->SetArgObject(0, battle.GetSides()[0]);
data.Context->SetArgObject(1, mon);
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)data.Context->GetReturnWord());
delete mon;
delete mon2;
}
TEST_CASE("Validate Battle GetBattleSides") {
auto mainLib = TestLibrary::GetLibrary();
auto battle = new PkmnLib::Battling::Battle(mainLib, {});
auto data = GetScript(mainLib, "testGetSides"_cnc);
data.Context->SetArgObject(0, battle->GetSides()[0].GetRaw());
data.Context->SetArgObject(1, battle->GetSides()[1].GetRaw());
data.Context->SetArgObject(2, battle);
REQUIRE(data.Context->Execute() == asEXECUTION_FINISHED);
REQUIRE((bool)data.Context->GetReturnWord());
delete battle;
}
#endif

View File

@ -24,7 +24,7 @@ class testScript1 : PkmnScript {
bool testHasType(Pokemon@ p, uint8 type){ return p.HasType(type); }
void testDamage(Pokemon@ p, uint32 damage, DamageSource source){ p.Damage(damage, source); }
void testHeal(Pokemon@ p, uint32 amount){ p.Heal(amount); }
bool testMove(Pokemon@ p, uint index, LearnedMove@ move){ return p.GetMoves()[index] is move; }
bool testMove(Pokemon@ p, uint index, LearnedMove@ move){ return p.Moves[index] is move; }
bool testHasHeldItem(Pokemon@ p, const constString &in item){ return p.HasHeldItem(item); }
void testSetHeldItem(Pokemon@ p, const constString &in item){ p.SetHeldItem(item); }
void testSetHeldItem2(Pokemon@ p){ p.SetHeldItem("testItem"); }