49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using HSchool.Content;
|
|
|
|
namespace HSchool.Simulation;
|
|
|
|
/// <summary>
|
|
/// Turns clock edges into world facts. One dayStart per morning crossing, one lessonStart per
|
|
/// school when the bell enters a lesson period — not one per class.
|
|
/// </summary>
|
|
internal static class EventSystem
|
|
{
|
|
public static IReadOnlyList<WorldEvent> Detect(School school, DateTime before, DateTime after)
|
|
{
|
|
if (school.Catalog is null || after <= before)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
var facts = new List<WorldEvent>(2);
|
|
if (CrossedWorkMorning(school.Catalog, before, after, school.SchoolWeekDays))
|
|
{
|
|
facts.Add(new WorldEvent(EventTriggers.DayStart));
|
|
}
|
|
|
|
if (EnteredLessonPeriod(school.Catalog, before, after, school.SchoolWeekDays))
|
|
{
|
|
facts.Add(new WorldEvent(EventTriggers.LessonStart));
|
|
}
|
|
|
|
return facts;
|
|
}
|
|
|
|
private static bool CrossedWorkMorning(DefCatalog catalog, DateTime before, DateTime after, int weekDays)
|
|
{
|
|
if (!PersonDayLog.CrossedDayStart(before, after))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return SchoolDay.IsWorkday(catalog, after, weekDays);
|
|
}
|
|
|
|
private static bool EnteredLessonPeriod(DefCatalog catalog, DateTime before, DateTime after, int weekDays)
|
|
{
|
|
var beforeSlot = SchoolDay.At(catalog, before, weekDays);
|
|
var afterSlot = SchoolDay.At(catalog, after, weekDays);
|
|
return afterSlot.Kind == DaySlotKind.Lesson && beforeSlot != afterSlot;
|
|
}
|
|
}
|