Adds Angelscript functions for getting a volatile script from a Battle or BattleSide.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2021-10-30 16:35:23 +02:00
parent 86ffe00b20
commit 6cc4206292
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 31 additions and 0 deletions

View File

@ -75,6 +75,18 @@ static CScriptHandle Battle_AddVolatileWrapper(PkmnLib::Battling::Battle* obj, c
return handle;
}
static CScriptHandle Battle_GetVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
auto* s = static_cast<AngelScriptScript*>(obj->GetVolatileScript(name).GetValue());
if (s == nullptr) {
return handle;
}
auto* script = s->GetRawAngelscriptObject();
handle.Set(script, resolver->GetBaseType("PkmnScript"));
return handle;
}
static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::BattleSide* obj,
const ArbUt::StringView& name) {
auto handle = CScriptHandle();
@ -84,6 +96,19 @@ static CScriptHandle BattleSide_AddVolatileWrapper(CreatureLib::Battling::Battle
return handle;
}
static CScriptHandle BattleSide_GetVolatileWrapper(CreatureLib::Battling::BattleSide* obj,
const ArbUt::StringView& name) {
auto handle = CScriptHandle();
auto* resolver = static_cast<AngelScriptResolver*>(obj->GetBattle()->GetLibrary()->GetScriptResolver().get());
auto* s = static_cast<AngelScriptScript*>(obj->GetVolatileScript(name).GetValue());
if (s == nullptr) {
return handle;
}
auto* script = s->GetRawAngelscriptObject();
handle.Set(script, resolver->GetBaseType("PkmnScript"));
return handle;
}
static bool Battle_HasVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
return obj->HasVolatileScript(name);
}
@ -122,6 +147,9 @@ void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("BattleSide", "ref@ AddVolatile(const constString &in name)",
asFUNCTION(BattleSide_AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("BattleSide", "ref@ GetVolatile(const constString &in name)",
asFUNCTION(BattleSide_GetVolatileWrapper), 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),
@ -154,6 +182,9 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)",
asFUNCTION(Battle_AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod("Battle", "ref@ GetVolatile(const constString &in name)",
asFUNCTION(Battle_GetVolatileWrapper), asCALL_CDECL_OBJFIRST);
Ensure(r >= 0);
r = engine->RegisterObjectMethod(
"Battle", "void RemoveVolatile(const constString &in name) const",
asMETHODPR(PkmnLib::Battling::Battle, RemoveVolatileScript, (const ArbUt::BasicStringView&), void),