using System; using System.Collections.Generic; namespace MoonTools.ECS { public struct FilterBuilder { private TypeIndices ComponentTypeIndices; private FilterStorage FilterStorage; private HashSet Included; private HashSet Excluded; internal FilterBuilder(FilterStorage filterStorage, TypeIndices componentTypeIndices) { FilterStorage = filterStorage; ComponentTypeIndices = componentTypeIndices; Included = new HashSet(); Excluded = new HashSet(); } private FilterBuilder(FilterStorage filterStorage, TypeIndices componentTypeIndices, HashSet included, HashSet excluded) { FilterStorage = filterStorage; ComponentTypeIndices = componentTypeIndices; Included = included; Excluded = excluded; } public FilterBuilder Include() where TComponent : unmanaged { Included.Add(ComponentTypeIndices.GetIndex()); return new FilterBuilder(FilterStorage, ComponentTypeIndices, Included, Excluded); } public FilterBuilder Exclude() where TComponent : unmanaged { Excluded.Add(ComponentTypeIndices.GetIndex()); return new FilterBuilder(FilterStorage, ComponentTypeIndices, Included, Excluded); } public Filter Build() { return FilterStorage.CreateFilter(Included, Excluded); } } }