diff --git a/src/MfGames.Gallium/Entity.cs b/src/MfGames.Gallium/Entity.cs
index 3137989..7f60251 100644
--- a/src/MfGames.Gallium/Entity.cs
+++ b/src/MfGames.Gallium/Entity.cs
@@ -3,471 +3,470 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
-namespace MfGames.Gallium
+namespace MfGames.Gallium;
+
+///
+/// A low-overhead entity with identification.
+///
+public record Entity
{
- ///
- /// A low-overhead entity with identification.
- ///
- public record Entity
+ ///
+ public virtual bool Equals(Entity? other)
{
- ///
- public virtual bool Equals(Entity? other)
+ if (ReferenceEquals(null, other))
{
- if (ReferenceEquals(null, other))
- {
- return false;
- }
-
- if (ReferenceEquals(this, other))
- {
- return true;
- }
-
- return this.Id == other.Id;
- }
-
- ///
- public override int GetHashCode()
- {
- return this.Id;
- }
-
- private ImmutableDictionary Components { get; set; }
-
- ///
- /// The internal ID to ensure the entities are unique. Since we are not
- /// worried about serialization or using the identifiers from one call
- /// to another, we can use a simple interlocked identifier instead of
- /// a factory or provider method.
- ///
- private static int nextId;
-
- public Entity()
- : this(Interlocked.Increment(ref nextId))
- {
- }
-
- private Entity(int id)
- {
- this.Id = id;
- this.Components = ImmutableDictionary.Create();
- }
-
- ///
- /// Gets a value indicating whether the entity has a specific type of
- /// component registered.
- ///
- /// The component type.
- /// True if the type exists, otherwise false.
- public bool Has()
- {
- return this.Has(typeof(T1));
- }
-
- ///
- /// Gets a value indicating whether the entity has components of the given types
- /// registered.
- ///
- /// The first component type.
- /// The second component type.
- ///
- /// True if there are components of the given type exists, otherwise
- /// false.
- ///
- public bool HasAll()
- {
- return this.HasAll(typeof(T1), typeof(T2));
- }
-
- ///
- /// Gets a value indicating whether the entity has components of the given types
- /// registered.
- ///
- /// The first component type.
- /// The second component type.
- /// The third component type.
- ///
- /// True if there are components of the given type exists, otherwise
- /// false.
- ///
- public bool HasAll()
- {
- return this.HasAll(typeof(T1), typeof(T2), typeof(T3));
- }
-
- ///
- /// Gets a value indicating whether the entity has components of the given types
- /// registered.
- ///
- /// The first component type.
- /// The second component type.
- /// The third component type.
- /// The third component type.
- ///
- /// True if there are components of the given type exists, otherwise
- /// false.
- ///
- public bool HasAll()
- {
- return this.HasAll(typeof(T1), typeof(T2), typeof(T3), typeof(T4));
- }
-
- ///
- /// Gets a value indicating whether the entity has a specific type of
- /// component registered.
- ///
- /// The component type.
- /// True if the type exists, otherwise false.
- public bool Has(Type type)
- {
- return this.Components.ContainsKey(type);
- }
-
- ///
- /// Gets a value indicating whether the entity has components for all the given
- /// types.
- ///
- /// The component type.
- /// The component type.
- /// True if the type exists, otherwise false.
- public bool HasAll(
- Type t1,
- Type t2)
- {
- return this.Has(t1) && this.Components.ContainsKey(t2);
- }
-
- ///
- /// Gets a value indicating whether the entity has components for all the given
- /// types.
- ///
- /// The component type.
- /// The component type.
- /// The component type.
- /// True if the type exists, otherwise false.
- public bool HasAll(
- Type t1,
- Type t2,
- Type t3)
- {
- return this.HasAll(t1, t2) && this.Components.ContainsKey(t3);
- }
-
- ///
- /// Gets a value indicating whether the entity has components for all the given
- /// types.
- ///
- /// The component type.
- /// The component type.
- /// The component type.
- /// The component type.
- /// True if the type exists, otherwise false.
- public bool HasAll(
- Type t1,
- Type t2,
- Type t3,
- Type t4)
- {
- return this.HasAll(t1, t2, t3) && this.Components.ContainsKey(t4);
- }
-
- ///
- /// Retrieves a registered component of the given type.
- ///
- /// The component type.
- /// The registered object.
- public TType Get()
- {
- return (TType)this.Components[typeof(TType)];
- }
-
- ///
- /// Retrieves a registered component of the given type and casts it to
- /// TType.
- ///
- /// The component key.
- /// The component type.
- /// The registered object.
- public TType Get(Type type)
- {
- return (TType)this.Components[type];
- }
-
- ///
- /// Gets the number of components registered in the entity.
- ///
- public int Count => this.Components.Count;
-
- ///
- /// Gets the given component type if inside the entity, otherwise the
- /// default value.
- ///
- /// The component type.
- /// The found component or default (typically null).
- public TType? GetOptional()
- {
- return this.Has() ? this.Get() : default;
- }
-
- ///
- /// Attempts to get the value, if present. If not, this returns false
- /// and the value is undefined. Otherwise, this method returns true
- /// and the actual value inside that variable.
- ///
- /// The value if contained in the entity.
- /// The component type.
- /// True if found, otherwise false.
- public bool TryGet(out T1 value)
- {
- if (this.Has())
- {
- value = this.Get();
-
- return true;
- }
-
- value = default!;
-
return false;
}
- ///
- /// Attempts to get the values, if present. If not, this returns false
- /// and the value is undefined. Otherwise, this method returns true
- /// and the actual value inside that variable.
- ///
- /// The value if contained in the entity.
- /// The value if contained in the entity.
- /// The first component type.
- /// The second component type.
- /// True if found, otherwise false.
- public bool TryGet(
- out T1 value1,
- out T2 value2)
+ if (ReferenceEquals(this, other))
{
- if (this.HasAll())
- {
- value1 = this.Get();
- value2 = this.Get();
-
- return true;
- }
-
- value1 = default!;
- value2 = default!;
-
- return false;
+ return true;
}
- ///
- /// Attempts to get the values, if present. If not, this returns false
- /// and the value is undefined. Otherwise, this method returns true
- /// and the actual value inside that variable.
- ///
- /// The value if contained in the entity.
- /// The value if contained in the entity.
- /// The value if contained in the entity.
- /// The first component type.
- /// The second component type.
- /// The third component type.
- /// True if found, otherwise false.
- public bool TryGet(
- out T1 value1,
- out T2 value2,
- out T3 value3)
+ return this.Id == other.Id;
+ }
+
+ ///
+ public override int GetHashCode()
+ {
+ return this.Id;
+ }
+
+ private ImmutableDictionary Components { get; set; }
+
+ ///
+ /// The internal ID to ensure the entities are unique. Since we are not
+ /// worried about serialization or using the identifiers from one call
+ /// to another, we can use a simple interlocked identifier instead of
+ /// a factory or provider method.
+ ///
+ private static int nextId;
+
+ public Entity()
+ : this(Interlocked.Increment(ref nextId))
+ {
+ }
+
+ private Entity(int id)
+ {
+ this.Id = id;
+ this.Components = ImmutableDictionary.Create();
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has a specific type of
+ /// component registered.
+ ///
+ /// The component type.
+ /// True if the type exists, otherwise false.
+ public bool Has()
+ {
+ return this.Has(typeof(T1));
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has components of the given types
+ /// registered.
+ ///
+ /// The first component type.
+ /// The second component type.
+ ///
+ /// True if there are components of the given type exists, otherwise
+ /// false.
+ ///
+ public bool HasAll()
+ {
+ return this.HasAll(typeof(T1), typeof(T2));
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has components of the given types
+ /// registered.
+ ///
+ /// The first component type.
+ /// The second component type.
+ /// The third component type.
+ ///
+ /// True if there are components of the given type exists, otherwise
+ /// false.
+ ///
+ public bool HasAll()
+ {
+ return this.HasAll(typeof(T1), typeof(T2), typeof(T3));
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has components of the given types
+ /// registered.
+ ///
+ /// The first component type.
+ /// The second component type.
+ /// The third component type.
+ /// The third component type.
+ ///
+ /// True if there are components of the given type exists, otherwise
+ /// false.
+ ///
+ public bool HasAll()
+ {
+ return this.HasAll(typeof(T1), typeof(T2), typeof(T3), typeof(T4));
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has a specific type of
+ /// component registered.
+ ///
+ /// The component type.
+ /// True if the type exists, otherwise false.
+ public bool Has(Type type)
+ {
+ return this.Components.ContainsKey(type);
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has components for all the given
+ /// types.
+ ///
+ /// The component type.
+ /// The component type.
+ /// True if the type exists, otherwise false.
+ public bool HasAll(
+ Type t1,
+ Type t2)
+ {
+ return this.Has(t1) && this.Components.ContainsKey(t2);
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has components for all the given
+ /// types.
+ ///
+ /// The component type.
+ /// The component type.
+ /// The component type.
+ /// True if the type exists, otherwise false.
+ public bool HasAll(
+ Type t1,
+ Type t2,
+ Type t3)
+ {
+ return this.HasAll(t1, t2) && this.Components.ContainsKey(t3);
+ }
+
+ ///
+ /// Gets a value indicating whether the entity has components for all the given
+ /// types.
+ ///
+ /// The component type.
+ /// The component type.
+ /// The component type.
+ /// The component type.
+ /// True if the type exists, otherwise false.
+ public bool HasAll(
+ Type t1,
+ Type t2,
+ Type t3,
+ Type t4)
+ {
+ return this.HasAll(t1, t2, t3) && this.Components.ContainsKey(t4);
+ }
+
+ ///
+ /// Retrieves a registered component of the given type.
+ ///
+ /// The component type.
+ /// The registered object.
+ public TType Get()
+ {
+ return (TType)this.Components[typeof(TType)];
+ }
+
+ ///
+ /// Retrieves a registered component of the given type and casts it to
+ /// TType.
+ ///
+ /// The component key.
+ /// The component type.
+ /// The registered object.
+ public TType Get(Type type)
+ {
+ return (TType)this.Components[type];
+ }
+
+ ///
+ /// Gets the number of components registered in the entity.
+ ///
+ public int Count => this.Components.Count;
+
+ ///
+ /// Gets the given component type if inside the entity, otherwise the
+ /// default value.
+ ///
+ /// The component type.
+ /// The found component or default (typically null).
+ public TType? GetOptional()
+ {
+ return this.Has() ? this.Get() : default;
+ }
+
+ ///
+ /// Attempts to get the value, if present. If not, this returns false
+ /// and the value is undefined. Otherwise, this method returns true
+ /// and the actual value inside that variable.
+ ///
+ /// The value if contained in the entity.
+ /// The component type.
+ /// True if found, otherwise false.
+ public bool TryGet(out T1 value)
+ {
+ if (this.Has())
{
- if (this.HasAll())
- {
- value1 = this.Get();
- value2 = this.Get();
- value3 = this.Get();
+ value = this.Get();
- return true;
- }
-
- value1 = default!;
- value2 = default!;
- value3 = default!;
-
- return false;
+ return true;
}
- ///
- /// Attempts to get the values, if present. If not, this returns false
- /// and the value is undefined. Otherwise, this method returns true
- /// and the actual value inside that variable.
- ///
- /// The value if contained in the entity.
- /// The value if contained in the entity.
- /// The value if contained in the entity.
- /// The value if contained in the entity.
- /// The first component type.
- /// The second component type.
- /// The third component type.
- /// The fourth component type.
- /// True if found, otherwise false.
- public bool TryGet(
- out T1 value1,
- out T2 value2,
- out T3 value3,
- out T4 value4)
+ value = default!;
+
+ return false;
+ }
+
+ ///
+ /// Attempts to get the values, if present. If not, this returns false
+ /// and the value is undefined. Otherwise, this method returns true
+ /// and the actual value inside that variable.
+ ///
+ /// The value if contained in the entity.
+ /// The value if contained in the entity.
+ /// The first component type.
+ /// The second component type.
+ /// True if found, otherwise false.
+ public bool TryGet(
+ out T1 value1,
+ out T2 value2)
+ {
+ if (this.HasAll())
{
- if (this.HasAll())
- {
- value1 = this.Get();
- value2 = this.Get();
- value3 = this.Get();
- value4 = this.Get();
+ value1 = this.Get();
+ value2 = this.Get();
- return true;
- }
-
- value1 = default!;
- value2 = default!;
- value3 = default!;
- value4 = default!;
-
- return false;
+ return true;
}
- ///
- /// Sets the component in the entity, regardless if there was a
- /// component already registered.
- ///
- /// The component to register.
- /// The component type.
- /// The entity for chaining.
- ///
- public Entity Set(T1 component)
+ value1 = default!;
+ value2 = default!;
+
+ return false;
+ }
+
+ ///
+ /// Attempts to get the values, if present. If not, this returns false
+ /// and the value is undefined. Otherwise, this method returns true
+ /// and the actual value inside that variable.
+ ///
+ /// The value if contained in the entity.
+ /// The value if contained in the entity.
+ /// The value if contained in the entity.
+ /// The first component type.
+ /// The second component type.
+ /// The third component type.
+ /// True if found, otherwise false.
+ public bool TryGet(
+ out T1 value1,
+ out T2 value2,
+ out T3 value3)
+ {
+ if (this.HasAll())
{
- if (component == null)
- {
- throw new ArgumentNullException(nameof(component));
- }
+ value1 = this.Get();
+ value2 = this.Get();
+ value3 = this.Get();
- if (this.Components.TryGetValue(typeof(T1), out object? value)
- && value is T1
- && value.Equals(component))
- {
- return this;
- }
-
- return this with
- {
- Components = this.Components.SetItem(typeof(T1), component),
- };
+ return true;
}
- ///
- /// Adds a component to the entity.
- ///
- /// The component to register.
- /// The component type.
- ///
- /// The same entity if the component is already registered, otherwise a
- /// cloned entity with the new component.
- ///
- ///
- public Entity Add(T1 component)
+ value1 = default!;
+ value2 = default!;
+ value3 = default!;
+
+ return false;
+ }
+
+ ///
+ /// Attempts to get the values, if present. If not, this returns false
+ /// and the value is undefined. Otherwise, this method returns true
+ /// and the actual value inside that variable.
+ ///
+ /// The value if contained in the entity.
+ /// The value if contained in the entity.
+ /// The value if contained in the entity.
+ /// The value if contained in the entity.
+ /// The first component type.
+ /// The second component type.
+ /// The third component type.
+ /// The fourth component type.
+ /// True if found, otherwise false.
+ public bool TryGet(
+ out T1 value1,
+ out T2 value2,
+ out T3 value3,
+ out T4 value4)
+ {
+ if (this.HasAll())
{
- if (component == null)
- {
- throw new ArgumentNullException(nameof(component));
- }
+ value1 = this.Get();
+ value2 = this.Get();
+ value3 = this.Get();
+ value4 = this.Get();
- if (this.Has())
- {
- throw new ArgumentException(
- "An element with the same type ("
- + typeof(T1).FullName
- + ") already exists.",
- nameof(component));
- }
-
- if (this.Components.TryGetValue(typeof(T1), out object? value)
- && value is T1
- && value.Equals(component))
- {
- return this;
- }
-
- return this with
- {
- Components = this.Components.Add(typeof(T1), component),
- };
+ return true;
}
- ///
- /// Removes a component to the entity.
- ///
- /// The component type.
- ///
- /// The same entity if the component is already removed, otherwise a
- /// cloned entity without the new component.
- ///
- ///
- public Entity Remove()
+ value1 = default!;
+ value2 = default!;
+ value3 = default!;
+ value4 = default!;
+
+ return false;
+ }
+
+ ///
+ /// Sets the component in the entity, regardless if there was a
+ /// component already registered.
+ ///
+ /// The component to register.
+ /// The component type.
+ /// The entity for chaining.
+ ///
+ public Entity Set(T1 component)
+ {
+ if (component == null)
{
- return this.Remove(typeof(TType));
+ throw new ArgumentNullException(nameof(component));
}
- ///
- /// Removes a component to the entity.
- ///
- ///
- /// The same entity if the component is already removed, otherwise a
- /// cloned entity without the new component.
- ///
- /// The component type to remove.
- public Entity Remove(Type type)
+ if (this.Components.TryGetValue(typeof(T1), out object? value)
+ && value is T1
+ && value.Equals(component))
{
- if (!this.Has(type))
- {
- return this;
- }
-
- return this with
- {
- Components = this.Components.Remove(type),
- };
+ return this;
}
- ///
- /// Gets the identifier of the entity. This should be treated as an
- /// opaque field.
- ///
- public int Id { get; private init; }
-
- ///
- /// Creates a copy of the entity, including copying the identifier.
- ///
- ///
- public Entity ExactCopy()
+ return this with
{
- return this with { };
+ Components = this.Components.SetItem(typeof(T1), component)
+ };
+ }
+
+ ///
+ /// Adds a component to the entity.
+ ///
+ /// The component to register.
+ /// The component type.
+ ///
+ /// The same entity if the component is already registered, otherwise a
+ /// cloned entity with the new component.
+ ///
+ ///
+ public Entity Add(T1 component)
+ {
+ if (component == null)
+ {
+ throw new ArgumentNullException(nameof(component));
}
- ///
- /// Creates a copy of the entity, including components, but with a new
- /// identifier.
- ///
- ///
- public Entity Copy()
+ if (this.Has())
{
- return this with
- {
- Id = Interlocked.Increment(ref nextId),
- };
+ throw new ArgumentException(
+ "An element with the same type ("
+ + typeof(T1).FullName
+ + ") already exists.",
+ nameof(component));
}
- ///
- /// Retrieves a list of the component types currently registered in the
- /// Entity.
- ///
- /// An enumerable of the various component keys.
- public IEnumerable GetComponentTypes()
+ if (this.Components.TryGetValue(typeof(T1), out object? value)
+ && value is T1
+ && value.Equals(component))
{
- return this.Components.Keys;
+ return this;
}
+
+ return this with
+ {
+ Components = this.Components.Add(typeof(T1), component)
+ };
+ }
+
+ ///
+ /// Removes a component to the entity.
+ ///
+ /// The component type.
+ ///
+ /// The same entity if the component is already removed, otherwise a
+ /// cloned entity without the new component.
+ ///
+ ///
+ public Entity Remove()
+ {
+ return this.Remove(typeof(TType));
+ }
+
+ ///
+ /// Removes a component to the entity.
+ ///
+ ///
+ /// The same entity if the component is already removed, otherwise a
+ /// cloned entity without the new component.
+ ///
+ /// The component type to remove.
+ public Entity Remove(Type type)
+ {
+ if (!this.Has(type))
+ {
+ return this;
+ }
+
+ return this with
+ {
+ Components = this.Components.Remove(type)
+ };
+ }
+
+ ///
+ /// Gets the identifier of the entity. This should be treated as an
+ /// opaque field.
+ ///
+ public int Id { get; private init; }
+
+ ///
+ /// Creates a copy of the entity, including copying the identifier.
+ ///
+ ///
+ public Entity ExactCopy()
+ {
+ return this with { };
+ }
+
+ ///
+ /// Creates a copy of the entity, including components, but with a new
+ /// identifier.
+ ///
+ ///
+ public Entity Copy()
+ {
+ return this with
+ {
+ Id = Interlocked.Increment(ref nextId)
+ };
+ }
+
+ ///
+ /// Retrieves a list of the component types currently registered in the
+ /// Entity.
+ ///
+ /// An enumerable of the various component keys.
+ public IEnumerable GetComponentTypes()
+ {
+ return this.Components.Keys;
}
}
diff --git a/src/MfGames.Gallium/JoinEntityExtensions.cs b/src/MfGames.Gallium/JoinEntityExtensions.cs
index 3a0bae5..d903a3f 100644
--- a/src/MfGames.Gallium/JoinEntityExtensions.cs
+++ b/src/MfGames.Gallium/JoinEntityExtensions.cs
@@ -2,28 +2,27 @@ using System;
using System.Collections.Generic;
using System.Linq;
-namespace MfGames.Gallium
+namespace MfGames.Gallium;
+
+public static class JoinEntityExtensions
{
- public static class JoinEntityExtensions
+ ///
+ /// Merges two sets of entities using the identifier to determine which
+ /// entities are the same. The `merge` function takes both of the
+ /// entities with the Entity from the `input` first and the one from
+ /// `other` second. The returning entity is put into the collection. If
+ /// an entity from the input is not found in other, then it is just
+ /// passed on.
+ ///
+ /// The enumerable of entities to merge to.
+ /// The collection of entities to merge from.
+ /// The callback to merge the two.
+ /// An sequence of entities, merged and unmerged.
+ public static IEnumerable JoinEntity(
+ this IEnumerable input,
+ ICollection other,
+ Func merge)
{
- ///
- /// Merges two sets of entities using the identifier to determine which
- /// entities are the same. The `merge` function takes both of the
- /// entities with the Entity from the `input` first and the one from
- /// `other` second. The returning entity is put into the collection. If
- /// an entity from the input is not found in other, then it is just
- /// passed on.
- ///
- /// The enumerable of entities to merge to.
- /// The collection of entities to merge from.
- /// The callback to merge the two.
- /// An sequence of entities, merged and unmerged.
- public static IEnumerable JoinEntity(
- this IEnumerable input,
- ICollection other,
- Func merge)
- {
- return input.Join(other, a => a.Id, a => a.Id, merge);
- }
+ return input.Join(other, a => a.Id, a => a.Id, merge);
}
}
diff --git a/src/MfGames.Gallium/SelectComponentExtensions.cs b/src/MfGames.Gallium/SelectComponentExtensions.cs
index 2b881d8..3e28196 100644
--- a/src/MfGames.Gallium/SelectComponentExtensions.cs
+++ b/src/MfGames.Gallium/SelectComponentExtensions.cs
@@ -16,7 +16,8 @@ public static class SelectComponentExtensions
/// The entities to process.
/// The component type being searched.
/// A sequence of T1.
- public static IEnumerable SelectComponent(this IEnumerable entities)
+ public static IEnumerable SelectComponent(
+ this IEnumerable entities)
{
foreach (Entity entity in entities)
{
diff --git a/src/MfGames.Gallium/SelectComponentOrDefaultExtensions.cs b/src/MfGames.Gallium/SelectComponentOrDefaultExtensions.cs
index 74c453f..df74e2a 100644
--- a/src/MfGames.Gallium/SelectComponentOrDefaultExtensions.cs
+++ b/src/MfGames.Gallium/SelectComponentOrDefaultExtensions.cs
@@ -37,7 +37,8 @@ public static class SelectComponentOrDefaultExtensions
/// The entities to process.
/// The component type being searched.
/// A sequence of T1.
- public static IEnumerable SelectComponentOrDefault(this IEnumerable entities)
+ public static IEnumerable SelectComponentOrDefault(
+ this IEnumerable entities)
{
foreach (Entity entity in entities)
{
diff --git a/src/MfGames.Gallium/SelectEntityExtensions.cs b/src/MfGames.Gallium/SelectEntityExtensions.cs
index ee27935..0798db5 100644
--- a/src/MfGames.Gallium/SelectEntityExtensions.cs
+++ b/src/MfGames.Gallium/SelectEntityExtensions.cs
@@ -1,260 +1,279 @@
using System;
using System.Collections.Generic;
-namespace MfGames.Gallium
+namespace MfGames.Gallium;
+
+public static class SelectEntityExtensions
{
- public static class SelectEntityExtensions
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// If true, then entities without all the components are included. Otherwise, they
+ /// are excluded.
+ ///
+ /// The type of the first component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ bool includeEntitiesWithoutComponents = true)
{
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// If true, then entities without all the components are included. Otherwise, they
- /// are excluded.
- ///
- /// The type of the first component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- bool includeEntitiesWithoutComponents = true)
- {
- return entities.SelectEntity(selectWithComponents, includeEntitiesWithoutComponents ? a => a : a => null);
- }
+ return entities.SelectEntity(
+ selectWithComponents,
+ includeEntitiesWithoutComponents ? a => a : a => null);
+ }
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// If true, then entities without all the components are included. Otherwise, they
- /// are excluded.
- ///
- /// The type of the first component.
- /// The type of the second component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- bool includeEntitiesWithoutComponents = true)
- {
- return entities.SelectEntity(selectWithComponents, includeEntitiesWithoutComponents ? a => a : a => null);
- }
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// If true, then entities without all the components are included. Otherwise, they
+ /// are excluded.
+ ///
+ /// The type of the first component.
+ /// The type of the second component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ bool includeEntitiesWithoutComponents = true)
+ {
+ return entities.SelectEntity(
+ selectWithComponents,
+ includeEntitiesWithoutComponents ? a => a : a => null);
+ }
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// If true, then entities without all the components are included. Otherwise, they
- /// are excluded.
- ///
- /// The type of the first component.
- /// The type of the second component.
- /// The type of the third component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- bool includeEntitiesWithoutComponents = true)
- {
- return entities.SelectEntity(selectWithComponents, includeEntitiesWithoutComponents ? a => a : a => null);
- }
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// If true, then entities without all the components are included. Otherwise, they
+ /// are excluded.
+ ///
+ /// The type of the first component.
+ /// The type of the second component.
+ /// The type of the third component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ bool includeEntitiesWithoutComponents = true)
+ {
+ return entities.SelectEntity(
+ selectWithComponents,
+ includeEntitiesWithoutComponents ? a => a : a => null);
+ }
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// If true, then entities without all the components are included. Otherwise, they
- /// are excluded.
- ///
- /// The type of the first component.
- /// The type of the second component.
- /// The type of the third component.
- /// The type of the fourth component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- bool includeEntitiesWithoutComponents = true)
- {
- return entities.SelectEntity(selectWithComponents, includeEntitiesWithoutComponents ? a => a : a => null);
- }
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// If true, then entities without all the components are included. Otherwise, they
+ /// are excluded.
+ ///
+ /// The type of the first component.
+ /// The type of the second component.
+ /// The type of the third component.
+ /// The type of the fourth component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ bool includeEntitiesWithoutComponents = true)
+ {
+ return entities.SelectEntity(
+ selectWithComponents,
+ includeEntitiesWithoutComponents ? a => a : a => null);
+ }
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// The optional transformation function for entities that do not have all the
- /// components. If returns null,
- /// then the entity will not be included.
- ///
- /// The type of the first component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- Func selectWithoutComponents)
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// The optional transformation function for entities that do not have all the
+ /// components. If returns null,
+ /// then the entity will not be included.
+ ///
+ /// The type of the first component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ Func selectWithoutComponents)
+ {
+ foreach (Entity entity in entities)
{
- foreach (Entity entity in entities)
+ Entity? result = entity.TryGet(out T1 value1)
+ ? selectWithComponents?.Invoke(entity, value1)
+ : selectWithoutComponents?.Invoke(entity);
+
+ if (result != null)
{
- Entity? result = entity.TryGet(out T1 value1)
- ? selectWithComponents?.Invoke(entity, value1)
- : selectWithoutComponents?.Invoke(entity);
-
- if (result != null)
- {
- yield return result;
- }
+ yield return result;
}
}
+ }
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// The optional transformation function for entities that do not have all the
- /// components. If returns null,
- /// then the entity will not be included.
- ///
- /// The type of the first component.
- /// The type of the second component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- Func selectWithoutComponents)
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// The optional transformation function for entities that do not have all the
+ /// components. If returns null,
+ /// then the entity will not be included.
+ ///
+ /// The type of the first component.
+ /// The type of the second component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ Func selectWithoutComponents)
+ {
+ foreach (Entity entity in entities)
{
- foreach (Entity entity in entities)
- {
- Entity? result = entity.TryGet(out T1 value1) && entity.TryGet(out T2 value2)
+ Entity? result = entity.TryGet(out T1 value1)
+ && entity.TryGet(out T2 value2)
? selectWithComponents?.Invoke(entity, value1, value2)
: selectWithoutComponents?.Invoke(entity);
- if (result != null)
- {
- yield return result;
- }
+ if (result != null)
+ {
+ yield return result;
}
}
+ }
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// The optional transformation function for entities that do not have all the
- /// components. If returns null,
- /// then the entity will not be included.
- ///
- /// The type of the first component.
- /// The type of the second component.
- /// The type of the third component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- Func selectWithoutComponents)
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// The optional transformation function for entities that do not have all the
+ /// components. If returns null,
+ /// then the entity will not be included.
+ ///
+ /// The type of the first component.
+ /// The type of the second component.
+ /// The type of the third component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ Func selectWithoutComponents)
+ {
+ foreach (Entity entity in entities)
{
- foreach (Entity entity in entities)
- {
- Entity? result =
- entity.TryGet(out T1 value1) && entity.TryGet(out T2 value2) && entity.TryGet(out T3 value3)
- ? selectWithComponents?.Invoke(entity, value1, value2, value3)
- : selectWithoutComponents?.Invoke(entity);
+ Entity? result =
+ entity.TryGet(out T1 value1)
+ && entity.TryGet(out T2 value2)
+ && entity.TryGet(out T3 value3)
+ ? selectWithComponents?.Invoke(
+ entity,
+ value1,
+ value2,
+ value3)
+ : selectWithoutComponents?.Invoke(entity);
- if (result != null)
- {
- yield return result;
- }
+ if (result != null)
+ {
+ yield return result;
}
}
+ }
- ///
- /// Selects an entity from the given list, filtering on entities with
- /// the given components.
- ///
- /// The entities to parse.
- ///
- /// The transformation function for the entity and selected components. If this
- /// returns null, then the entity
- /// will be filtered out.
- ///
- ///
- /// The optional transformation function for entities that do not have all the
- /// components. If returns null,
- /// then the entity will not be included.
- ///
- /// The type of the first component.
- /// The type of the second component.
- /// The type of the third component.
- /// The type of the third component.
- /// An enumeration of transformed entities.
- public static IEnumerable SelectEntity(
- this IEnumerable entities,
- Func selectWithComponents,
- Func selectWithoutComponents)
+ ///
+ /// Selects an entity from the given list, filtering on entities with
+ /// the given components.
+ ///
+ /// The entities to parse.
+ ///
+ /// The transformation function for the entity and selected components. If this
+ /// returns null, then the entity
+ /// will be filtered out.
+ ///
+ ///
+ /// The optional transformation function for entities that do not have all the
+ /// components. If returns null,
+ /// then the entity will not be included.
+ ///
+ /// The type of the first component.
+ /// The type of the second component.
+ /// The type of the third component.
+ /// The type of the third component.
+ /// An enumeration of transformed entities.
+ public static IEnumerable SelectEntity(
+ this IEnumerable entities,
+ Func selectWithComponents,
+ Func selectWithoutComponents)
+ {
+ foreach (Entity entity in entities)
{
- foreach (Entity entity in entities)
- {
- Entity? result =
- entity.TryGet(out T1 value1)
- && entity.TryGet(out T2 value2)
- && entity.TryGet(out T3 value3)
- && entity.TryGet(out T4 value4)
- ? selectWithComponents?.Invoke(entity, value1, value2, value3, value4)
- : selectWithoutComponents?.Invoke(entity);
+ Entity? result =
+ entity.TryGet(out T1 value1)
+ && entity.TryGet(out T2 value2)
+ && entity.TryGet(out T3 value3)
+ && entity.TryGet(out T4 value4)
+ ? selectWithComponents?.Invoke(
+ entity,
+ value1,
+ value2,
+ value3,
+ value4)
+ : selectWithoutComponents?.Invoke(entity);
- if (result != null)
- {
- yield return result;
- }
+ if (result != null)
+ {
+ yield return result;
}
}
}
diff --git a/src/MfGames.Gallium/SplitEntityExtensions.cs b/src/MfGames.Gallium/SplitEntityExtensions.cs
index 43333ec..41fc301 100644
--- a/src/MfGames.Gallium/SplitEntityExtensions.cs
+++ b/src/MfGames.Gallium/SplitEntityExtensions.cs
@@ -189,7 +189,9 @@ public static class SplitEntityExtensions
Type t1,
Func test)
{
- return SplitEntity(entities, a => a.Has(t1) && test(a, a.Get