diff options
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Events/ContentEvents.cs | 15 | ||||
-rw-r--r-- | src/SMAPI/Events/ControlEvents.cs | 57 | ||||
-rw-r--r-- | src/SMAPI/Events/GameEvents.cs | 57 | ||||
-rw-r--r-- | src/SMAPI/Events/GraphicsEvents.cs | 51 | ||||
-rw-r--r-- | src/SMAPI/Events/InputEvents.cs | 21 | ||||
-rw-r--r-- | src/SMAPI/Events/LocationEvents.cs | 27 | ||||
-rw-r--r-- | src/SMAPI/Events/MenuEvents.cs | 21 | ||||
-rw-r--r-- | src/SMAPI/Events/MineEvents.cs | 15 | ||||
-rw-r--r-- | src/SMAPI/Events/MultiplayerEvents.cs | 33 | ||||
-rw-r--r-- | src/SMAPI/Events/PlayerEvents.cs | 27 | ||||
-rw-r--r-- | src/SMAPI/Events/SaveEvents.cs | 45 | ||||
-rw-r--r-- | src/SMAPI/Events/SpecialisedEvents.cs | 15 | ||||
-rw-r--r-- | src/SMAPI/Events/TimeEvents.cs | 21 | ||||
-rw-r--r-- | src/SMAPI/Framework/DeprecationManager.cs | 6 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 26 | ||||
-rw-r--r-- | src/SMAPI/IModHelper.cs | 1 |
16 files changed, 363 insertions, 75 deletions
diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs index 3ee0560b..3bf3881b 100644 --- a/src/SMAPI/Events/ContentEvents.cs +++ b/src/SMAPI/Events/ContentEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the game loads content.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class ContentEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the content language changes.</summary> public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged { - add => ContentEvents.EventManager.Legacy_LocaleChanged.Add(value); + add + { + ContentEvents.DeprecationManager.WarnForOldEvents(); + ContentEvents.EventManager.Legacy_LocaleChanged.Add(value); + } remove => ContentEvents.EventManager.Legacy_LocaleChanged.Remove(value); } @@ -29,9 +38,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { ContentEvents.EventManager = eventManager; + ContentEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index 56a4fa3f..c50d5bea 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -1,10 +1,12 @@ using System; using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the player uses a controller, keyboard, or mouse.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class ControlEvents { /********* @@ -13,6 +15,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -20,56 +25,88 @@ namespace StardewModdingAPI.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 { - add => ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value); + } remove => ControlEvents.EventManager.Legacy_KeyboardChanged.Remove(value); } /// <summary>Raised after the player presses a keyboard key.</summary> public static event EventHandler<EventArgsKeyPressed> KeyPressed { - add => ControlEvents.EventManager.Legacy_KeyPressed.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_KeyPressed.Add(value); + } remove => ControlEvents.EventManager.Legacy_KeyPressed.Remove(value); } /// <summary>Raised after the player releases a keyboard key.</summary> public static event EventHandler<EventArgsKeyPressed> KeyReleased { - add => ControlEvents.EventManager.Legacy_KeyReleased.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_KeyReleased.Add(value); + } remove => ControlEvents.EventManager.Legacy_KeyReleased.Remove(value); } /// <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 { - add => ControlEvents.EventManager.Legacy_MouseChanged.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_MouseChanged.Add(value); + } remove => ControlEvents.EventManager.Legacy_MouseChanged.Remove(value); } /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary> public static event EventHandler<EventArgsControllerButtonPressed> ControllerButtonPressed { - add => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Remove(value); } /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary> public static event EventHandler<EventArgsControllerButtonReleased> ControllerButtonReleased { - add => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Remove(value); } /// <summary>The player pressed a controller trigger button.</summary> public static event EventHandler<EventArgsControllerTriggerPressed> ControllerTriggerPressed { - add => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Remove(value); } /// <summary>The player released a controller trigger button.</summary> public static event EventHandler<EventArgsControllerTriggerReleased> ControllerTriggerReleased { - add => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Remove(value); } @@ -79,9 +116,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { ControlEvents.EventManager = eventManager; + ControlEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs index 952b3570..13f6bfb0 100644 --- a/src/SMAPI/Events/GameEvents.cs +++ b/src/SMAPI/Events/GameEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the game changes state.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class GameEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,56 +24,88 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the game updates its state (≈60 times per second).</summary> public static event EventHandler UpdateTick { - add => GameEvents.EventManager.Legacy_UpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_UpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_UpdateTick.Remove(value); } /// <summary>Raised every other tick (≈30 times per second).</summary> public static event EventHandler SecondUpdateTick { - add => GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_SecondUpdateTick.Remove(value); } /// <summary>Raised every fourth tick (≈15 times per second).</summary> public static event EventHandler FourthUpdateTick { - add => GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_FourthUpdateTick.Remove(value); } /// <summary>Raised every eighth tick (≈8 times per second).</summary> public static event EventHandler EighthUpdateTick { - add => GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_EighthUpdateTick.Remove(value); } /// <summary>Raised every 15th tick (≈4 times per second).</summary> public static event EventHandler QuarterSecondTick { - add => GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value); + } remove => GameEvents.EventManager.Legacy_QuarterSecondTick.Remove(value); } /// <summary>Raised every 30th tick (≈twice per second).</summary> public static event EventHandler HalfSecondTick { - add => GameEvents.EventManager.Legacy_HalfSecondTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_HalfSecondTick.Add(value); + } remove => GameEvents.EventManager.Legacy_HalfSecondTick.Remove(value); } /// <summary>Raised every 60th tick (≈once per second).</summary> public static event EventHandler OneSecondTick { - add => GameEvents.EventManager.Legacy_OneSecondTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_OneSecondTick.Add(value); + } remove => GameEvents.EventManager.Legacy_OneSecondTick.Remove(value); } /// <summary>Raised once after the game initialises and all <see cref="IMod.Entry"/> methods have been called.</summary> public static event EventHandler FirstUpdateTick { - add => GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_FirstUpdateTick.Remove(value); } @@ -78,9 +115,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { GameEvents.EventManager = eventManager; + GameEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs index 53f04822..de79e42e 100644 --- a/src/SMAPI/Events/GraphicsEvents.cs +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised during the game's draw loop, when the game is rendering content to the window.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class GraphicsEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the game window is resized.</summary> public static event EventHandler Resize { - add => GraphicsEvents.EventManager.Legacy_Resize.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_Resize.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_Resize.Remove(value); } @@ -29,14 +38,22 @@ namespace StardewModdingAPI.Events /// <summary>Raised before drawing the world to the screen.</summary> public static event EventHandler OnPreRenderEvent { - add => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Remove(value); } /// <summary>Raised after drawing the world to the screen.</summary> public static event EventHandler OnPostRenderEvent { - add => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Remove(value); } @@ -46,14 +63,22 @@ namespace StardewModdingAPI.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 { - add => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Remove(value); } /// <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 { - add => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Remove(value); } @@ -63,14 +88,22 @@ namespace StardewModdingAPI.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 { - add => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Remove(value); } /// <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 { - add => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Remove(value); } @@ -80,9 +113,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { GraphicsEvents.EventManager = eventManager; + GraphicsEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index 4c1781a5..788dde62 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the player uses a controller, keyboard, or mouse button.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class InputEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,14 +24,22 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary> public static event EventHandler<EventArgsInput> ButtonPressed { - add => InputEvents.EventManager.Legacy_ButtonPressed.Add(value); + add + { + InputEvents.DeprecationManager.WarnForOldEvents(); + InputEvents.EventManager.Legacy_ButtonPressed.Add(value); + } remove => InputEvents.EventManager.Legacy_ButtonPressed.Remove(value); } /// <summary>Raised when the player releases a keyboard key on the keyboard, controller, or mouse.</summary> public static event EventHandler<EventArgsInput> ButtonReleased { - add => InputEvents.EventManager.Legacy_ButtonReleased.Add(value); + add + { + InputEvents.DeprecationManager.WarnForOldEvents(); + InputEvents.EventManager.Legacy_ButtonReleased.Add(value); + } remove => InputEvents.EventManager.Legacy_ButtonReleased.Remove(value); } @@ -36,9 +49,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { InputEvents.EventManager = eventManager; + InputEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs index 81f547ae..4aad5387 100644 --- a/src/SMAPI/Events/LocationEvents.cs +++ b/src/SMAPI/Events/LocationEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the player transitions between game locations, a location is added or removed, or the objects in the current location change.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class LocationEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,21 +24,33 @@ namespace StardewModdingAPI.Events /// <summary>Raised after a game location is added or removed.</summary> public static event EventHandler<EventArgsLocationsChanged> LocationsChanged { - add => LocationEvents.EventManager.Legacy_LocationsChanged.Add(value); + add + { + LocationEvents.DeprecationManager.WarnForOldEvents(); + LocationEvents.EventManager.Legacy_LocationsChanged.Add(value); + } remove => LocationEvents.EventManager.Legacy_LocationsChanged.Remove(value); } /// <summary>Raised after buildings are added or removed in a location.</summary> public static event EventHandler<EventArgsLocationBuildingsChanged> BuildingsChanged { - add => LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value); + add + { + LocationEvents.DeprecationManager.WarnForOldEvents(); + LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value); + } remove => LocationEvents.EventManager.Legacy_BuildingsChanged.Remove(value); } /// <summary>Raised after objects are added or removed in a location.</summary> public static event EventHandler<EventArgsLocationObjectsChanged> ObjectsChanged { - add => LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value); + add + { + LocationEvents.DeprecationManager.WarnForOldEvents(); + LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value); + } remove => LocationEvents.EventManager.Legacy_ObjectsChanged.Remove(value); } @@ -43,9 +60,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { LocationEvents.EventManager = eventManager; + LocationEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MenuEvents.cs b/src/SMAPI/Events/MenuEvents.cs index 362b5070..502ec340 100644 --- a/src/SMAPI/Events/MenuEvents.cs +++ b/src/SMAPI/Events/MenuEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when a game menu is opened or closed (including internal menus like the title screen).</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class MenuEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,14 +24,22 @@ namespace StardewModdingAPI.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 { - add => MenuEvents.EventManager.Legacy_MenuChanged.Add(value); + add + { + MenuEvents.DeprecationManager.WarnForOldEvents(); + MenuEvents.EventManager.Legacy_MenuChanged.Add(value); + } remove => MenuEvents.EventManager.Legacy_MenuChanged.Remove(value); } /// <summary>Raised after a game menu is closed.</summary> public static event EventHandler<EventArgsClickableMenuClosed> MenuClosed { - add => MenuEvents.EventManager.Legacy_MenuClosed.Add(value); + add + { + MenuEvents.DeprecationManager.WarnForOldEvents(); + MenuEvents.EventManager.Legacy_MenuClosed.Add(value); + } remove => MenuEvents.EventManager.Legacy_MenuClosed.Remove(value); } @@ -36,9 +49,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { MenuEvents.EventManager = eventManager; + MenuEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MineEvents.cs b/src/SMAPI/Events/MineEvents.cs index f5565a76..617c8013 100644 --- a/src/SMAPI/Events/MineEvents.cs +++ b/src/SMAPI/Events/MineEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when something happens in the mines.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class MineEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the player warps to a new level of the mine.</summary> public static event EventHandler<EventArgsMineLevelChanged> MineLevelChanged { - add => MineEvents.EventManager.Legacy_MineLevelChanged.Add(value); + add + { + MineEvents.DeprecationManager.WarnForOldEvents(); + MineEvents.EventManager.Legacy_MineLevelChanged.Add(value); + } remove => MineEvents.EventManager.Legacy_MineLevelChanged.Remove(value); } @@ -29,9 +38,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { MineEvents.EventManager = eventManager; + MineEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MultiplayerEvents.cs b/src/SMAPI/Events/MultiplayerEvents.cs index 49de380e..14c58031 100644 --- a/src/SMAPI/Events/MultiplayerEvents.cs +++ b/src/SMAPI/Events/MultiplayerEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised during the multiplayer sync process.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class MultiplayerEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,28 +24,44 @@ namespace StardewModdingAPI.Events /// <summary>Raised before the game syncs changes from other players.</summary> public static event EventHandler BeforeMainSync { - add => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Remove(value); } /// <summary>Raised after the game syncs changes from other players.</summary> public static event EventHandler AfterMainSync { - add => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Remove(value); } /// <summary>Raised before the game broadcasts changes to other players.</summary> public static event EventHandler BeforeMainBroadcast { - add => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Remove(value); } /// <summary>Raised after the game broadcasts changes to other players.</summary> public static event EventHandler AfterMainBroadcast { - add => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Remove(value); } @@ -50,9 +71,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { MultiplayerEvents.EventManager = eventManager; + MultiplayerEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs index bfc1b569..4f5f4a37 100644 --- a/src/SMAPI/Events/PlayerEvents.cs +++ b/src/SMAPI/Events/PlayerEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the player data changes.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class PlayerEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,21 +24,33 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the player's inventory changes in any way (added or removed item, sorted, etc).</summary> public static event EventHandler<EventArgsInventoryChanged> InventoryChanged { - add => PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value); + add + { + PlayerEvents.DeprecationManager.WarnForOldEvents(); + PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value); + } remove => PlayerEvents.EventManager.Legacy_InventoryChanged.Remove(value); } /// <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 { - add => PlayerEvents.EventManager.Legacy_LeveledUp.Add(value); + add + { + PlayerEvents.DeprecationManager.WarnForOldEvents(); + PlayerEvents.EventManager.Legacy_LeveledUp.Add(value); + } remove => PlayerEvents.EventManager.Legacy_LeveledUp.Remove(value); } /// <summary>Raised after the player warps to a new location.</summary> public static event EventHandler<EventArgsPlayerWarped> Warped { - add => PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value); + add + { + PlayerEvents.DeprecationManager.WarnForOldEvents(); + PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value); + } remove => PlayerEvents.EventManager.Legacy_PlayerWarped.Remove(value); } @@ -44,9 +61,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { PlayerEvents.EventManager = eventManager; + PlayerEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/SaveEvents.cs b/src/SMAPI/Events/SaveEvents.cs index 731bf9d1..5b83efc8 100644 --- a/src/SMAPI/Events/SaveEvents.cs +++ b/src/SMAPI/Events/SaveEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised before and after the player saves/loads the game.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class SaveEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,42 +24,66 @@ namespace StardewModdingAPI.Events /// <summary>Raised before the game creates the save file.</summary> public static event EventHandler BeforeCreate { - add => SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_BeforeCreateSave.Remove(value); } /// <summary>Raised after the game finishes creating the save file.</summary> public static event EventHandler AfterCreate { - add => SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterCreateSave.Remove(value); } /// <summary>Raised before the game begins writes data to the save file.</summary> public static event EventHandler BeforeSave { - add => SaveEvents.EventManager.Legacy_BeforeSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_BeforeSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_BeforeSave.Remove(value); } /// <summary>Raised after the game finishes writing data to the save file.</summary> public static event EventHandler AfterSave { - add => SaveEvents.EventManager.Legacy_AfterSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterSave.Remove(value); } /// <summary>Raised after the player loads a save slot.</summary> public static event EventHandler AfterLoad { - add => SaveEvents.EventManager.Legacy_AfterLoad.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterLoad.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterLoad.Remove(value); } /// <summary>Raised after the game returns to the title screen.</summary> public static event EventHandler AfterReturnToTitle { - add => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Remove(value); } @@ -64,9 +93,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { SaveEvents.EventManager = eventManager; + SaveEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/SpecialisedEvents.cs b/src/SMAPI/Events/SpecialisedEvents.cs index bdf25ccb..482ac62e 100644 --- a/src/SMAPI/Events/SpecialisedEvents.cs +++ b/src/SMAPI/Events/SpecialisedEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events serving specialised edge cases that shouldn't be used by most mods.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class SpecialisedEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// <summary>Raised when the game updates its state (≈60 times per second), regardless of normal SMAPI validation. This event is not thread-safe and may be invoked while game logic is running asynchronously. Changes to game state in this method may crash the game or corrupt an in-progress save. Do not use this event unless you're fully aware of the context in which your code will be run. Mods using this method will trigger a stability warning in the SMAPI console.</summary> public static event EventHandler UnvalidatedUpdateTick { - add => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value); + add + { + SpecialisedEvents.DeprecationManager.WarnForOldEvents(); + SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value); + } remove => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Remove(value); } @@ -29,9 +38,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { SpecialisedEvents.EventManager = eventManager; + SpecialisedEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/TimeEvents.cs b/src/SMAPI/Events/TimeEvents.cs index 311ffe9e..cca6a056 100644 --- a/src/SMAPI/Events/TimeEvents.cs +++ b/src/SMAPI/Events/TimeEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// <summary>Events raised when the in-game date or time changes.</summary> + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class TimeEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// <summary>The core event manager.</summary> private static EventManager EventManager; + /// <summary>Manages deprecation warnings.</summary> + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,14 +24,22 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the game begins a new day, including when loading a save.</summary> public static event EventHandler AfterDayStarted { - add => TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value); + add + { + TimeEvents.DeprecationManager.WarnForOldEvents(); + TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value); + } remove => TimeEvents.EventManager.Legacy_AfterDayStarted.Remove(value); } /// <summary>Raised after the in-game clock changes.</summary> public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged { - add => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value); + add + { + TimeEvents.DeprecationManager.WarnForOldEvents(); + TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value); + } remove => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Remove(value); } @@ -36,9 +49,11 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Initialise the events.</summary> /// <param name="eventManager">The core event manager.</param> - internal static void Init(EventManager eventManager) + /// <param name="deprecationManager">Manages deprecation warnings.</param> + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { TimeEvents.EventManager = eventManager; + TimeEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs index 0fde67ee..be564c22 100644 --- a/src/SMAPI/Framework/DeprecationManager.cs +++ b/src/SMAPI/Framework/DeprecationManager.cs @@ -35,6 +35,12 @@ namespace StardewModdingAPI.Framework this.ModRegistry = modRegistry; } + /// <summary>Log a deprecation warning for the old-style events.</summary> + public void WarnForOldEvents() + { + this.Warn("legacy events", "2.9", DeprecationLevel.Notice); + } + /// <summary>Log a deprecation warning.</summary> /// <param name="nounPhrase">A noun phrase describing what is deprecated.</param> /// <param name="version">The SMAPI version which deprecated it.</param> diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 4b95917b..827ed82c 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -181,19 +181,19 @@ namespace StardewModdingAPI.Framework try { // hook up events - ContentEvents.Init(this.EventManager); - ControlEvents.Init(this.EventManager); - GameEvents.Init(this.EventManager); - GraphicsEvents.Init(this.EventManager); - InputEvents.Init(this.EventManager); - LocationEvents.Init(this.EventManager); - MenuEvents.Init(this.EventManager); - MineEvents.Init(this.EventManager); - MultiplayerEvents.Init(this.EventManager); - PlayerEvents.Init(this.EventManager); - SaveEvents.Init(this.EventManager); - SpecialisedEvents.Init(this.EventManager); - TimeEvents.Init(this.EventManager); + ContentEvents.Init(this.EventManager, this.DeprecationManager); + ControlEvents.Init(this.EventManager, this.DeprecationManager); + GameEvents.Init(this.EventManager, this.DeprecationManager); + GraphicsEvents.Init(this.EventManager, this.DeprecationManager); + InputEvents.Init(this.EventManager, this.DeprecationManager); + LocationEvents.Init(this.EventManager, this.DeprecationManager); + MenuEvents.Init(this.EventManager, this.DeprecationManager); + MineEvents.Init(this.EventManager, this.DeprecationManager); + MultiplayerEvents.Init(this.EventManager, this.DeprecationManager); + PlayerEvents.Init(this.EventManager, this.DeprecationManager); + SaveEvents.Init(this.EventManager, this.DeprecationManager); + SpecialisedEvents.Init(this.EventManager, this.DeprecationManager); + TimeEvents.Init(this.EventManager, this.DeprecationManager); // init JSON parser JsonConverter[] converters = { diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs index e4b5d390..7e82e0d0 100644 --- a/src/SMAPI/IModHelper.cs +++ b/src/SMAPI/IModHelper.cs @@ -14,7 +14,6 @@ namespace StardewModdingAPI string DirectoryPath { get; } /// <summary>Manages access to events raised by SMAPI, which let your mod react when something happens in the game.</summary> - [Obsolete("This is an experimental interface which may change at any time. Don't depend on this for released mods.")] IModEvents Events { get; } /// <summary>An API for managing console commands.</summary> |