diff options
Diffstat (limited to 'src/StardewModdingAPI/Events')
-rw-r--r-- | src/StardewModdingAPI/Events/ContentEvents.cs | 7 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/ControlEvents.cs | 20 | ||||
-rw-r--r-- | src/StardewModdingAPI/Events/GameEvents.cs | 39 |
3 files changed, 45 insertions, 21 deletions
diff --git a/src/StardewModdingAPI/Events/ContentEvents.cs b/src/StardewModdingAPI/Events/ContentEvents.cs index 5b4146c5..0dcd2cc6 100644 --- a/src/StardewModdingAPI/Events/ContentEvents.cs +++ b/src/StardewModdingAPI/Events/ContentEvents.cs @@ -27,7 +27,12 @@ namespace StardewModdingAPI.Events public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged; /// <summary>Raised when an XNB file is being read into the cache. Mods can change the data here before it's cached.</summary> - internal static event EventHandler<IContentEventHelper> AfterAssetLoaded; +#if EXPERIMENTAL + public +#else + internal +#endif + static event EventHandler<IContentEventHelper> AfterAssetLoaded; /********* diff --git a/src/StardewModdingAPI/Events/ControlEvents.cs b/src/StardewModdingAPI/Events/ControlEvents.cs index 790bf193..80d0f547 100644 --- a/src/StardewModdingAPI/Events/ControlEvents.cs +++ b/src/StardewModdingAPI/Events/ControlEvents.cs @@ -77,40 +77,36 @@ namespace StardewModdingAPI.Events /// <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(IMonitor monitor, PlayerIndex playerIndex, Buttons button) + internal static void InvokeButtonPressed(IMonitor monitor, Buttons button) { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonPressed)}", ControlEvents.ControllerButtonPressed?.GetInvocationList(), null, new EventArgsControllerButtonPressed(playerIndex, button)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonPressed)}", ControlEvents.ControllerButtonPressed?.GetInvocationList(), null, new EventArgsControllerButtonPressed(PlayerIndex.One, 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(IMonitor monitor, PlayerIndex playerIndex, Buttons button) + internal static void InvokeButtonReleased(IMonitor monitor, Buttons button) { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonReleased)}", ControlEvents.ControllerButtonReleased?.GetInvocationList(), null, new EventArgsControllerButtonReleased(playerIndex, button)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerButtonReleased)}", ControlEvents.ControllerButtonReleased?.GetInvocationList(), null, new EventArgsControllerButtonReleased(PlayerIndex.One, 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(IMonitor monitor, PlayerIndex playerIndex, Buttons button, float value) + internal static void InvokeTriggerPressed(IMonitor monitor, Buttons button, float value) { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerPressed)}", ControlEvents.ControllerTriggerPressed?.GetInvocationList(), null, new EventArgsControllerTriggerPressed(playerIndex, button, value)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerPressed)}", ControlEvents.ControllerTriggerPressed?.GetInvocationList(), null, new EventArgsControllerTriggerPressed(PlayerIndex.One, 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(IMonitor monitor, PlayerIndex playerIndex, Buttons button, float value) + internal static void InvokeTriggerReleased(IMonitor monitor, Buttons button, float value) { - monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerReleased)}", ControlEvents.ControllerTriggerReleased?.GetInvocationList(), null, new EventArgsControllerTriggerReleased(playerIndex, button, value)); + monitor.SafelyRaiseGenericEvent($"{nameof(ControlEvents)}.{nameof(ControlEvents.ControllerTriggerReleased)}", ControlEvents.ControllerTriggerReleased?.GetInvocationList(), null, new EventArgsControllerTriggerReleased(PlayerIndex.One, button, value)); } } } diff --git a/src/StardewModdingAPI/Events/GameEvents.cs b/src/StardewModdingAPI/Events/GameEvents.cs index 029ec1f9..4f9ce7a7 100644 --- a/src/StardewModdingAPI/Events/GameEvents.cs +++ b/src/StardewModdingAPI/Events/GameEvents.cs @@ -19,6 +19,9 @@ namespace StardewModdingAPI.Events /// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called after <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary> internal static event EventHandler InitializeInternal; + /// <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> + internal static event EventHandler GameLoadedInternal; + /// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called after <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary> [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the " + nameof(GameEvents.Initialize) + " event, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")] public static event EventHandler Initialize; @@ -28,9 +31,11 @@ namespace StardewModdingAPI.Events public static event EventHandler LoadContent; /// <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> + [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the game loads, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")] public static event EventHandler GameLoaded; /// <summary>Raised during the first game update tick.</summary> + [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the game loads, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")] public static event EventHandler FirstUpdateTick; /// <summary>Raised when the game updates its state (≈60 times per second).</summary> @@ -99,7 +104,32 @@ namespace StardewModdingAPI.Events /// <param name="monitor">Encapsulates monitoring and logging.</param> internal static void InvokeGameLoaded(IMonitor monitor) { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", GameEvents.GameLoaded?.GetInvocationList()); + // notify SMAPI + monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoadedInternal)}", GameEvents.GameLoadedInternal?.GetInvocationList()); + + // notify mods + if (GameEvents.GameLoaded == null) + return; + + string name = $"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}"; + Delegate[] handlers = GameEvents.GameLoaded.GetInvocationList(); + + GameEvents.DeprecationManager.WarnForEvent(handlers, name, "1.12", DeprecationLevel.Info); + monitor.SafelyRaisePlainEvent(name, handlers); + } + + /// <summary>Raise a <see cref="FirstUpdateTick"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeFirstUpdateTick(IMonitor monitor) + { + if (GameEvents.FirstUpdateTick == null) + return; + + string name = $"{nameof(GameEvents)}.{nameof(GameEvents.FirstUpdateTick)}"; + Delegate[] handlers = GameEvents.FirstUpdateTick.GetInvocationList(); + + GameEvents.DeprecationManager.WarnForEvent(handlers, name, "1.12", DeprecationLevel.Info); + monitor.SafelyRaisePlainEvent(name, handlers); } /// <summary>Raise an <see cref="UpdateTick"/> event.</summary> @@ -150,12 +180,5 @@ namespace StardewModdingAPI.Events { monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.OneSecondTick)}", GameEvents.OneSecondTick?.GetInvocationList()); } - - /// <summary>Raise a <see cref="FirstUpdateTick"/> event.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> - internal static void InvokeFirstUpdateTick(IMonitor monitor) - { - monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.FirstUpdateTick)}", GameEvents.FirstUpdateTick?.GetInvocationList()); - } } } |