52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using System;
|
|
|
|
using MfGames.Gallium;
|
|
using MfGames.Nitride.Generators;
|
|
|
|
using NodaTime;
|
|
|
|
namespace MfGames.Nitride.Temporal.Schedules;
|
|
|
|
/// <summary>
|
|
/// A schedule that goes against all entities it is applied to.
|
|
/// </summary>
|
|
[WithProperties]
|
|
public partial class SimplePathSchedule : ISchedule
|
|
{
|
|
/// <summary>
|
|
/// Gets or sets when the first item is scheduled.
|
|
/// </summary>
|
|
public DateTime? ScheduleStart { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
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);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual bool CanApply(Entity entity)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected virtual Entity Apply(
|
|
Entity entity,
|
|
Instant instant)
|
|
{
|
|
return entity.Set(instant);
|
|
}
|
|
}
|