Adds support for modifying volatile scripts after adding them.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -31,6 +31,7 @@ public:
|
||||
} else {
|
||||
ctx->PopState();
|
||||
}
|
||||
printf("%s\n", err.str().c_str());
|
||||
throw ArbUt::Exception(err.str());
|
||||
}
|
||||
if (newContext) {
|
||||
|
||||
@@ -32,7 +32,10 @@ static void TranslateException(asIScriptContext* ctx, void* /*userParam*/) {
|
||||
try {
|
||||
// Retrow the original exception so we can catch it again
|
||||
throw;
|
||||
} catch (std::exception& e) {
|
||||
} catch (ArbUt::Exception& e) {
|
||||
// Tell the VM the type of exception that occurred
|
||||
ctx->SetException(e.what());
|
||||
}catch (std::exception& e) {
|
||||
// Tell the VM the type of exception that occurred
|
||||
ctx->SetException(e.what());
|
||||
} catch (...) {
|
||||
|
||||
@@ -84,7 +84,10 @@ public:
|
||||
asITypeInfo* t;
|
||||
auto v = _baseTypes.TryGet(name);
|
||||
if (!v.has_value()) {
|
||||
t = this->_engine->GetTypeInfoByDecl(name.c_str());
|
||||
t = _mainModule->GetTypeInfoByName(name.c_str());
|
||||
if (t == NULL){
|
||||
t = _engine->GetTypeInfoByDecl(name.c_str());
|
||||
}
|
||||
_baseTypes.Insert(name, t);
|
||||
} else {
|
||||
t = v.value();
|
||||
|
||||
@@ -25,6 +25,8 @@ public:
|
||||
|
||||
~AngelScriptScript() override { _obj->Release(); }
|
||||
|
||||
inline asIScriptObject* GetRawAngelscriptObject() const noexcept { return _obj; }
|
||||
|
||||
[[nodiscard]] const ArbUt::StringView& GetName() const noexcept override { return _type->GetName(); }
|
||||
const AngelScriptTypeInfo* GetType() const noexcept { return _type; }
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <CreatureLib/Battling/Models/Battle.hpp>
|
||||
#include <CreatureLib/Battling/Models/BattleSide.hpp>
|
||||
#include "../../../../Battling/Battle/Battle.hpp"
|
||||
#include "../../AngelScriptScript.hpp"
|
||||
#include "../HelperFile.hpp"
|
||||
|
||||
void RegisterBattleClass::Register(asIScriptEngine* engine) {
|
||||
@@ -50,6 +51,11 @@ CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battl
|
||||
return battle->GetSides()[index];
|
||||
}
|
||||
|
||||
static asIScriptObject* AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) {
|
||||
auto* scriptObject = (AngelScriptScript*)obj->AddVolatileScript(name);
|
||||
return scriptObject->GetRawAngelscriptObject();
|
||||
}
|
||||
|
||||
void RegisterBattleClass::RegisterBattleSide(asIScriptEngine* engine) {
|
||||
int r = engine->RegisterObjectMethod(
|
||||
"BattleSide", "bool SwapPositions(uint8 a, uint8 b)",
|
||||
@@ -81,9 +87,8 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("Battle", "ChoiceQueue@ get_TurnQueue() const property",
|
||||
asFUNCTION(GetCurrentTurnQueueWrapper), asCALL_CDECL_OBJFIRST);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Battle", "void AddVolatile(const constString &in name) const",
|
||||
asMETHODPR(PkmnLib::Battling::Battle, AddVolatileScript, (const ArbUt::StringView&), void), asCALL_THISCALL);
|
||||
r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name) const",
|
||||
asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Battle", "void RemoveVolatile(const constString &in name) const",
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include "RegisterPokemonClass.hpp"
|
||||
#include <CreatureLib/Battling/Models/LearnedAttack.hpp>
|
||||
#include "../../../../../extern/angelscript_addons/scriptarray/scriptarray.h"
|
||||
#include "../../../../../extern/angelscript_addons/scripthandle/scripthandle.h"
|
||||
#include "../../../../Battling/PkmnDamageSource.hpp"
|
||||
#include "../../../../Battling/Pokemon/Pokemon.hpp"
|
||||
#include "../../AngelScriptResolver.hpp"
|
||||
#include "../../AngelScriptScript.hpp"
|
||||
#include "../HelperFile.hpp"
|
||||
|
||||
// Hack to handle AngelScript not recognizing different sized enums on fields, and returning invalid values due to it.
|
||||
@@ -87,6 +90,15 @@ OPTIONAL_BORROWED_PTR_GETTER_FUNC(PkmnLib::Battling::Pokemon, const CreatureLib:
|
||||
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) {
|
||||
auto handle = CScriptHandle();
|
||||
auto *resolver = static_cast<AngelScriptResolver*>(obj->GetLibrary()->GetScriptResolver().get());
|
||||
auto script = static_cast<AngelScriptScript*>(obj->AddVolatileScript(name))->GetRawAngelscriptObject();
|
||||
script->AddRef();
|
||||
handle.Set(script, resolver->GetBaseType("PkmnScript"));
|
||||
return handle;
|
||||
}
|
||||
|
||||
void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
[[maybe_unused]] int r = engine->RegisterObjectType("Pokemon", 0, asOBJ_REF | asOBJ_NOCOUNT);
|
||||
Ensure(r >= 0);
|
||||
@@ -177,9 +189,8 @@ void RegisterPokemonClass::RegisterPokemonType(asIScriptEngine* engine) {
|
||||
r = engine->RegisterObjectMethod("Pokemon", "int8 GetStatBoost(Statistic stat) const",
|
||||
asMETHOD(PkmnLib::Battling::Pokemon, GetStatBoost), asCALL_THISCALL);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Pokemon", "void AddVolatile(const constString &in name) const",
|
||||
asMETHODPR(PkmnLib::Battling::Pokemon, AddVolatileScript, (const ArbUt::StringView&), void), asCALL_THISCALL);
|
||||
r = engine->RegisterObjectMethod("Pokemon", "ref@ AddVolatile(const constString &in name)",
|
||||
asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST);
|
||||
Ensure(r >= 0);
|
||||
r = engine->RegisterObjectMethod(
|
||||
"Pokemon", "void RemoveVolatile(const constString &in name) const",
|
||||
|
||||
Reference in New Issue
Block a user