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-nitride-cil/src/MfGames.Nitride.Temporal/FilterOutFutureInstant.cs

37 lines
886 B
C#

using System.Collections.Generic;
using MfGames.Gallium;
using MfGames.Nitride.Generators;
using NodaTime;
namespace MfGames.Nitride.Temporal;
/// <summary>
/// Filters out all entities that have an instant before the current
/// NitrideClock time.
/// </summary>
[WithProperties]
public partial class FilterOutFutureInstant : OperationBase
{
public FilterOutFutureInstant(Timekeeper timekeeper)
{
this.Timekeeper = timekeeper;
}
public Timekeeper Timekeeper { get; set; }
/// <inheritdoc />
public override IEnumerable<Entity> Run(IEnumerable<Entity> input)
{
Instant now = this.Timekeeper.Clock.GetCurrentInstant();
return input
.SelectEntity<Instant>(
(
entity,
instant) =>
instant.CompareTo(now) <= 0 ? entity : null);
}
}