예제 #1
0
        public bool Equals(FilterRules filter)
        {
            if (_filterTags.Count == filter._filterTags.Count && _componentsToFilterOn.Count == filter._componentsToFilterOn.Count)
            {
                for (int i = 0, c = _filterTags.Count; i < c; i++)
                {
                    TagRule ownRule = _filterTags[i];
                    if (filter._filterTags.FindIndex(fc => ownRule.IsEqual(fc)) < 0)
                    {
                        return(false);
                    }
                }

                for (int i = 0, c = _componentsToFilterOn.Count; i < c; i++)
                {
                    IncComponentRule ownRule = _componentsToFilterOn[i];
                    if (filter._componentsToFilterOn.FindIndex(fc => ownRule.IsEqual(fc)) < 0)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Adds a component type to the filter, so it will only get entries with the given component present.
        /// The filter will return entries which have ALL of the components given to it.
        /// </summary>
        public FilterRulesBuilder AddHasComponentRule(Type entityComponentType, bool mustBeEnabled)
        {
            if (!typeof(EntityComponent).IsAssignableFrom(entityComponentType))
            {
                throw new InvalidCastException($"Can't add component rule because `{entityComponentType}` is not of type `{nameof(EntityComponent)}`");
            }

            IncComponentRule rule = new IncComponentRule(entityComponentType, mustBeEnabled);

            if (!_componentsToFilterOn.Contains(rule))
            {
                _componentsToFilterOn.Add(rule);
            }
            return(this);
        }
예제 #3
0
 public bool IsEqual(IncComponentRule otherRule)
 {
     return(ComponentType == otherRule.ComponentType && MustBeEnabled == otherRule.MustBeEnabled);
 }