Пример #1
0
        /// <summary>
        /// Evaluates a condition.
        /// </summary>
        public bool EvaluateCondition(RSConditionData inCondition)
        {
            Assert.True(!inCondition.Target.IsMultiValue(), "Multi-target queries cannot be right-hand values for conditions");

            MultiReturn <RSValue> query = ResolveValue(inCondition.Query);
            RSValue         target      = ResolveValue(inCondition.Target).ForceSingle();
            CompareOperator op          = inCondition.Operator;

            if (query.Set != null)
            {
                Subset subset = inCondition.MultiQuerySubset;
                foreach (var check in query.Set)
                {
                    bool bPass = Evaluate(op, check, target);
                    switch (subset)
                    {
                    case Subset.All:
                    {
                        if (!bPass)
                        {
                            return(false);
                        }
                        break;
                    }

                    case Subset.Any:
                    {
                        if (bPass)
                        {
                            return(true);
                        }
                        break;
                    }

                    case Subset.None:
                    {
                        if (bPass)
                        {
                            return(false);
                        }
                        break;
                    }
                    }
                }

                switch (subset)
                {
                case Subset.All:
                case Subset.None:
                    return(true);

                default:
                    return(false);
                }
            }

            return(Evaluate(op, query.Single, target));
        }
Пример #2
0
        private MultiReturn <IRSRuntimeEntity> ResolveEntityLinks(MultiReturn <IRSRuntimeEntity> inEntities, string inLinks, bool inbUseFirstLink)
        {
            if (string.IsNullOrEmpty(inLinks))
            {
                return(inEntities);
            }

            return(new MultiReturn <IRSRuntimeEntity>(EnumerateEntityLinks(inEntities, inLinks, inbUseFirstLink)));
        }
Пример #3
0
        /// <summary>
        /// Performs an action on entities.
        /// </summary>
        public MultiReturn <ActionResult> PerformAction(RSActionData inAction)
        {
            RSActionInfo actionInfo = m_Environment.Library.GetAction(inAction.Action.Id);
            MultiReturn <IRSRuntimeEntity> targets = ResolveEntity(inAction.Action.Scope);

            ResolveArgsArray(inAction.Arguments, actionInfo.TempArgStorage);

            if (targets.Set != null)
            {
                return(new MultiReturn <ActionResult>(m_Environment.PerformActions(targets.Set, actionInfo, actionInfo.TempArgStorage, this)));
            }

            return(new MultiReturn <ActionResult>(m_Environment.PerformAction(targets.Single, actionInfo, actionInfo.TempArgStorage, this)));
        }
Пример #4
0
        /// <summary>
        /// Resolves a query to a set of values.
        /// </summary>
        public MultiReturn <RSValue> EvaluateQuery(EntityScopedIdentifier inQuery, NestedValue[] inArguments)
        {
            RSQueryInfo queryInfo = m_Environment.Library.GetQuery(inQuery.Id);
            MultiReturn <IRSRuntimeEntity> targets = ResolveEntity(inQuery.Scope);

            ResolveArgsArray(inArguments, queryInfo.TempArgStorage);

            if (targets.Set != null)
            {
                return(new MultiReturn <RSValue>(m_Environment.EvaluateQueries(targets.Set, queryInfo, queryInfo.TempArgStorage, this)));
            }

            return(new MultiReturn <RSValue>(m_Environment.EvaluateQuery(targets.Single, queryInfo, queryInfo.TempArgStorage, this)));
        }
Пример #5
0
        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);
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Resolves scope to an entity or set of entities.
        /// </summary>
        public MultiReturn <IRSRuntimeEntity> ResolveEntity(EntityScopeData inScope)
        {
            MultiReturn <IRSRuntimeEntity> returnVal;

            switch (inScope.Type)
            {
            case EntityScopeType.Null:
            {
                returnVal = MultiReturn <IRSRuntimeEntity> .Default;
                break;
            }

            case EntityScopeType.Self:
            {
                returnVal = new MultiReturn <IRSRuntimeEntity>(m_Self);
                break;
            }

            case EntityScopeType.Global:
            {
                return(new MultiReturn <IRSRuntimeEntity>());
            }

            case EntityScopeType.Argument:
            {
                returnVal = ResolveEntity(m_Argument.AsEntity);
                break;
            }

            case EntityScopeType.ObjectById:
            {
                returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntityWithId(inScope.IdArg));
                break;
            }

            case EntityScopeType.ObjectInRegister:
            {
                EntityScopeData id = PeekRegister(inScope.RegisterArg).AsEntity;
                returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntityWithId(id.IdArg));
                break;
            }

            case EntityScopeType.ObjectsWithGroup:
            {
                if (inScope.UseFirst)
                {
                    returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntityWithGroup(inScope.GroupArg));
                }
                else
                {
                    returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntitiesWithGroup(inScope.GroupArg));
                }
                break;
            }

            case EntityScopeType.ObjectsWithName:
            {
                if (inScope.UseFirst)
                {
                    returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntityWithName(inScope.SearchArg));
                }
                else
                {
                    returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntitiesWithName(inScope.SearchArg));
                }
                break;
            }

            case EntityScopeType.ObjectsWithPrefab:
            {
                if (inScope.UseFirst)
                {
                    returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntityWithPrefab(inScope.SearchArg));
                }
                else
                {
                    returnVal = new MultiReturn <IRSRuntimeEntity>(m_Environment.Entities.Lookup.EntitiesWithPrefab(inScope.SearchArg));
                }
                break;
            }

            case EntityScopeType.Invalid:
            {
                Assert.Fail("Missing entity reference");
                return(MultiReturn <IRSRuntimeEntity> .Default);
            }

            default:
            {
                Assert.Fail("Unrecognized scope type {0}", inScope.Type);
                return(MultiReturn <IRSRuntimeEntity> .Default);
            }
            }

            return(ResolveEntityLinks(returnVal, inScope.LinksArg, inScope.UseFirstLink));
        }