using System; using MfGames.Gallium; using MfGames.Nitride.Generators; using NodaTime; namespace MfGames.Nitride.Temporal.Schedules; /// /// A schedule that goes against all entities it is applied to. /// [WithProperties] public partial class SimplePathSchedule : ISchedule { /// /// Gets or sets when the first item is scheduled. /// public DateTime? ScheduleStart { get; set; } /// public virtual Entity Apply( Entity entity, TimeService timeService) { DateTime start = this.ScheduleStart ?? throw new NullReferenceException( "Cannot use a schedule without a start date."); Instant instant = timeService.CreateInstant(start); // If the time hasn't past, then we don't apply it. Instant now = timeService.Clock.GetCurrentInstant(); return instant > now ? entity : this.Apply(entity, instant); } /// public virtual bool CanApply(Entity entity) { return true; } protected virtual Entity Apply( Entity entity, Instant instant) { return entity.Set(instant); } }