using System.Collections.Generic; using System.Linq; using MfGames.Gallium; namespace MfGames.Nitride.Temporal.Schedules; /// /// An indexed-based schedule that uses the regular expression to get a /// numerical value and then uses that to determine the schedule. /// public partial class IndexedPathRegexSchedule : PathRegexScheduleBase where TSchedule : IndexedSchedule { public IndexedPathRegexSchedule() { this.Indexes = new Dictionary(); } /// /// Gets or sets the dictionary that indexes the various numerical indexes /// to provide the scheduling. /// public Dictionary Indexes { get; set; } public IndexedPathRegexSchedule WithIndexes( Dictionary value) { this.Indexes = value; return this; } /// protected override Entity Apply( Entity entity, int number, TimeService timeService) { // Figure out the entry in the index. var applicableKeys = this.Indexes.Keys .Where(a => a <= number) .ToList(); if (applicableKeys.Count == 0) { return entity; } int startIndex = applicableKeys.Max(a => a); TSchedule schedule = this.Indexes[startIndex]; // Pass everything into the schedule to perform the applying. int startOffset = number - startIndex; return schedule.Apply(entity, startOffset, timeService); } }