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