39 lines
1008 B
C#
39 lines
1008 B
C#
|
|
namespace OECS;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Fluent builder for constructing <see cref="QueryDescriptor"/> instances.
|
||
|
|
/// Returned by <see cref="World.Query"/>.
|
||
|
|
/// </summary>
|
||
|
|
public class QueryBuilder
|
||
|
|
{
|
||
|
|
private readonly HashSet<Type> _with = new();
|
||
|
|
private readonly HashSet<Type> _without = new();
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Requires entities to have a component of type <typeparamref name="T"/>.
|
||
|
|
/// </summary>
|
||
|
|
public QueryBuilder With<T>() where T : struct
|
||
|
|
{
|
||
|
|
_with.Add(typeof(T));
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Excludes entities that have a component of type <typeparamref name="T"/>.
|
||
|
|
/// </summary>
|
||
|
|
public QueryBuilder Without<T>() where T : struct
|
||
|
|
{
|
||
|
|
_without.Add(typeof(T));
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Builds the query descriptor.
|
||
|
|
/// </summary>
|
||
|
|
public QueryDescriptor Build()
|
||
|
|
{
|
||
|
|
return new QueryDescriptor(
|
||
|
|
new HashSet<Type>(_with),
|
||
|
|
new HashSet<Type>(_without));
|
||
|
|
}
|
||
|
|
}
|