Adds Angelscript functions for setting volatile scripts on a battleside.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-10-28 16:27:59 +02:00
parent f5032bebb1
commit 3d75e8233d
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 25 additions and 4 deletions

View File

@ -67,7 +67,7 @@ CreatureLib::Battling::BattleParty* FindPartyWrapper(PkmnLib::Battling::Battle*
return {};
}
static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
@ -75,6 +75,15 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const Ar
return handle;
}
static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::BattleSide* obj,
const ArbUt::StringView& name) {
auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get());
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
handle.Set(script, resolver->GetBaseType("PkmnScript"));
return handle;
}
static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* obj, PkmnLib::Battling::Pokemon* pokemon) {
return obj->GetCreatureIndex(pokemon);
}
@ -91,6 +100,10 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
REGISTER_GETTER("BattleSide", "uint8 get_SideIndex() const property", CreatureLib::Battling::BattleSide,
GetSideIndex);
REGISTER_GETTER("BattleSide", "bool get_IsDefeated() const property", CreatureLib::Battling::BattleSide,
IsDefeated);
REGISTER_GETTER("BattleSide", "bool get_HasFled() const property", CreatureLib::Battling::BattleSide, HasFled);
REGISTER_GETTER("BattleSide", "Battle@ get_Battle() const property", CreatureLib::Battling::BattleSide, GetBattle);
r = engine->RegisterObjectMethod("BattleSide", "uint8 GetPokemonIndex(const Pokemon@ pokemon) const",
asFUNCTION(GetPokemonIndexWrapper), asCALL_CDECL_OBJFIRST);
@ -98,6 +111,15 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("BattleSide", "Pokemon@ GetPokemon(uint8 index) const",
asFUNCTION(GetPokemonWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleSide", "ref@ AddVolatile(const constString &in name)",
asFUNCTION(BattleSide_AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"BattleSide", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(CreatureLib::Battling::BattleSide, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),
asCALL_THISCALL);
Ensure(r >= 0);
}
void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
@ -112,14 +134,13 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
GetSides);
REGISTER_GETTER("Battle", "narray<BattleParty>@ get_Parties() const property", CreatureLib::Battling::Battle,
GetParties);
REGISTER_GETTER("Battle", "BattleHistory@ get_History() const property", CreatureLib::Battling::Battle,
GetHistory);
REGISTER_GETTER("Battle", "BattleHistory@ get_History() const property", CreatureLib::Battling::Battle, GetHistory);
auto r = engine->RegisterObjectMethod("Battle", "bool CanUse(BaseTurnChoice@ choice)",
asMETHOD(PkmnLib::Battling::Battle, CanUse), asCALL_THISCALL);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)",
asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
asFUNCTION(Battle_AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void RemoveVolatile(const constString &in name) const",