From 9bf1ad71b43e41a3dfe645ccf66c6fb6b2e96242 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 21 Nov 2016 22:09:02 -0500 Subject: intercept event handler exceptions (#179) --- src/StardewModdingAPI/Events/TimeEvents.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/StardewModdingAPI/Events/TimeEvents.cs') diff --git a/src/StardewModdingAPI/Events/TimeEvents.cs b/src/StardewModdingAPI/Events/TimeEvents.cs index 0481ad48..1b367230 100644 --- a/src/StardewModdingAPI/Events/TimeEvents.cs +++ b/src/StardewModdingAPI/Events/TimeEvents.cs @@ -1,4 +1,5 @@ using System; +using StardewModdingAPI.Framework; namespace StardewModdingAPI.Events { @@ -28,44 +29,49 @@ namespace StardewModdingAPI.Events ** 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(int priorTime, int newTime) + internal static void InvokeTimeOfDayChanged(IMonitor monitor, int priorTime, int newTime) { - TimeEvents.TimeOfDayChanged?.Invoke(null, new EventArgsIntChanged(priorTime, 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(int priorDay, int newDay) + internal static void InvokeDayOfMonthChanged(IMonitor monitor, int priorDay, int newDay) { - TimeEvents.DayOfMonthChanged?.Invoke(null, new EventArgsIntChanged(priorDay, 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(int priorYear, int newYear) + internal static void InvokeYearOfGameChanged(IMonitor monitor, int priorYear, int newYear) { - TimeEvents.YearOfGameChanged?.Invoke(null, new EventArgsIntChanged(priorYear, 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(string priorSeason, string newSeason) + internal static void InvokeSeasonOfYearChanged(IMonitor monitor, string priorSeason, string newSeason) { - TimeEvents.SeasonOfYearChanged?.Invoke(null, new EventArgsStringChanged(priorSeason, 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(int priorDay, int newDay, bool isTransitioning) + internal static void InvokeOnNewDay(IMonitor monitor, int priorDay, int newDay, bool isTransitioning) { - TimeEvents.OnNewDay?.Invoke(null, new EventArgsNewDay(priorDay, newDay, isTransitioning)); + monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", TimeEvents.OnNewDay?.GetInvocationList(), null, new EventArgsNewDay(priorDay, newDay, isTransitioning)); } } } -- cgit