This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-gallium-cil/src/Gallium/ForEntityExtensions.cs
2022-07-06 01:34:51 -05:00

93 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
namespace Gallium
{
public static class ForEntityExtensions
{
/// <summary>
/// Selects an entity from the given list, filtering on entities with
/// the given components. If the entity doesn't match, it is passed as it.
/// </summary>
/// <param name="entities">The entities to parse.</param>
/// <param name="selectWithComponents">
/// The transformation function for the entity
/// and selected components. If this returns null, then the entity will be filtered
/// out.
/// </param>
/// <typeparam name="T1">The type of the first component.</typeparam>
/// <returns>An enumeration of transformed entities.</returns>
public static IEnumerable<Entity> ForEntity<T1>(
this IEnumerable<Entity> entities,
Func<Entity, T1, Entity?> selectWithComponents)
{
return entities.SelectEntity(selectWithComponents, a => a);
}
/// <summary>
/// Selects an entity from the given list, filtering on entities with
/// the given components. If the entity doesn't match, it is passed as it.
/// </summary>
/// <param name="entities">The entities to parse.</param>
/// <param name="selectWithComponents">
/// The transformation function for the entity
/// and selected components. If this returns null, then the entity will be filtered
/// out.
/// </param>
/// <typeparam name="T1">The type of the first component.</typeparam>
/// <typeparam name="T2">The type of the second component.</typeparam>
/// <returns>An enumeration of transformed entities.</returns>
public static IEnumerable<Entity> ForEntity<T1, T2>(
this IEnumerable<Entity> entities,
Func<Entity, T1, T2, Entity?> selectWithComponents)
{
return entities.SelectEntity(selectWithComponents, a => a);
}
/// <summary>
/// Selects an entity from the given list, filtering on entities with
/// the given components. If the entity doesn't match, it is passed as it.
/// </summary>
/// <param name="entities">The entities to parse.</param>
/// <param name="selectWithComponents">
/// The transformation function for the entity
/// and selected components. If this returns null, then the entity will be filtered
/// out.
/// </param>
/// <typeparam name="T1">The type of the first component.</typeparam>
/// <typeparam name="T2">The type of the second component.</typeparam>
/// <typeparam name="T3">The type of the third component.</typeparam>
/// <returns>An enumeration of transformed entities.</returns>
public static IEnumerable<Entity> ForEntity<T1, T2, T3>(
this IEnumerable<Entity> entities,
Func<Entity, T1, T2, T3, Entity?> selectWithComponents)
{
return entities.SelectEntity(selectWithComponents, a => a);
}
/// <summary>
/// Selects an entity from the given list, filtering on entities with
/// the given components. If the entity doesn't match, it is passed as it.
/// </summary>
/// <param name="entities">The entities to parse.</param>
/// <param name="selectWithComponents">
/// The transformation function for the entity
/// and selected components. If this returns null, then the entity will be filtered
/// out.
/// </param>
/// <typeparam name="T1">The type of the first component.</typeparam>
/// <typeparam name="T2">The type of the second component.</typeparam>
/// <typeparam name="T3">The type of the third component.</typeparam>
/// <typeparam name="T4">The type of the third component.</typeparam>
/// <returns>An enumeration of transformed entities.</returns>
public static IEnumerable<Entity> ForEntity<T1, T2, T3, T4>(
this IEnumerable<Entity> entities,
Func<Entity, T1, T2, T3, T4, Entity?> selectWithComponents)
{
return entities.SelectEntity<T1, T2, T3, T4>(
selectWithComponents,
a => a);
}
}
}