Adds some more Angelscript functionality for the BattleSide.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-03-26 23:05:51 +01:00
parent 41475fcb2f
commit bee9170603
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
3 changed files with 26 additions and 11 deletions

View File

@ -91,7 +91,6 @@ void AngelScriptResolver::Initialize(CreatureLib::Battling::BattleLibrary* arg,
_contextPool = new ContextPool(_engine);
}
OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, CreatureLib::Battling::Battle, GetBattle);
void AngelScriptResolver::RegisterTypes() {
// Register static library types
@ -104,14 +103,17 @@ void AngelScriptResolver::RegisterTypes() {
RegisterEffectParameter::Register(_engine);
// Register battle types
// Predeclare these two types, and declare their implementation later.
[[maybe_unused]] int r = _engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = _engine->RegisterObjectType("BattleSide", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
RegisterPokemonClass::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",
asFUNCTION(GetBattleWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
// Register base script
BasicScriptClass::Register(_engine);

View File

@ -51,19 +51,23 @@ CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battl
}
void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
int r = engine->RegisterObjectType("BattleSide", 0, asOBJ_REF | asOBJ_NOCOUNT);
int r = engine->RegisterObjectMethod(
"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", "bool SwapPositions(uint8 a, uint8 b)",
asMETHODPR(CreatureLib::Battling::BattleSide, SwapPositions, (u8 a, u8 b), bool),
r = engine->RegisterObjectMethod("BattleSide", "uint8 get_SideIndex() const property",
asMETHOD(CreatureLib::Battling::BattleSide, GetSideIndex), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleSide", "uint8 GetPokemonIndex(const Pokemon@ pokemon) const",
asMETHODPR(CreatureLib::Battling::BattleSide, GetCreatureIndex,
(const ArbUt::BorrowedPtr<CreatureLib::Battling::Creature>& c), u8),
asCALL_THISCALL);
Ensure(r >= 0);
}
void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Battle", 0, asOBJ_REF | asOBJ_NOCOUNT);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property",
asMETHOD(PkmnLib::Battling::Battle, GetLibrary), asCALL_THISCALL);
int r = engine->RegisterObjectMethod("Battle", "const BattleLibrary@ get_Library() const property",
asMETHOD(PkmnLib::Battling::Battle, GetLibrary), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);

View File

@ -84,6 +84,8 @@ static std::string NicknameWrapper(const PkmnLib::Battling::Pokemon* obj) { retu
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(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);
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
@ -184,4 +186,11 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
asMETHODPR(PkmnLib::Battling::Pokemon, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const Battle@ get_Battle() const property",
asFUNCTION(GetBattleWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Pokemon", "const BattleSide@ get_BattleSide() const property",
asFUNCTION(GetBattleSideWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
}