2022-03-06 06:12:27 +00:00
|
|
|
namespace MoonTools.ECS;
|
|
|
|
|
|
|
|
public struct FilterBuilder
|
|
|
|
{
|
|
|
|
private ComponentDepot ComponentDepot;
|
|
|
|
private HashSet<Type> Included;
|
|
|
|
private HashSet<Type> Excluded;
|
|
|
|
|
|
|
|
internal FilterBuilder(ComponentDepot componentDepot)
|
|
|
|
{
|
|
|
|
ComponentDepot = componentDepot;
|
|
|
|
Included = new HashSet<Type>();
|
|
|
|
Excluded = new HashSet<Type>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private FilterBuilder(ComponentDepot componentDepot, HashSet<Type> included, HashSet<Type> excluded)
|
|
|
|
{
|
|
|
|
ComponentDepot = componentDepot;
|
|
|
|
Included = included;
|
|
|
|
Excluded = excluded;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FilterBuilder Include<TComponent>() where TComponent : struct
|
|
|
|
{
|
2022-03-07 20:05:06 +00:00
|
|
|
ComponentDepot.Register<TComponent>();
|
2022-03-06 06:12:27 +00:00
|
|
|
Included.Add(typeof(TComponent));
|
|
|
|
return new FilterBuilder(ComponentDepot, Included, Excluded);
|
|
|
|
}
|
|
|
|
|
|
|
|
public FilterBuilder Exclude<TComponent>() where TComponent : struct
|
|
|
|
{
|
2022-03-07 20:05:06 +00:00
|
|
|
ComponentDepot.Register<TComponent>();
|
2022-03-06 06:12:27 +00:00
|
|
|
Excluded.Add(typeof(TComponent));
|
|
|
|
return new FilterBuilder(ComponentDepot, Included, Excluded);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Filter Build()
|
|
|
|
{
|
|
|
|
return ComponentDepot.CreateFilter(Included, Excluded);
|
|
|
|
}
|
|
|
|
}
|