A bunch of work on the concept of script owners.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-10-29 23:54:44 +02:00
parent 0623bdff06
commit ede314ef39
19 changed files with 110 additions and 32 deletions

View File

@@ -15,6 +15,27 @@ AngelScriptScript::GetEffectParameters(const ArbUt::List<CreatureLib::Library::E
return new NativeArray<ArbUt::List<CreatureLib::Library::EffectParameter*>>(&ls);
}
AngelScriptScript::AngelScriptScript(const ArbUt::OptionalBorrowedPtr<void>& owner, asITypeInfo* ownerType,
AngelScriptResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
ContextPool* ctxPool)
: PkmnLib::Battling::PkmnScript(owner), _resolver(resolver), _type(type), _ctxPool(ctxPool), _obj(obj) {
if (_type->GetGetOwner().Exists) {
CScriptHandle* handle = nullptr;
AngelScriptUtils::AngelscriptFunctionCall(
_type->GetGetOwner().Function, _ctxPool, _obj, _resolver, GetName(), [&](asIScriptContext*) {},
[&](asIScriptContext* ctx) { handle = (CScriptHandle*)ctx->GetReturnObject(); });
handle->Set(owner.GetValue(), ownerType);
}
}
CScriptHandle* AngelScriptScript::GetAngelscriptOwner() {
CScriptHandle* handle = nullptr;
AngelScriptUtils::AngelscriptFunctionCall(
_type->GetGetOwner().Function, _ctxPool, _obj, _resolver, GetName(), [&](asIScriptContext*) {},
[&](asIScriptContext* ctx) { handle = (CScriptHandle*)ctx->GetReturnObject(); });
return handle;
}
void AngelScriptScript::OnInitialize(const ArbUt::List<CreatureLib::Library::EffectParameter*>& parameters) {
CALL_HOOK(OnInitialize, {
auto arr = GetEffectParameters(parameters);
@@ -301,12 +322,13 @@ void AngelScriptScript::ModifyNumberOfHits(CreatureLib::Battling::AttackTurnChoi
ctx->SetArgAddress(1, numberOfHits);
})}
CreatureLib::Battling::BattleScript* AngelScriptScript::Clone() {
CreatureLib::Battling::BattleScript* AngelScriptScript::Clone(const ArbUt::OptionalBorrowedPtr<void>& owner) {
auto* ctx = _ctxPool->RequestContext();
auto* obj = _type->Instantiate(ctx);
if (_obj != nullptr) {
obj->CopyFrom(_obj);
}
_ctxPool->ReturnContextToPool(ctx);
return new AngelScriptScript(_resolver, _type, obj, _ctxPool);
return new AngelScriptScript(owner, GetAngelscriptOwner()->GetType(), _resolver, _type, obj, _ctxPool);
}