diff options
Diffstat (limited to 'src/StardewModdingAPI/Events')
-rw-r--r-- | src/StardewModdingAPI/Events/ControlEvents.cs | 41 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/GameEvents.cs | 68 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/GraphicsEvents.cs | 97 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/LocationEvents.cs | 16 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/MenuEvents.cs | 11 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/MineEvents.cs | 6 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/PlayerEvents.cs | 21 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/TimeEvents.cs | 26 |
8 files changed, 144 insertions, 142 deletions
diff --git a/src/StardewModdingAPI/Events/ControlEvents.cs b/src/StardewModdingAPI/Events/ControlEvents.cs index b7f69805..790bf193 100644 --- a/src/StardewModdingAPI/Events/ControlEvents.cs +++ b/src/StardewModdingAPI/Events/ControlEvents.cs @@ -1,6 +1,7 @@ using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Framework; namespace StardewModdingAPI.Events { @@ -39,69 +40,77 @@ namespace StardewModdingAPI.Events ** Internal methods *********/ /// <summary>Raise a <see cref="KeyboardChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorState">The previous keyboard state.</param> /// <param name="newState">The current keyboard state.</param> - internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) + internal static void InvokeKeyboardChanged(IMonitor monitor, KeyboardState priorState, KeyboardState newState) { - ControlEvents.KeyboardChanged?.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyboardChanged)}", ControlEvents.KeyboardChanged?.GetInvocationList(), null, new EventArgsKeyboardStateChanged(priorState, newState)); } /// <summary>Raise a <see cref="MouseChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorState">The previous mouse state.</param> /// <param name="newState">The current mouse state.</param> /// <param name="priorPosition">The previous mouse position on the screen adjusted for the zoom level.</param> /// <param name="newPosition">The current mouse position on the screen adjusted for the zoom level.</param> - internal static void InvokeMouseChanged(MouseState priorState, MouseState newState, Point priorPosition, Point newPosition) + internal static void InvokeMouseChanged(IMonitor monitor, MouseState priorState, MouseState newState, Point priorPosition, Point newPosition) { - ControlEvents.MouseChanged?.Invoke(null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.MouseChanged)}", ControlEvents.MouseChanged?.GetInvocationList(), null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); } /// <summary>Raise a <see cref="KeyPressed"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="key">The keyboard button that was pressed.</param> - internal static void InvokeKeyPressed(Keys key) + internal static void InvokeKeyPressed(IMonitor monitor, Keys key) { - ControlEvents.KeyPressed?.Invoke(null, new EventArgsKeyPressed(key)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyPressed)}", ControlEvents.KeyPressed?.GetInvocationList(), null, new EventArgsKeyPressed(key)); } /// <summary>Raise a <see cref="KeyReleased"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="key">The keyboard button that was released.</param> - internal static void InvokeKeyReleased(Keys key) + internal static void InvokeKeyReleased(IMonitor monitor, Keys key) { - ControlEvents.KeyReleased?.Invoke(null, new EventArgsKeyPressed(key)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.KeyReleased)}", ControlEvents.KeyReleased?.GetInvocationList(), null, new EventArgsKeyPressed(key)); } /// <summary>Raise a <see cref="ControllerButtonPressed"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="playerIndex">The player who pressed the button.</param> /// <param name="button">The controller button that was pressed.</param> - internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons button) + internal static void InvokeButtonPressed(IMonitor monitor, PlayerIndex playerIndex, Buttons button) { - ControlEvents.ControllerButtonPressed?.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, button)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonPressed)}", ControlEvents.ControllerButtonPressed?.GetInvocationList(), null, new EventArgsControllerButtonPressed(playerIndex, button)); } /// <summary>Raise a <see cref="ControllerButtonReleased"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="playerIndex">The player who released the button.</param> /// <param name="button">The controller button that was released.</param> - internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons button) + internal static void InvokeButtonReleased(IMonitor monitor, PlayerIndex playerIndex, Buttons button) { - ControlEvents.ControllerButtonReleased?.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, button)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonReleased)}", ControlEvents.ControllerButtonReleased?.GetInvocationList(), null, new EventArgsControllerButtonReleased(playerIndex, button)); } /// <summary>Raise a <see cref="ControllerTriggerPressed"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="playerIndex">The player who pressed the trigger button.</param> /// <param name="button">The trigger button that was pressed.</param> /// <param name="value">The current trigger value.</param> - internal static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons button, float value) + internal static void InvokeTriggerPressed(IMonitor monitor, PlayerIndex playerIndex, Buttons button, float value) { - ControlEvents.ControllerTriggerPressed?.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, button, value)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerPressed)}", ControlEvents.ControllerTriggerPressed?.GetInvocationList(), null, new EventArgsControllerTriggerPressed(playerIndex, button, value)); } /// <summary>Raise a <see cref="ControllerTriggerReleased"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="playerIndex">The player who pressed the trigger button.</param> /// <param name="button">The trigger button that was pressed.</param> /// <param name="value">The current trigger value.</param> - internal static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons button, float value) + internal static void InvokeTriggerReleased(IMonitor monitor, PlayerIndex playerIndex, Buttons button, float value) { - ControlEvents.ControllerTriggerReleased?.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, button, value)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerReleased)}", ControlEvents.ControllerTriggerReleased?.GetInvocationList(), null, new EventArgsControllerTriggerReleased(playerIndex, button, value)); } } } diff --git a/src/StardewModdingAPI/Events/GameEvents.cs b/src/StardewModdingAPI/Events/GameEvents.cs index 46505d14..715083b9 100644 --- a/src/StardewModdingAPI/Events/GameEvents.cs +++ b/src/StardewModdingAPI/Events/GameEvents.cs @@ -1,4 +1,5 @@ using System; +using StardewModdingAPI.Framework; namespace StardewModdingAPI.Events { @@ -46,93 +47,80 @@ namespace StardewModdingAPI.Events ** Internal methods *********/ /// <summary>Raise a <see cref="GameLoaded"/> event.</summary> - internal static void InvokeGameLoaded() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeGameLoaded(IMonitor monitor) { - GameEvents.GameLoaded?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", GameEvents.GameLoaded?.GetInvocationList()); } /// <summary>Raise an <see cref="Initialize"/> event.</summary> /// <param name="monitor">Encapsulates logging and monitoring.</param> internal static void InvokeInitialize(IMonitor monitor) { - try - { - GameEvents.Initialize?.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - monitor.Log($"A mod crashed handling an event.\n{ex}", LogLevel.Error); - } + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.Initialize)}", GameEvents.Initialize?.GetInvocationList()); } /// <summary>Raise a <see cref="LoadContent"/> event.</summary> /// <param name="monitor">Encapsulates logging and monitoring.</param> internal static void InvokeLoadContent(IMonitor monitor) { - try - { - GameEvents.LoadContent?.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - monitor.Log($"A mod crashed handling an event.\n{ex}", LogLevel.Error); - } + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.LoadContent)}", GameEvents.LoadContent?.GetInvocationList()); } /// <summary>Raise an <see cref="UpdateTick"/> event.</summary> /// <param name="monitor">Encapsulates logging and monitoring.</param> internal static void InvokeUpdateTick(IMonitor monitor) { - try - { - GameEvents.UpdateTick?.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - monitor.Log($"A mod crashed handling an event.\n{ex}", LogLevel.Error); - } + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.UpdateTick)}", GameEvents.UpdateTick?.GetInvocationList()); } /// <summary>Raise a <see cref="SecondUpdateTick"/> event.</summary> - internal static void InvokeSecondUpdateTick() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeSecondUpdateTick(IMonitor monitor) { - GameEvents.SecondUpdateTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.SecondUpdateTick)}", GameEvents.SecondUpdateTick?.GetInvocationList()); } /// <summary>Raise a <see cref="FourthUpdateTick"/> event.</summary> - internal static void InvokeFourthUpdateTick() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeFourthUpdateTick(IMonitor monitor) { - GameEvents.FourthUpdateTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.FourthUpdateTick)}", GameEvents.FourthUpdateTick?.GetInvocationList()); } /// <summary>Raise a <see cref="EighthUpdateTick"/> event.</summary> - internal static void InvokeEighthUpdateTick() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeEighthUpdateTick(IMonitor monitor) { - GameEvents.EighthUpdateTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.EighthUpdateTick)}", GameEvents.EighthUpdateTick?.GetInvocationList()); } /// <summary>Raise a <see cref="QuarterSecondTick"/> event.</summary> - internal static void InvokeQuarterSecondTick() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeQuarterSecondTick(IMonitor monitor) { - GameEvents.QuarterSecondTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.QuarterSecondTick)}", GameEvents.QuarterSecondTick?.GetInvocationList()); } /// <summary>Raise a <see cref="HalfSecondTick"/> event.</summary> - internal static void InvokeHalfSecondTick() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeHalfSecondTick(IMonitor monitor) { - GameEvents.HalfSecondTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.HalfSecondTick)}", GameEvents.HalfSecondTick?.GetInvocationList()); } /// <summary>Raise a <see cref="OneSecondTick"/> event.</summary> - internal static void InvokeOneSecondTick() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOneSecondTick(IMonitor monitor) { - GameEvents.OneSecondTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.OneSecondTick)}", GameEvents.OneSecondTick?.GetInvocationList()); } /// <summary>Raise a <see cref="FirstUpdateTick"/> event.</summary> - internal static void InvokeFirstUpdateTick() + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeFirstUpdateTick(IMonitor monitor) { - GameEvents.FirstUpdateTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.FirstUpdateTick)}", GameEvents.FirstUpdateTick?.GetInvocationList()); } } } diff --git a/src/StardewModdingAPI/Events/GraphicsEvents.cs b/src/StardewModdingAPI/Events/GraphicsEvents.cs index 3f52212b..5f4feeac 100644 --- a/src/StardewModdingAPI/Events/GraphicsEvents.cs +++ b/src/StardewModdingAPI/Events/GraphicsEvents.cs @@ -1,4 +1,5 @@ using System; +using StardewModdingAPI.Framework; namespace StardewModdingAPI.Events { @@ -72,19 +73,19 @@ namespace StardewModdingAPI.Events ** Generic events ****/ /// <summary>Raise a <see cref="Resize"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="sender">The object which raised the event.</param> /// <param name="e">The event arguments.</param> - internal static void InvokeResize(object sender, EventArgs e) + internal static void InvokeResize(IMonitor monitor, object sender, EventArgs e) { - GraphicsEvents.Resize?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.Resize)}", GraphicsEvents.Resize?.GetInvocationList(), sender, e); } /// <summary>Raise a <see cref="DrawDebug"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeDrawDebug(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeDrawDebug(IMonitor monitor) { - GraphicsEvents.DrawDebug?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.DrawDebug)}", GraphicsEvents.DrawDebug?.GetInvocationList()); } /// <summary>Raise a <see cref="DrawTick"/> event.</summary> @@ -92,110 +93,94 @@ namespace StardewModdingAPI.Events [Obsolete("Should not be used.")] public static void InvokeDrawTick(IMonitor monitor) { - try - { - GraphicsEvents.DrawTick?.Invoke(null, EventArgs.Empty); - } - catch (Exception ex) - { - monitor.Log($"A mod crashed handling an event.\n{ex}", LogLevel.Error); - } + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.DrawTick)}", GraphicsEvents.DrawTick?.GetInvocationList()); } /// <summary>Raise a <see cref="DrawInRenderTargetTick"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> [Obsolete("Should not be used.")] - public static void InvokeDrawInRenderTargetTick() + public static void InvokeDrawInRenderTargetTick(IMonitor monitor) { - GraphicsEvents.DrawInRenderTargetTick?.Invoke(null, EventArgs.Empty); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.DrawInRenderTargetTick)}", GraphicsEvents.DrawInRenderTargetTick?.GetInvocationList()); } /**** ** Main render events ****/ /// <summary>Raise an <see cref="OnPreRenderEvent"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPreRenderEvent(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPreRenderEvent(IMonitor monitor) { - GraphicsEvents.OnPreRenderEvent?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderEvent)}", GraphicsEvents.OnPreRenderEvent?.GetInvocationList()); } /// <summary>Raise an <see cref="OnPostRenderEvent"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPostRenderEvent(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPostRenderEvent(IMonitor monitor) { - GraphicsEvents.OnPostRenderEvent?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderEvent)}", GraphicsEvents.OnPostRenderEvent?.GetInvocationList()); } /**** ** HUD events ****/ /// <summary>Raise an <see cref="OnPreRenderGuiEvent"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPreRenderGuiEvent(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPreRenderGuiEvent(IMonitor monitor) { - GraphicsEvents.OnPreRenderGuiEvent?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderGuiEvent)}", GraphicsEvents.OnPreRenderGuiEvent?.GetInvocationList()); } /// <summary>Raise an <see cref="OnPreRenderGuiEventNoCheck"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPreRenderGuiEventNoCheck(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPreRenderGuiEventNoCheck(IMonitor monitor) { - GraphicsEvents.OnPreRenderGuiEventNoCheck?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderGuiEventNoCheck)}", GraphicsEvents.OnPreRenderGuiEventNoCheck?.GetInvocationList()); } /// <summary>Raise an <see cref="OnPostRenderGuiEvent"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPostRenderGuiEvent(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPostRenderGuiEvent(IMonitor monitor) { - GraphicsEvents.OnPostRenderGuiEvent?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderGuiEvent)}", GraphicsEvents.OnPostRenderGuiEvent?.GetInvocationList()); } /// <summary>Raise an <see cref="OnPostRenderGuiEventNoCheck"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPostRenderGuiEventNoCheck(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPostRenderGuiEventNoCheck(IMonitor monitor) { - GraphicsEvents.OnPostRenderGuiEventNoCheck?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderGuiEventNoCheck)}", GraphicsEvents.OnPostRenderGuiEventNoCheck?.GetInvocationList()); } /**** ** GUI events ****/ /// <summary>Raise an <see cref="OnPreRenderHudEvent"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPreRenderHudEvent(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPreRenderHudEvent(IMonitor monitor) { - GraphicsEvents.OnPreRenderHudEvent?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderHudEvent)}", GraphicsEvents.OnPreRenderHudEvent?.GetInvocationList()); } /// <summary>Raise an <see cref="OnPreRenderHudEventNoCheck"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPreRenderHudEventNoCheck(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPreRenderHudEventNoCheck(IMonitor monitor) { - GraphicsEvents.OnPreRenderHudEventNoCheck?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPreRenderHudEventNoCheck)}", GraphicsEvents.OnPreRenderHudEventNoCheck?.GetInvocationList()); } /// <summary>Raise an <see cref="OnPostRenderHudEvent"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPostRenderHudEvent(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPostRenderHudEvent(IMonitor monitor) { - GraphicsEvents.OnPostRenderHudEvent?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderHudEvent)}", GraphicsEvents.OnPostRenderHudEvent?.GetInvocationList()); } /// <summary>Raise an <see cref="OnPostRenderHudEventNoCheck"/> event.</summary> - /// <param name="sender">The object which raised the event.</param> - /// <param name="e">The event arguments.</param> - internal static void InvokeOnPostRenderHudEventNoCheck(object sender, EventArgs e) + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeOnPostRenderHudEventNoCheck(IMonitor monitor) { - GraphicsEvents.OnPostRenderHudEventNoCheck?.Invoke(sender, e); + monitor.SafelyRaisePlainEvent($"{nameof(GraphicsEvents)}.{nameof(GraphicsEvents.OnPostRenderHudEventNoCheck)}", GraphicsEvents.OnPostRenderHudEventNoCheck?.GetInvocationList()); } } } diff --git a/src/StardewModdingAPI/Events/LocationEvents.cs b/src/StardewModdingAPI/Events/LocationEvents.cs index 3c28f541..b834bc1c 100644 --- a/src/StardewModdingAPI/Events/LocationEvents.cs +++ b/src/StardewModdingAPI/Events/LocationEvents.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework; using StardewValley; using Object = StardewValley.Object; @@ -26,25 +27,28 @@ namespace StardewModdingAPI.Events ** Internal methods *********/ /// <summary>Raise a <see cref="CurrentLocationChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorLocation">The player's previous location.</param> /// <param name="newLocation">The player's current location.</param> - internal static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) + internal static void InvokeCurrentLocationChanged(IMonitor monitor, GameLocation priorLocation, GameLocation newLocation) { - LocationEvents.CurrentLocationChanged?.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); + monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.CurrentLocationChanged)}", LocationEvents.CurrentLocationChanged?.GetInvocationList(), null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); } /// <summary>Raise a <see cref="LocationsChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="newLocations">The current list of game locations.</param> - internal static void InvokeLocationsChanged(List<GameLocation> newLocations) + internal static void InvokeLocationsChanged(IMonitor monitor, List<GameLocation> newLocations) { - LocationEvents.LocationsChanged?.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); + monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.LocationsChanged)}", LocationEvents.LocationsChanged?.GetInvocationList(), null, new EventArgsGameLocationsChanged(newLocations)); } /// <summary>Raise a <see cref="LocationObjectsChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="newObjects">The current list of objects in the current location.</param> - internal static void InvokeOnNewLocationObject(SerializableDictionary<Vector2, Object> newObjects) + internal static void InvokeOnNewLocationObject(IMonitor monitor, SerializableDictionary<Vector2, Object> newObjects) { - LocationEvents.LocationObjectsChanged?.Invoke(null, new EventArgsLocationObjectsChanged(newObjects)); + monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.LocationObjectsChanged)}", LocationEvents.LocationObjectsChanged?.GetInvocationList(), null, new EventArgsLocationObjectsChanged(newObjects)); } } } diff --git a/src/StardewModdingAPI/Events/MenuEvents.cs b/src/StardewModdingAPI/Events/MenuEvents.cs index 4cb68cbb..bd8d897e 100644 --- a/src/StardewModdingAPI/Events/MenuEvents.cs +++ b/src/StardewModdingAPI/Events/MenuEvents.cs @@ -1,4 +1,5 @@ using System; +using StardewModdingAPI.Framework; using StardewValley.Menus; namespace StardewModdingAPI.Events @@ -20,18 +21,20 @@ namespace StardewModdingAPI.Events ** Internal methods *********/ /// <summary>Raise a <see cref="MenuChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorMenu">The previous menu.</param> /// <param name="newMenu">The current menu.</param> - internal static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) + internal static void InvokeMenuChanged(IMonitor monitor, IClickableMenu priorMenu, IClickableMenu newMenu) { - MenuEvents.MenuChanged?.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); + monitor.SafelyRaiseGenericEvent($"{nameof(MenuEvents)}.{nameof(MenuEvents.MenuChanged)}", MenuEvents.MenuChanged?.GetInvocationList(), null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); } /// <summary>Raise a <see cref="MenuClosed"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorMenu">The menu that was closed.</param> - internal static void InvokeMenuClosed(IClickableMenu priorMenu) + internal static void InvokeMenuClosed(IMonitor monitor, IClickableMenu priorMenu) { - MenuEvents.MenuClosed?.Invoke(null, new EventArgsClickableMenuClosed(priorMenu)); + monitor.SafelyRaiseGenericEvent($"{nameof(MenuEvents)}.{nameof(MenuEvents.MenuClosed)}", MenuEvents.MenuClosed?.GetInvocationList(), null, new EventArgsClickableMenuClosed(priorMenu)); } } } diff --git a/src/StardewModdingAPI/Events/MineEvents.cs b/src/StardewModdingAPI/Events/MineEvents.cs index 8b91d7d7..9cf7edac 100644 --- a/src/StardewModdingAPI/Events/MineEvents.cs +++ b/src/StardewModdingAPI/Events/MineEvents.cs @@ -1,4 +1,5 @@ using System; +using StardewModdingAPI.Framework; namespace StardewModdingAPI.Events { @@ -16,11 +17,12 @@ namespace StardewModdingAPI.Events ** Internal methods *********/ /// <summary>Raise a <see cref="MineLevelChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="previousMineLevel">The previous mine level.</param> /// <param name="currentMineLevel">The current mine level.</param> - internal static void InvokeMineLevelChanged(int previousMineLevel, int currentMineLevel) + internal static void InvokeMineLevelChanged(IMonitor monitor, int previousMineLevel, int currentMineLevel) { - MineEvents.MineLevelChanged?.Invoke(null, new EventArgsMineLevelChanged(previousMineLevel, currentMineLevel)); + monitor.SafelyRaiseGenericEvent($"{nameof(MineEvents)}.{nameof(MineEvents.MineLevelChanged)}", MineEvents.MineLevelChanged?.GetInvocationList(), null, new EventArgsMineLevelChanged(previousMineLevel, currentMineLevel)); } } } diff --git a/src/StardewModdingAPI/Events/PlayerEvents.cs b/src/StardewModdingAPI/Events/PlayerEvents.cs index c92ab7ce..3f301b07 100644 --- a/src/StardewModdingAPI/Events/PlayerEvents.cs +++ b/src/StardewModdingAPI/Events/PlayerEvents.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using StardewModdingAPI.Framework; using StardewModdingAPI.Inheritance; using StardewValley; @@ -29,34 +30,38 @@ namespace StardewModdingAPI.Events ** Internal methods *********/ /// <summary>Raise a <see cref="LoadedGame"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="loaded">Whether the save has been loaded. This is always true.</param> - internal static void InvokeLoadedGame(EventArgsLoadedGameChanged loaded) + internal static void InvokeLoadedGame(IMonitor monitor, EventArgsLoadedGameChanged loaded) { - PlayerEvents.LoadedGame?.Invoke(null, loaded); + monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.LoadedGame)}", PlayerEvents.LoadedGame?.GetInvocationList(), null, loaded); } /// <summary>Raise a <see cref="FarmerChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorFarmer">The previous player character.</param> /// <param name="newFarmer">The new player character.</param> - internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) + internal static void InvokeFarmerChanged(IMonitor monitor, Farmer priorFarmer, Farmer newFarmer) { - PlayerEvents.FarmerChanged?.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); + monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.FarmerChanged)}", PlayerEvents.FarmerChanged?.GetInvocationList(), null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); } /// <summary>Raise an <see cref="InventoryChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="inventory">The player's inventory.</param> /// <param name="changedItems">The inventory changes.</param> - internal static void InvokeInventoryChanged(List<Item> inventory, IEnumerable<ItemStackChange> changedItems) + internal static void InvokeInventoryChanged(IMonitor monitor, List<Item> inventory, IEnumerable<ItemStackChange> changedItems) { - PlayerEvents.InventoryChanged?.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems.ToList())); + monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.InventoryChanged)}", PlayerEvents.InventoryChanged?.GetInvocationList(), null, new EventArgsInventoryChanged(inventory, changedItems.ToList())); } /// <summary>Rase a <see cref="LeveledUp"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="type">The player skill that leveled up.</param> /// <param name="newLevel">The new skill level.</param> - internal static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel) + internal static void InvokeLeveledUp(IMonitor monitor, EventArgsLevelUp.LevelType type, int newLevel) { - PlayerEvents.LeveledUp?.Invoke(null, new EventArgsLevelUp(type, newLevel)); + monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.LeveledUp)}", PlayerEvents.LeveledUp?.GetInvocationList(), null, new EventArgsLevelUp(type, newLevel)); } } } 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 *********/ /// <summary>Raise a <see cref="InvokeDayOfMonthChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorTime">The previous time in military time format (e.g. 6:00pm is 1800).</param> /// <param name="newTime">The current time in military time format (e.g. 6:10pm is 1810).</param> - 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)); } /// <summary>Raise a <see cref="DayOfMonthChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorDay">The previous day value.</param> /// <param name="newDay">The current day value.</param> - 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)); } /// <summary>Raise a <see cref="YearOfGameChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorYear">The previous year value.</param> /// <param name="newYear">The current year value.</param> - 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)); } /// <summary>Raise a <see cref="SeasonOfYearChanged"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorSeason">The previous season name.</param> /// <param name="newSeason">The current season name.</param> - 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)); } /// <summary>Raise a <see cref="OnNewDay"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorDay">The previous day value.</param> /// <param name="newDay">The current day value.</param> /// <param name="isTransitioning">Whether the game just started the transition (<c>true</c>) or finished it (<c>false</c>).</param> - 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)); } } } |