diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-14 22:09:44 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-14 22:09:44 -0500 |
commit | aafdcaa2c5eed8201b3a0f735891ba03446ec70e (patch) | |
tree | 989a8c3867aade26c77ba79ef3827378439f0404 | |
parent | bc8773bbddb017b8f67fcf6139f923069392e723 (diff) | |
download | SMAPI-aafdcaa2c5eed8201b3a0f735891ba03446ec70e.tar.gz SMAPI-aafdcaa2c5eed8201b3a0f735891ba03446ec70e.tar.bz2 SMAPI-aafdcaa2c5eed8201b3a0f735891ba03446ec70e.zip |
simplify null guards when rasing events
-rw-r--r-- | src/StardewModdingAPI/Events/ControlEvents.cs | 32 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/GameEvents.cs | 50 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/GraphicsEvents.cs | 56 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/LocationEvents.cs | 12 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/MenuEvents.cs | 8 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/MineEvents.cs | 4 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/PlayerEvents.cs | 16 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/TimeEvents.cs | 20 |
8 files changed, 99 insertions, 99 deletions
diff --git a/src/StardewModdingAPI/Events/ControlEvents.cs b/src/StardewModdingAPI/Events/ControlEvents.cs index 1b1e0b78..b7f69805 100644 --- a/src/StardewModdingAPI/Events/ControlEvents.cs +++ b/src/StardewModdingAPI/Events/ControlEvents.cs @@ -11,28 +11,28 @@ namespace StardewModdingAPI.Events ** Events *********/ /// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary> - public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged = delegate { }; + public static event EventHandler<EventArgsKeyboardStateChanged> KeyboardChanged; /// <summary>Raised when the player presses a keyboard key.</summary> - public static event EventHandler<EventArgsKeyPressed> KeyPressed = delegate { }; + public static event EventHandler<EventArgsKeyPressed> KeyPressed; /// <summary>Raised when the player releases a keyboard key.</summary> - public static event EventHandler<EventArgsKeyPressed> KeyReleased = delegate { }; + public static event EventHandler<EventArgsKeyPressed> KeyReleased; /// <summary>Raised when the <see cref="MouseState"/> changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button.</summary> - public static event EventHandler<EventArgsMouseStateChanged> MouseChanged = delegate { }; + public static event EventHandler<EventArgsMouseStateChanged> MouseChanged; /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary> - public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed = delegate { }; + public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed; /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary> - public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased = delegate { }; + public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased; /// <summary>The player pressed a controller trigger button.</summary> - public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed = delegate { }; + public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed; /// <summary>The player released a controller trigger button.</summary> - public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased = delegate { }; + public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased; /********* @@ -43,7 +43,7 @@ namespace StardewModdingAPI.Events /// <param name="newState">The current keyboard state.</param> internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) { - ControlEvents.KeyboardChanged.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); + ControlEvents.KeyboardChanged?.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); } /// <summary>Raise a <see cref="MouseChanged"/> event.</summary> @@ -53,21 +53,21 @@ namespace StardewModdingAPI.Events /// <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) { - ControlEvents.MouseChanged.Invoke(null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); + ControlEvents.MouseChanged?.Invoke(null, new EventArgsMouseStateChanged(priorState, newState, priorPosition, newPosition)); } /// <summary>Raise a <see cref="KeyPressed"/> event.</summary> /// <param name="key">The keyboard button that was pressed.</param> internal static void InvokeKeyPressed(Keys key) { - ControlEvents.KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); + ControlEvents.KeyPressed?.Invoke(null, new EventArgsKeyPressed(key)); } /// <summary>Raise a <see cref="KeyReleased"/> event.</summary> /// <param name="key">The keyboard button that was released.</param> internal static void InvokeKeyReleased(Keys key) { - ControlEvents.KeyReleased.Invoke(null, new EventArgsKeyPressed(key)); + ControlEvents.KeyReleased?.Invoke(null, new EventArgsKeyPressed(key)); } /// <summary>Raise a <see cref="ControllerButtonPressed"/> event.</summary> @@ -75,7 +75,7 @@ namespace StardewModdingAPI.Events /// <param name="button">The controller button that was pressed.</param> internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons button) { - ControlEvents.ControllerButtonPressed.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, button)); + ControlEvents.ControllerButtonPressed?.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, button)); } /// <summary>Raise a <see cref="ControllerButtonReleased"/> event.</summary> @@ -83,7 +83,7 @@ namespace StardewModdingAPI.Events /// <param name="button">The controller button that was released.</param> internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons button) { - ControlEvents.ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, button)); + ControlEvents.ControllerButtonReleased?.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, button)); } /// <summary>Raise a <see cref="ControllerTriggerPressed"/> event.</summary> @@ -92,7 +92,7 @@ namespace StardewModdingAPI.Events /// <param name="value">The current trigger value.</param> internal static void InvokeTriggerPressed(PlayerIndex playerIndex, Buttons button, float value) { - ControlEvents.ControllerTriggerPressed.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, button, value)); + ControlEvents.ControllerTriggerPressed?.Invoke(null, new EventArgsControllerTriggerPressed(playerIndex, button, value)); } /// <summary>Raise a <see cref="ControllerTriggerReleased"/> event.</summary> @@ -101,7 +101,7 @@ namespace StardewModdingAPI.Events /// <param name="value">The current trigger value.</param> internal static void InvokeTriggerReleased(PlayerIndex playerIndex, Buttons button, float value) { - ControlEvents.ControllerTriggerReleased.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, button, value)); + ControlEvents.ControllerTriggerReleased?.Invoke(null, new EventArgsControllerTriggerReleased(playerIndex, button, value)); } } } diff --git a/src/StardewModdingAPI/Events/GameEvents.cs b/src/StardewModdingAPI/Events/GameEvents.cs index e4a0e08d..e1bfc924 100644 --- a/src/StardewModdingAPI/Events/GameEvents.cs +++ b/src/StardewModdingAPI/Events/GameEvents.cs @@ -9,37 +9,37 @@ namespace StardewModdingAPI.Events ** Events *********/ /// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called during <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary> - public static event EventHandler Initialize = delegate { }; + public static event EventHandler Initialize; /// <summary>Raised during launch after configuring Stardew Valley, loading it into memory, and opening the game window. The window is still blank by this point.</summary> - public static event EventHandler GameLoaded = delegate { }; + public static event EventHandler GameLoaded; /// <summary>Raised before XNA loads or reloads graphics resources. Called during <see cref="Microsoft.Xna.Framework.Game.LoadContent"/>.</summary> - public static event EventHandler LoadContent = delegate { }; + public static event EventHandler LoadContent; /// <summary>Raised during the first game update tick.</summary> - public static event EventHandler FirstUpdateTick = delegate { }; + public static event EventHandler FirstUpdateTick; /// <summary>Raised when the game updates its state (≈60 times per second).</summary> - public static event EventHandler UpdateTick = delegate { }; + public static event EventHandler UpdateTick; /// <summary>Raised every other tick (≈30 times per second).</summary> - public static event EventHandler SecondUpdateTick = delegate { }; + public static event EventHandler SecondUpdateTick; /// <summary>Raised every fourth tick (≈15 times per second).</summary> - public static event EventHandler FourthUpdateTick = delegate { }; + public static event EventHandler FourthUpdateTick; /// <summary>Raised every eighth tick (≈8 times per second).</summary> - public static event EventHandler EighthUpdateTick = delegate { }; + public static event EventHandler EighthUpdateTick; /// <summary>Raised every 15th tick (≈4 times per second).</summary> - public static event EventHandler QuarterSecondTick = delegate { }; + public static event EventHandler QuarterSecondTick; /// <summary>Raised every 30th tick (≈twice per second).</summary> - public static event EventHandler HalfSecondTick = delegate { }; + public static event EventHandler HalfSecondTick; /// <summary>Raised every 60th tick (≈once per second).</summary> - public static event EventHandler OneSecondTick = delegate { }; + public static event EventHandler OneSecondTick; /********* @@ -48,7 +48,7 @@ namespace StardewModdingAPI.Events /// <summary>Raise a <see cref="GameLoaded"/> event.</summary> internal static void InvokeGameLoaded() { - GameEvents.GameLoaded.Invoke(null, EventArgs.Empty); + GameEvents.GameLoaded?.Invoke(null, EventArgs.Empty); } /// <summary>Raise an <see cref="Initialize"/> event.</summary> @@ -56,11 +56,11 @@ namespace StardewModdingAPI.Events { try { - GameEvents.Initialize.Invoke(null, EventArgs.Empty); + GameEvents.Initialize?.Invoke(null, EventArgs.Empty); } catch (Exception ex) { - Log.AsyncR("An exception occured in XNA Initialize: " + ex); + Log.Error($"A mod crashed handling an event.\n{ex}"); } } @@ -69,11 +69,11 @@ namespace StardewModdingAPI.Events { try { - GameEvents.LoadContent.Invoke(null, EventArgs.Empty); + GameEvents.LoadContent?.Invoke(null, EventArgs.Empty); } catch (Exception ex) { - Log.AsyncR("An exception occured in XNA LoadContent: " + ex); + Log.Error($"A mod crashed handling an event.\n{ex}"); } } @@ -82,54 +82,54 @@ namespace StardewModdingAPI.Events { try { - GameEvents.UpdateTick.Invoke(null, EventArgs.Empty); + GameEvents.UpdateTick?.Invoke(null, EventArgs.Empty); } catch (Exception ex) { - Log.AsyncR("An exception occured in XNA UpdateTick: " + ex); + Log.Error($"A mod crashed handling an event.\n{ex}"); } } /// <summary>Raise a <see cref="SecondUpdateTick"/> event.</summary> internal static void InvokeSecondUpdateTick() { - GameEvents.SecondUpdateTick.Invoke(null, EventArgs.Empty); + GameEvents.SecondUpdateTick?.Invoke(null, EventArgs.Empty); } /// <summary>Raise a <see cref="FourthUpdateTick"/> event.</summary> internal static void InvokeFourthUpdateTick() { - GameEvents.FourthUpdateTick.Invoke(null, EventArgs.Empty); + GameEvents.FourthUpdateTick?.Invoke(null, EventArgs.Empty); } /// <summary>Raise a <see cref="EighthUpdateTick"/> event.</summary> internal static void InvokeEighthUpdateTick() { - GameEvents.EighthUpdateTick.Invoke(null, EventArgs.Empty); + GameEvents.EighthUpdateTick?.Invoke(null, EventArgs.Empty); } /// <summary>Raise a <see cref="QuarterSecondTick"/> event.</summary> internal static void InvokeQuarterSecondTick() { - GameEvents.QuarterSecondTick.Invoke(null, EventArgs.Empty); + GameEvents.QuarterSecondTick?.Invoke(null, EventArgs.Empty); } /// <summary>Raise a <see cref="HalfSecondTick"/> event.</summary> internal static void InvokeHalfSecondTick() { - GameEvents.HalfSecondTick.Invoke(null, EventArgs.Empty); + GameEvents.HalfSecondTick?.Invoke(null, EventArgs.Empty); } /// <summary>Raise a <see cref="OneSecondTick"/> event.</summary> internal static void InvokeOneSecondTick() { - GameEvents.OneSecondTick.Invoke(null, EventArgs.Empty); + GameEvents.OneSecondTick?.Invoke(null, EventArgs.Empty); } /// <summary>Raise a <see cref="FirstUpdateTick"/> event.</summary> internal static void InvokeFirstUpdateTick() { - GameEvents.FirstUpdateTick.Invoke(null, EventArgs.Empty); + GameEvents.FirstUpdateTick?.Invoke(null, EventArgs.Empty); } } } diff --git a/src/StardewModdingAPI/Events/GraphicsEvents.cs b/src/StardewModdingAPI/Events/GraphicsEvents.cs index fe38c1bb..a6112807 100644 --- a/src/StardewModdingAPI/Events/GraphicsEvents.cs +++ b/src/StardewModdingAPI/Events/GraphicsEvents.cs @@ -12,57 +12,57 @@ namespace StardewModdingAPI.Events ** Generic events ****/ /// <summary>Raised after the game window is resized.</summary> - public static event EventHandler Resize = delegate { }; + public static event EventHandler Resize; /// <summary>Raised when drawing debug information to the screen (when <see cref="StardewModdingAPI.Inheritance.SGame.Debug"/> is true). This is called after the sprite batch is begun. If you just want to add debug info, use <see cref="StardewModdingAPI.Inheritance.SGame.DebugMessageQueue" /> in your update loop.</summary> - public static event EventHandler DrawDebug = delegate { }; + public static event EventHandler DrawDebug; /// <summary>Obsolete.</summary> [Obsolete("Use the other Pre/Post render events instead.")] - public static event EventHandler DrawTick = delegate { }; + public static event EventHandler DrawTick; /// <summary>Obsolete.</summary> [Obsolete("Use the other Pre/Post render events instead. All of them will automatically be drawn into the render target if needed.")] - public static event EventHandler DrawInRenderTargetTick = delegate { }; + public static event EventHandler DrawInRenderTargetTick; /**** ** Main render events ****/ /// <summary>Raised before drawing everything to the screen during a draw loop.</summary> - public static event EventHandler OnPreRenderEvent = delegate { }; + public static event EventHandler OnPreRenderEvent; /// <summary>Raised after drawing everything to the screen during a draw loop.</summary> - public static event EventHandler OnPostRenderEvent = delegate { }; + public static event EventHandler OnPostRenderEvent; /**** ** HUD events ****/ /// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> - public static event EventHandler OnPreRenderHudEvent = delegate { }; + public static event EventHandler OnPreRenderHudEvent; /// <summary>Equivalent to <see cref="OnPreRenderHudEvent"/>, but invoked even if the HUD isn't available.</summary> - public static event EventHandler OnPreRenderHudEventNoCheck = delegate { }; + public static event EventHandler OnPreRenderHudEventNoCheck; /// <summary>Raised after drawing the HUD (item toolbar, clock, etc) to the screen. The HUD is available at this point, but not necessarily visible. (For example, the event is raised even if a menu is open.)</summary> - public static event EventHandler OnPostRenderHudEvent = delegate { }; + public static event EventHandler OnPostRenderHudEvent; /// <summary>Equivalent to <see cref="OnPostRenderHudEvent"/>, but invoked even if the HUD isn't available.</summary> - public static event EventHandler OnPostRenderHudEventNoCheck = delegate { }; + public static event EventHandler OnPostRenderHudEventNoCheck; /**** ** GUI events ****/ /// <summary>Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> - public static event EventHandler OnPreRenderGuiEvent = delegate { }; + public static event EventHandler OnPreRenderGuiEvent; /// <summary>Equivalent to <see cref="OnPreRenderGuiEvent"/>, but invoked even if there's no menu being drawn.</summary> - public static event EventHandler OnPreRenderGuiEventNoCheck = delegate { }; + public static event EventHandler OnPreRenderGuiEventNoCheck; /// <summary>Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen.</summary> - public static event EventHandler OnPostRenderGuiEvent = delegate { }; + public static event EventHandler OnPostRenderGuiEvent; /// <summary>Equivalent to <see cref="OnPreRenderGuiEvent"/>, but invoked even if there's no menu being drawn.</summary> - public static event EventHandler OnPostRenderGuiEventNoCheck = delegate { }; + public static event EventHandler OnPostRenderGuiEventNoCheck; /********* @@ -76,7 +76,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeResize(object sender, EventArgs e) { - GraphicsEvents.Resize.Invoke(sender, e); + GraphicsEvents.Resize?.Invoke(sender, e); } /// <summary>Raise a <see cref="DrawDebug"/> event.</summary> @@ -84,7 +84,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeDrawDebug(object sender, EventArgs e) { - GraphicsEvents.DrawDebug.Invoke(sender, e); + GraphicsEvents.DrawDebug?.Invoke(sender, e); } /// <summary>Raise a <see cref="DrawTick"/> event.</summary> @@ -93,7 +93,7 @@ namespace StardewModdingAPI.Events { try { - GraphicsEvents.DrawTick.Invoke(null, EventArgs.Empty); + GraphicsEvents.DrawTick?.Invoke(null, EventArgs.Empty); } catch (Exception ex) { @@ -105,7 +105,7 @@ namespace StardewModdingAPI.Events [Obsolete("Should not be used.")] public static void InvokeDrawInRenderTargetTick() { - GraphicsEvents.DrawInRenderTargetTick.Invoke(null, EventArgs.Empty); + GraphicsEvents.DrawInRenderTargetTick?.Invoke(null, EventArgs.Empty); } /**** @@ -116,7 +116,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPreRenderEvent(object sender, EventArgs e) { - GraphicsEvents.OnPreRenderEvent.Invoke(sender, e); + GraphicsEvents.OnPreRenderEvent?.Invoke(sender, e); } /// <summary>Raise an <see cref="OnPostRenderEvent"/> event.</summary> @@ -124,7 +124,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPostRenderEvent(object sender, EventArgs e) { - GraphicsEvents.OnPostRenderEvent.Invoke(sender, e); + GraphicsEvents.OnPostRenderEvent?.Invoke(sender, e); } /**** @@ -135,7 +135,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPreRenderGuiEvent(object sender, EventArgs e) { - GraphicsEvents.OnPreRenderGuiEvent.Invoke(sender, e); + GraphicsEvents.OnPreRenderGuiEvent?.Invoke(sender, e); } /// <summary>Raise an <see cref="OnPreRenderGuiEventNoCheck"/> event.</summary> @@ -143,7 +143,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPreRenderGuiEventNoCheck(object sender, EventArgs e) { - GraphicsEvents.OnPreRenderGuiEventNoCheck.Invoke(sender, e); + GraphicsEvents.OnPreRenderGuiEventNoCheck?.Invoke(sender, e); } /// <summary>Raise an <see cref="OnPostRenderGuiEvent"/> event.</summary> @@ -151,7 +151,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPostRenderGuiEvent(object sender, EventArgs e) { - GraphicsEvents.OnPostRenderGuiEvent.Invoke(sender, e); + GraphicsEvents.OnPostRenderGuiEvent?.Invoke(sender, e); } /// <summary>Raise an <see cref="OnPostRenderGuiEventNoCheck"/> event.</summary> @@ -159,7 +159,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPostRenderGuiEventNoCheck(object sender, EventArgs e) { - GraphicsEvents.OnPostRenderGuiEventNoCheck.Invoke(sender, e); + GraphicsEvents.OnPostRenderGuiEventNoCheck?.Invoke(sender, e); } /**** @@ -170,7 +170,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPreRenderHudEvent(object sender, EventArgs e) { - GraphicsEvents.OnPreRenderHudEvent.Invoke(sender, e); + GraphicsEvents.OnPreRenderHudEvent?.Invoke(sender, e); } /// <summary>Raise an <see cref="OnPreRenderHudEventNoCheck"/> event.</summary> @@ -178,7 +178,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPreRenderHudEventNoCheck(object sender, EventArgs e) { - GraphicsEvents.OnPreRenderHudEventNoCheck.Invoke(sender, e); + GraphicsEvents.OnPreRenderHudEventNoCheck?.Invoke(sender, e); } /// <summary>Raise an <see cref="OnPostRenderHudEvent"/> event.</summary> @@ -186,7 +186,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPostRenderHudEvent(object sender, EventArgs e) { - GraphicsEvents.OnPostRenderHudEvent.Invoke(sender, e); + GraphicsEvents.OnPostRenderHudEvent?.Invoke(sender, e); } /// <summary>Raise an <see cref="OnPostRenderHudEventNoCheck"/> event.</summary> @@ -194,7 +194,7 @@ namespace StardewModdingAPI.Events /// <param name="e">The event arguments.</param> internal static void InvokeOnPostRenderHudEventNoCheck(object sender, EventArgs e) { - GraphicsEvents.OnPostRenderHudEventNoCheck.Invoke(sender, e); + GraphicsEvents.OnPostRenderHudEventNoCheck?.Invoke(sender, e); } } } diff --git a/src/StardewModdingAPI/Events/LocationEvents.cs b/src/StardewModdingAPI/Events/LocationEvents.cs index af2eb400..3c28f541 100644 --- a/src/StardewModdingAPI/Events/LocationEvents.cs +++ b/src/StardewModdingAPI/Events/LocationEvents.cs @@ -13,13 +13,13 @@ namespace StardewModdingAPI.Events ** Events *********/ /// <summary>Raised after the player warps to a new location.</summary> - public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged = delegate { }; + public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged; /// <summary>Raised after a game location is added or removed.</summary> - public static event EventHandler<EventArgsGameLocationsChanged> LocationsChanged = delegate { }; + public static event EventHandler<EventArgsGameLocationsChanged> LocationsChanged; /// <summary>Raised after the list of objects in the current location changes (e.g. an object is added or removed).</summary> - public static event EventHandler<EventArgsLocationObjectsChanged> LocationObjectsChanged = delegate { }; + public static event EventHandler<EventArgsLocationObjectsChanged> LocationObjectsChanged; /********* @@ -30,21 +30,21 @@ namespace StardewModdingAPI.Events /// <param name="newLocation">The player's current location.</param> internal static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation) { - LocationEvents.CurrentLocationChanged.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); + LocationEvents.CurrentLocationChanged?.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation)); } /// <summary>Raise a <see cref="LocationsChanged"/> event.</summary> /// <param name="newLocations">The current list of game locations.</param> internal static void InvokeLocationsChanged(List<GameLocation> newLocations) { - LocationEvents.LocationsChanged.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); + LocationEvents.LocationsChanged?.Invoke(null, new EventArgsGameLocationsChanged(newLocations)); } /// <summary>Raise a <see cref="LocationObjectsChanged"/> event.</summary> /// <param name="newObjects">The current list of objects in the current location.</param> internal static void InvokeOnNewLocationObject(SerializableDictionary<Vector2, Object> newObjects) { - LocationEvents.LocationObjectsChanged.Invoke(null, new EventArgsLocationObjectsChanged(newObjects)); + LocationEvents.LocationObjectsChanged?.Invoke(null, new EventArgsLocationObjectsChanged(newObjects)); } } } diff --git a/src/StardewModdingAPI/Events/MenuEvents.cs b/src/StardewModdingAPI/Events/MenuEvents.cs index 59f03449..4cb68cbb 100644 --- a/src/StardewModdingAPI/Events/MenuEvents.cs +++ b/src/StardewModdingAPI/Events/MenuEvents.cs @@ -10,10 +10,10 @@ namespace StardewModdingAPI.Events ** Events *********/ /// <summary>Raised after a game menu is opened or replaced with another menu. This event is not invoked when a menu is closed.</summary> - public static event EventHandler<EventArgsClickableMenuChanged> MenuChanged = delegate { }; + public static event EventHandler<EventArgsClickableMenuChanged> MenuChanged; /// <summary>Raised after a game menu is closed.</summary> - public static event EventHandler<EventArgsClickableMenuClosed> MenuClosed = delegate { }; + public static event EventHandler<EventArgsClickableMenuClosed> MenuClosed; /********* @@ -24,14 +24,14 @@ namespace StardewModdingAPI.Events /// <param name="newMenu">The current menu.</param> internal static void InvokeMenuChanged(IClickableMenu priorMenu, IClickableMenu newMenu) { - MenuEvents.MenuChanged.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); + MenuEvents.MenuChanged?.Invoke(null, new EventArgsClickableMenuChanged(priorMenu, newMenu)); } /// <summary>Raise a <see cref="MenuClosed"/> event.</summary> /// <param name="priorMenu">The menu that was closed.</param> internal static void InvokeMenuClosed(IClickableMenu priorMenu) { - MenuEvents.MenuClosed.Invoke(null, new EventArgsClickableMenuClosed(priorMenu)); + MenuEvents.MenuClosed?.Invoke(null, new EventArgsClickableMenuClosed(priorMenu)); } } } diff --git a/src/StardewModdingAPI/Events/MineEvents.cs b/src/StardewModdingAPI/Events/MineEvents.cs index 6121abf4..8b91d7d7 100644 --- a/src/StardewModdingAPI/Events/MineEvents.cs +++ b/src/StardewModdingAPI/Events/MineEvents.cs @@ -9,7 +9,7 @@ namespace StardewModdingAPI.Events ** Events *********/ /// <summary>Raised after the player warps to a new level of the mine.</summary> - public static event EventHandler<EventArgsMineLevelChanged> MineLevelChanged = delegate { }; + public static event EventHandler<EventArgsMineLevelChanged> MineLevelChanged; /********* @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events /// <param name="currentMineLevel">The current mine level.</param> internal static void InvokeMineLevelChanged(int previousMineLevel, int currentMineLevel) { - MineEvents.MineLevelChanged.Invoke(null, new EventArgsMineLevelChanged(previousMineLevel, currentMineLevel)); + MineEvents.MineLevelChanged?.Invoke(null, new EventArgsMineLevelChanged(previousMineLevel, currentMineLevel)); } } } diff --git a/src/StardewModdingAPI/Events/PlayerEvents.cs b/src/StardewModdingAPI/Events/PlayerEvents.cs index 87e6a509..c92ab7ce 100644 --- a/src/StardewModdingAPI/Events/PlayerEvents.cs +++ b/src/StardewModdingAPI/Events/PlayerEvents.cs @@ -13,16 +13,16 @@ namespace StardewModdingAPI.Events ** Events *********/ /// <summary>Raised after the player loads a saved game.</summary> - public static event EventHandler<EventArgsLoadedGameChanged> LoadedGame = delegate { }; + public static event EventHandler<EventArgsLoadedGameChanged> LoadedGame; /// <summary>Raised after the game assigns a new player character. This happens just before <see cref="LoadedGame"/>; it's unclear how this would happen any other time.</summary> - public static event EventHandler<EventArgsFarmerChanged> FarmerChanged = delegate { }; + public static event EventHandler<EventArgsFarmerChanged> FarmerChanged; /// <summary>Raised after the player's inventory changes in any way (added or removed item, sorted, etc).</summary> - public static event EventHandler<EventArgsInventoryChanged> InventoryChanged = delegate { }; + public static event EventHandler<EventArgsInventoryChanged> InventoryChanged; /// <summary> Raised after the player levels up a skill. This happens as soon as they level up, not when the game notifies the player after their character goes to bed.</summary> - public static event EventHandler<EventArgsLevelUp> LeveledUp = delegate { }; + public static event EventHandler<EventArgsLevelUp> LeveledUp; /********* @@ -32,7 +32,7 @@ namespace StardewModdingAPI.Events /// <param name="loaded">Whether the save has been loaded. This is always true.</param> internal static void InvokeLoadedGame(EventArgsLoadedGameChanged loaded) { - PlayerEvents.LoadedGame.Invoke(null, loaded); + PlayerEvents.LoadedGame?.Invoke(null, loaded); } /// <summary>Raise a <see cref="FarmerChanged"/> event.</summary> @@ -40,7 +40,7 @@ namespace StardewModdingAPI.Events /// <param name="newFarmer">The new player character.</param> internal static void InvokeFarmerChanged(Farmer priorFarmer, Farmer newFarmer) { - PlayerEvents.FarmerChanged.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); + PlayerEvents.FarmerChanged?.Invoke(null, new EventArgsFarmerChanged(priorFarmer, newFarmer)); } /// <summary>Raise an <see cref="InventoryChanged"/> event.</summary> @@ -48,7 +48,7 @@ namespace StardewModdingAPI.Events /// <param name="changedItems">The inventory changes.</param> internal static void InvokeInventoryChanged(List<Item> inventory, IEnumerable<ItemStackChange> changedItems) { - PlayerEvents.InventoryChanged.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems.ToList())); + PlayerEvents.InventoryChanged?.Invoke(null, new EventArgsInventoryChanged(inventory, changedItems.ToList())); } /// <summary>Rase a <see cref="LeveledUp"/> event.</summary> @@ -56,7 +56,7 @@ namespace StardewModdingAPI.Events /// <param name="newLevel">The new skill level.</param> internal static void InvokeLeveledUp(EventArgsLevelUp.LevelType type, int newLevel) { - PlayerEvents.LeveledUp.Invoke(null, new EventArgsLevelUp(type, newLevel)); + PlayerEvents.LeveledUp?.Invoke(null, new EventArgsLevelUp(type, newLevel)); } } } diff --git a/src/StardewModdingAPI/Events/TimeEvents.cs b/src/StardewModdingAPI/Events/TimeEvents.cs index ee83a267..0481ad48 100644 --- a/src/StardewModdingAPI/Events/TimeEvents.cs +++ b/src/StardewModdingAPI/Events/TimeEvents.cs @@ -9,19 +9,19 @@ namespace StardewModdingAPI.Events ** Events *********/ /// <summary>Raised after the in-game clock changes.</summary> - public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged = delegate { }; + public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged; /// <summary>Raised after the day-of-month value changes, including when loading a save (unlike <see cref="OnNewDay"/>).</summary> - public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged = delegate { }; + public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged; /// <summary>Raised after the year value changes.</summary> - public static event EventHandler<EventArgsIntChanged> YearOfGameChanged = delegate { }; + public static event EventHandler<EventArgsIntChanged> YearOfGameChanged; /// <summary>Raised after the season value changes.</summary> - public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged = delegate { }; + public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged; /// <summary>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.</summary> - public static event EventHandler<EventArgsNewDay> OnNewDay = delegate { }; + public static event EventHandler<EventArgsNewDay> OnNewDay; /********* @@ -32,7 +32,7 @@ namespace StardewModdingAPI.Events /// <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) { - TimeEvents.TimeOfDayChanged.Invoke(null, new EventArgsIntChanged(priorTime, newTime)); + TimeEvents.TimeOfDayChanged?.Invoke(null, new EventArgsIntChanged(priorTime, newTime)); } /// <summary>Raise a <see cref="DayOfMonthChanged"/> event.</summary> @@ -40,7 +40,7 @@ namespace StardewModdingAPI.Events /// <param name="newDay">The current day value.</param> internal static void InvokeDayOfMonthChanged(int priorDay, int newDay) { - TimeEvents.DayOfMonthChanged.Invoke(null, new EventArgsIntChanged(priorDay, newDay)); + TimeEvents.DayOfMonthChanged?.Invoke(null, new EventArgsIntChanged(priorDay, newDay)); } /// <summary>Raise a <see cref="YearOfGameChanged"/> event.</summary> @@ -48,7 +48,7 @@ namespace StardewModdingAPI.Events /// <param name="newYear">The current year value.</param> internal static void InvokeYearOfGameChanged(int priorYear, int newYear) { - TimeEvents.YearOfGameChanged.Invoke(null, new EventArgsIntChanged(priorYear, newYear)); + TimeEvents.YearOfGameChanged?.Invoke(null, new EventArgsIntChanged(priorYear, newYear)); } /// <summary>Raise a <see cref="SeasonOfYearChanged"/> event.</summary> @@ -56,7 +56,7 @@ namespace StardewModdingAPI.Events /// <param name="newSeason">The current season name.</param> internal static void InvokeSeasonOfYearChanged(string priorSeason, string newSeason) { - TimeEvents.SeasonOfYearChanged.Invoke(null, new EventArgsStringChanged(priorSeason, newSeason)); + TimeEvents.SeasonOfYearChanged?.Invoke(null, new EventArgsStringChanged(priorSeason, newSeason)); } /// <summary>Raise a <see cref="OnNewDay"/> event.</summary> @@ -65,7 +65,7 @@ namespace StardewModdingAPI.Events /// <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) { - TimeEvents.OnNewDay.Invoke(null, new EventArgsNewDay(priorDay, newDay, isTransitioning)); + TimeEvents.OnNewDay?.Invoke(null, new EventArgsNewDay(priorDay, newDay, isTransitioning)); } } } |