using System; using StardewModdingAPI.Framework; namespace StardewModdingAPI.Events { /// Events raised when the in-game date or time changes. public static class TimeEvents { /********* ** Events *********/ /// Raised after the in-game clock changes. public static event EventHandler TimeOfDayChanged; /// Raised after the day-of-month value changes, including when loading a save (unlike ). public static event EventHandler DayOfMonthChanged; /// Raised after the year value changes. public static event EventHandler YearOfGameChanged; /// Raised after the season value changes. public static event EventHandler SeasonOfYearChanged; /// Raised when the player is transitioning to a new day and the game is performing its day update logic. This event is triggered twice: once after the game starts transitioning, and again after it finishes. public static event EventHandler OnNewDay; /********* ** Internal methods *********/ /// Raise a event. /// Encapsulates monitoring and logging. /// The previous time in military time format (e.g. 6:00pm is 1800). /// The current time in military time format (e.g. 6:10pm is 1810). internal static void InvokeTimeOfDayChanged(IMonitor monitor, int priorTime, int newTime) { monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.TimeOfDayChanged)}", TimeEvents.TimeOfDayChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorTime, newTime)); } /// Raise a event. /// Encapsulates monitoring and logging. /// The previous day value. /// The current day value. internal static void InvokeDayOfMonthChanged(IMonitor monitor, int priorDay, int newDay) { monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.DayOfMonthChanged)}", TimeEvents.DayOfMonthChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorDay, newDay)); } /// Raise a event. /// Encapsulates monitoring and logging. /// The previous year value. /// The current year value. internal static void InvokeYearOfGameChanged(IMonitor monitor, int priorYear, int newYear) { monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.YearOfGameChanged)}", TimeEvents.YearOfGameChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorYear, newYear)); } /// Raise a event. /// Encapsulates monitoring and logging. /// The previous season name. /// The current season name. internal static void InvokeSeasonOfYearChanged(IMonitor monitor, string priorSeason, string newSeason) { monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.SeasonOfYearChanged)}", TimeEvents.SeasonOfYearChanged?.GetInvocationList(), null, new EventArgsStringChanged(priorSeason, newSeason)); } /// Raise a event. /// Encapsulates monitoring and logging. /// The previous day value. /// The current day value. /// Whether the game just started the transition (true) or finished it (false). internal static void InvokeOnNewDay(IMonitor monitor, int priorDay, int newDay, bool isTransitioning) { monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", TimeEvents.OnNewDay?.GetInvocationList(), null, new EventArgsNewDay(priorDay, newDay, isTransitioning)); } } }