Bunch of fixes for Owners of scripts.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -467,3 +467,28 @@ i32 AngelScriptResolver::IncludeCallback(const char* include, const char*, CScri
|
||||
}
|
||||
return builder->AddSectionFromFile((const char*)path.c_str());
|
||||
}
|
||||
|
||||
void AngelScriptResolver::Reset(CreatureLib::Battling::BattleLibrary* library) {
|
||||
for (const auto& ius : _itemUseScripts) {
|
||||
delete ius.second;
|
||||
}
|
||||
delete _contextPool;
|
||||
for (const auto& category : _typeDatabase) {
|
||||
for (const auto& type : category.second) {
|
||||
delete type.second;
|
||||
}
|
||||
}
|
||||
delete _userData;
|
||||
_engine->ShutDownAndRelease();
|
||||
|
||||
_userData = new AngelscriptUserdata(this);
|
||||
_typeDatabase.Clear();
|
||||
_baseTypes.Clear();
|
||||
_itemUseTypes.Clear();
|
||||
_evolutionTypes.Clear();
|
||||
_itemUseScripts.Clear();
|
||||
_evolutionScripts.Clear();
|
||||
_scriptOwnerTypes.Clear();
|
||||
|
||||
Initialize(library);
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
inline ArbUt::OptionalBorrowedPtr<AngelscriptDebugger> GetDebugger() const noexcept { return _debugger.GetValue(); }
|
||||
inline void SetDebugger(AngelscriptDebugger* debugger) noexcept { _debugger = debugger; }
|
||||
|
||||
inline asITypeInfo* GetScriptOwnerType(ScriptCategory category) {
|
||||
asITypeInfo* GetScriptOwnerType(ScriptCategory category) {
|
||||
auto tryget = _scriptOwnerTypes.TryGet(category);
|
||||
if (tryget.has_value()) {
|
||||
return tryget.value();
|
||||
@@ -137,5 +137,7 @@ public:
|
||||
_scriptOwnerTypes.Set(category, t);
|
||||
return t;
|
||||
}
|
||||
|
||||
void Reset(CreatureLib::Battling::BattleLibrary* library);
|
||||
};
|
||||
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
||||
|
||||
@@ -20,13 +20,13 @@ AngelScriptScript::AngelScriptScript(const ArbUt::OptionalBorrowedPtr<void>& own
|
||||
ContextPool* ctxPool)
|
||||
: PkmnLib::Battling::PkmnScript(owner), _resolver(resolver), _type(type), _ctxPool(ctxPool), _obj(obj) {
|
||||
if (_type->GetGetOwner().Exists && owner.HasValue()) {
|
||||
if (ownerType == nullptr){
|
||||
if (ownerType == nullptr) {
|
||||
THROW("Script was created with owner value, but with unknown owner type.")
|
||||
}
|
||||
CScriptHandle* handle = nullptr;
|
||||
AngelScriptUtils::AngelscriptFunctionCall(
|
||||
_type->GetGetOwner().Function, _ctxPool, _obj, _resolver, GetName(), [&](asIScriptContext*) {},
|
||||
[&](asIScriptContext* ctx) { handle = (CScriptHandle*)ctx->GetReturnObject(); });
|
||||
[&](asIScriptContext* ctx) { handle = (CScriptHandle*)ctx->GetReturnAddress(); });
|
||||
handle->Set(owner.GetValue(), ownerType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
FunctionInfo InitializeGetOwner(){
|
||||
auto t = _type;
|
||||
while (t != nullptr){
|
||||
auto val = t->GetMethodByDecl("protected ref@& GetOwner()", false);
|
||||
auto val = t->GetMethodByDecl("ref@& GetOwner()", true);
|
||||
if (val != nullptr){
|
||||
return FunctionInfo{.Exists = true, .Function = val};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user