/// <summary> /// Performs an action with static scope. /// </summary> public object PerformAction(IRSRuntimeEntity inEntity, string inActionId, params object[] inArgs) { RSActionInfo actionInfo = Library.GetAction(inActionId); ExecutionScope scope = CreateScope(inEntity, RSValue.Null, TableUtils.GetRuleFlags(actionInfo.Flags)); using (new SharedRef <ExecutionScope>(scope)) { return(PerformAction(inEntity, actionInfo, InternalScriptUtils.Convert(inArgs), scope).Value); } }
public void Reset() { m_Self = null; m_Argument = RSValue.Null; if (m_Registers != null) { for (int i = 0; i < RSRegisters.MaxRegisters; ++i) { m_Registers[i] = default(RSValue); } } }
internal void TriggerRS(IRSRuntimeEntity inEntity, RSTriggerId inTriggerId, RSValue inArgument, bool inbForce) { if (!inbForce && inEntity.IsLocked()) { return; } ExecutionScope scope = CreateScope(inEntity, inArgument, 0); using (new SharedRef <ExecutionScope>(scope)) { inEntity?.RuleTable?.EvaluateTrigger(inTriggerId, scope); } }
static public bool IsListeningForTrigger(this IRSRuntimeEntity inEntity, RSTriggerId inTriggerId) { if (inTriggerId == RSTriggerId.Null) { return(false); } RSTriggerId[] triggers = (inEntity.RuleTable?.Data?.UniqueTriggers); if (triggers != null) { return(Array.IndexOf(triggers, inTriggerId) >= 0); } return(false); }
private void Bind(InvocationTarget inTarget, IRSRuntimeEntity inEntity, IScriptContext inContext, ref object ioValue) { switch (inTarget) { case InvocationTarget.Entity: ioValue = inEntity; break; case InvocationTarget.Component: ioValue = inEntity?.GetRSComponent(ComponentType); break; case InvocationTarget.Context: ioValue = inContext; break; } }
internal RSValue InvokeWithCachedArgs(IRSRuntimeEntity inTarget, ExecutionScope inContext) { object thisArg; bool bValid = PrepContext(inTarget, inContext, out thisArg); if (!bValid) { if (m_MethodSettings.ComponentType != null) { inContext.Logger?.Warn("Unable to evaluate query {0} on Entity \"{1}\" ({2}) - missing component type {3}", Id, inTarget?.Name, inTarget != null ? inTarget.Id : RSEntityId.Null, m_MethodSettings.ComponentType); } else { inContext.Logger?.Warn("Unable to evaluate query {0} on Entity \"{1}\" ({2})", Id, inTarget?.Name, inTarget != null ? inTarget.Id : RSEntityId.Null); } return(m_DefaultValue); } object returnVal = m_MethodInfo.Invoke(thisArg, m_CachedArguments); return(RSInterop.ToRSValue(returnVal)); }
private IEnumerable <IRSRuntimeEntity> EnumerateEntityLinks(MultiReturn <IRSRuntimeEntity> inEntities, string inLinks, bool inbUseFirstLink) { using (PooledList <StringSlice> paths = PooledList <StringSlice> .Alloc()) { int sliceCount = StringSlice.Split(inLinks, EntityLinkSplitChars, StringSplitOptions.None, paths); foreach (var entity in inEntities) { IRSRuntimeEntity currentEntity = entity; for (int i = 0; currentEntity != null && i < sliceCount - 1; ++i) { StringSlice path = paths[i]; currentEntity = currentEntity.Links?.EntityWithLink(path); } if (currentEntity != null) { var links = currentEntity.Links; if (links == null) { continue; } if (inbUseFirstLink) { yield return(links.EntityWithLink(paths[sliceCount - 1])); } else { foreach (var linkedEntity in links.EntitiesWithLink(paths[sliceCount - 1])) { yield return(linkedEntity); } } } } } }
public bool Bind(IRSRuntimeEntity inEntity, object[] ioArguments, IScriptContext inContext, out object outThis) { if (IsExtension) { if (ioArguments.Length == 0) { outThis = null; return(false); } } if (ioArguments.Length > 0) { Bind(FirstParam, inEntity, inContext, ref ioArguments[0]); if (ioArguments.Length > 1) { Bind(SecondParam, inEntity, inContext, ref ioArguments[1]); } } outThis = null; Bind(ThisParam, inEntity, inContext, ref outThis); if (IsExtension) { return(!FirstParam.MustBeNotNull() || ioArguments[0] != null); } else if (IsInstance) { return(outThis != null); } else { return(true); } }
static private void SetActive(this IRSRuntimeEntity inEntity, [RSParameter("Active")] bool inbActive) { inEntity.SetActive(inbActive); }
static private void Deactivate(this IRSRuntimeEntity inEntity) { inEntity.SetActive(false); }
static private void ToggleActive(this IRSRuntimeEntity inEntity) { inEntity.SetActive(!inEntity.IsActive()); }
static private void LoadRegisterEntity(IScriptContext inContext, [RSParameter("Register")] RegisterIndex inRegister, [RSParameter("Value")] IRSRuntimeEntity inValue) { inContext?.Logger?.Log("Loading register {0} with value {1}", inRegister, inValue); inContext.LoadRegister(inRegister, inValue); }
static private void StopRule(this IRSRuntimeEntity inEntity, [RSParameter("Rule Name")] string inRuleName) { inEntity.RuleTable.StopRule(inRuleName); }
internal ActionResult PerformAction(IRSRuntimeEntity inEntity, RSActionInfo inAction, RSValue[] inArguments, ExecutionScope inContext) { return(inAction.Invoke(inEntity, inArguments, inContext)); }
static private void Activate(this IRSRuntimeEntity inEntity) { inEntity.SetActive(true); }
static private bool IsActive(this IRSRuntimeEntity inEntity) { return(inEntity.IsActive()); }
static private bool IsLocked(this IRSRuntimeEntity inEntity) { return(inEntity.IsLocked()); }
static private void ToggleLocked(this IRSRuntimeEntity inEntity) { inEntity.SetLocked(!inEntity.IsLocked()); }
static private void DispatchTrigger(this IRSRuntimeEntity inEntity, IScriptContext inContext, [RSParameter("Trigger", TriggerParameterType = typeof(void))] RSTriggerId inTrigger) { inContext?.Trigger(inEntity, inTrigger); }
void IScriptContext.Trigger(IRSRuntimeEntity inEntity, RSTriggerId inTriggerId, object inArgument, bool inbForce) { m_Environment.Trigger(inEntity, inTriggerId, RSInterop.ToRSValue(inArgument), inbForce); }
internal RSValue EvaluateQuery(IRSRuntimeEntity inEntity, RSQueryInfo inQuery, RSValue[] inArgs, ExecutionScope inContext) { return(inQuery.Invoke(inEntity, inArgs, inContext)); }
public void Initialize(IRSRuntimeEntity inSelf, RSValue inArgument) { m_Self = inSelf; m_Argument = inArgument; }
static private void Lock(this IRSRuntimeEntity inEntity) { inEntity.SetLocked(true); }
public RSRuntimeRuleTable(IRSRuntimeEntity inOwner) { m_Entity = inOwner; }
static private void Unlock(this IRSRuntimeEntity inEntity) { inEntity.SetLocked(false); }
public void Trigger(IRSRuntimeEntity inEntity, string inTriggerId, bool inbForce = false) { Trigger(inEntity, new RSTriggerId(ScriptUtils.Hash(inTriggerId)), RSValue.Null, inbForce); }
static private void SetLocked(this IRSRuntimeEntity inEntity, [RSParameter("Locked")] bool inbLocked) { inEntity.SetLocked(inbLocked); }
internal bool PrepContext(IRSRuntimeEntity inTarget, ExecutionScope inScope, out object outThis) { return(m_MethodSettings.Bind(inTarget, m_CachedArguments, inScope, out outThis)); }
static private void DispatchTriggerWithString(this IRSRuntimeEntity inEntity, IScriptContext inContext, [RSParameter("Trigger", TriggerParameterType = typeof(string))] RSTriggerId inTrigger, [RSParameter("Trigger Parameter")] string inArgument) { inContext?.Trigger(inEntity, inTrigger, inArgument); }
static private RSGroupId Group(this IRSRuntimeEntity inEntity) { return(inEntity.Group); }