From aafdcaa2c5eed8201b3a0f735891ba03446ec70e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 14 Nov 2016 22:09:44 -0500 Subject: simplify null guards when rasing events --- src/StardewModdingAPI/Events/ControlEvents.cs | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/StardewModdingAPI/Events/ControlEvents.cs') 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 *********/ /// Raised when the changes. That happens when the player presses or releases a key. - public static event EventHandler KeyboardChanged = delegate { }; + public static event EventHandler KeyboardChanged; /// Raised when the player presses a keyboard key. - public static event EventHandler KeyPressed = delegate { }; + public static event EventHandler KeyPressed; /// Raised when the player releases a keyboard key. - public static event EventHandler KeyReleased = delegate { }; + public static event EventHandler KeyReleased; /// Raised when the changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button. - public static event EventHandler MouseChanged = delegate { }; + public static event EventHandler MouseChanged; /// The player pressed a controller button. This event isn't raised for trigger buttons. - public static event EventHandler ControllerButtonPressed = delegate { }; + public static event EventHandler ControllerButtonPressed; /// The player released a controller button. This event isn't raised for trigger buttons. - public static event EventHandler ControllerButtonReleased = delegate { }; + public static event EventHandler ControllerButtonReleased; /// The player pressed a controller trigger button. - public static event EventHandler ControllerTriggerPressed = delegate { }; + public static event EventHandler ControllerTriggerPressed; /// The player released a controller trigger button. - public static event EventHandler ControllerTriggerReleased = delegate { }; + public static event EventHandler ControllerTriggerReleased; /********* @@ -43,7 +43,7 @@ namespace StardewModdingAPI.Events /// The current keyboard state. internal static void InvokeKeyboardChanged(KeyboardState priorState, KeyboardState newState) { - ControlEvents.KeyboardChanged.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); + ControlEvents.KeyboardChanged?.Invoke(null, new EventArgsKeyboardStateChanged(priorState, newState)); } /// Raise a event. @@ -53,21 +53,21 @@ namespace StardewModdingAPI.Events /// The current mouse position on the screen adjusted for the zoom level. 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)); } /// Raise a event. /// The keyboard button that was pressed. internal static void InvokeKeyPressed(Keys key) { - ControlEvents.KeyPressed.Invoke(null, new EventArgsKeyPressed(key)); + ControlEvents.KeyPressed?.Invoke(null, new EventArgsKeyPressed(key)); } /// Raise a event. /// The keyboard button that was released. internal static void InvokeKeyReleased(Keys key) { - ControlEvents.KeyReleased.Invoke(null, new EventArgsKeyPressed(key)); + ControlEvents.KeyReleased?.Invoke(null, new EventArgsKeyPressed(key)); } /// Raise a event. @@ -75,7 +75,7 @@ namespace StardewModdingAPI.Events /// The controller button that was pressed. internal static void InvokeButtonPressed(PlayerIndex playerIndex, Buttons button) { - ControlEvents.ControllerButtonPressed.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, button)); + ControlEvents.ControllerButtonPressed?.Invoke(null, new EventArgsControllerButtonPressed(playerIndex, button)); } /// Raise a event. @@ -83,7 +83,7 @@ namespace StardewModdingAPI.Events /// The controller button that was released. internal static void InvokeButtonReleased(PlayerIndex playerIndex, Buttons button) { - ControlEvents.ControllerButtonReleased.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, button)); + ControlEvents.ControllerButtonReleased?.Invoke(null, new EventArgsControllerButtonReleased(playerIndex, button)); } /// Raise a event. @@ -92,7 +92,7 @@ namespace StardewModdingAPI.Events /// The current trigger value. 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)); } /// Raise a event. @@ -101,7 +101,7 @@ namespace StardewModdingAPI.Events /// The current trigger value. 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)); } } } -- cgit