using System;
using System.Collections.Generic;
using System.Linq;
namespace MfGames.Gallium;
///
/// An extension method that handle SelectManyEntity which extracts all the
/// entities that match the given components,
/// passes the results to a select many callback, and then optionally includes the
/// ones that didn't have the components
/// before return.
///
public static class SelectManyEntityExtensions
{
///
/// Pulls out all the entities that match the given components into an enumeration,
/// passes it into the callback
/// function, and then optionally merges the entities that did not match before
/// returning.
///
/// The entities to process
///
/// The callback function to manipulate the list of
/// entities.
///
///
/// If true, the include entities
/// without components.
///
/// The type of the first component.
/// An enumeration of entities.
public static IEnumerable SelectManyEntity(
this IEnumerable entities,
Func, IEnumerable> selectMany,
bool includeEntitiesWithoutComponents = true)
{
SplitEntityEnumerations split = entities.SplitEntity();
IEnumerable results = selectMany(split.HasAll);
if (includeEntitiesWithoutComponents)
{
results = results.Union(split.NotHasAll);
}
return results;
}
///
/// Pulls out all the entities that match the given components into an enumeration,
/// passes it into the callback
/// function, and then optionally merges the entities that did not match before
/// returning.
///
/// The entities to process
///
/// The callback function to manipulate the list of
/// entities.
///
///
/// If true, the include entities
/// without components.
///
/// The type of the first component.
/// The type of the second component.
/// An enumeration of entities.
public static IEnumerable SelectManyEntity(
this IEnumerable entities,
Func, IEnumerable> selectMany,
bool includeEntitiesWithoutComponents = true)
{
SplitEntityEnumerations split = entities.SplitEntity();
IEnumerable results = selectMany(split.HasAll);
if (includeEntitiesWithoutComponents)
{
results = results.Union(split.NotHasAll);
}
return results;
}
///
/// Pulls out all the entities that match the given components into an enumeration,
/// passes it into the callback
/// function, and then optionally merges the entities that did not match before
/// returning.
///
/// The entities to process
///
/// The callback function to manipulate the list of
/// entities.
///
///
/// If true, the include entities
/// without components.
///
/// The type of the first component.
/// The type of the second component.
/// The type of the second component.
/// An enumeration of entities.
public static IEnumerable SelectManyEntity(
this IEnumerable entities,
Func, IEnumerable> selectMany,
bool includeEntitiesWithoutComponents = true)
{
SplitEntityEnumerations split = entities.SplitEntity();
IEnumerable results = selectMany(split.HasAll);
if (includeEntitiesWithoutComponents)
{
results = results.Union(split.NotHasAll);
}
return results;
}
///
/// Pulls out all the entities that match the given components into an enumeration,
/// passes it into the callback
/// function, and then optionally merges the entities that did not match before
/// returning.
///
/// The entities to process
///
/// The callback function to manipulate the list of
/// entities.
///
///
/// If true, the include entities
/// without components.
///
/// The type of the first component.
/// The type of the second component.
/// The type of the second component.
/// The type of the second component.
/// An enumeration of entities.
public static IEnumerable SelectManyEntity(
this IEnumerable entities,
Func, IEnumerable> selectMany,
bool includeEntitiesWithoutComponents = true)
{
SplitEntityEnumerations split = entities.SplitEntity();
IEnumerable results = selectMany(split.HasAll);
if (includeEntitiesWithoutComponents)
{
results = results.Union(split.NotHasAll);
}
return results;
}
}