diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-12-07 13:40:44 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-12-07 13:40:44 -0500 |
commit | a78b1935928919694dfe8de823a1accd6d222732 (patch) | |
tree | 3f17b6087cf2749e52c1e237de17e2e9addb6c06 /src/SMAPI/Events | |
parent | 4cd9eda1591c3908bf80b60c2902491a7595ee27 (diff) | |
parent | 8901218418693d610a17b22fe789ba6279f63446 (diff) | |
download | SMAPI-a78b1935928919694dfe8de823a1accd6d222732.tar.gz SMAPI-a78b1935928919694dfe8de823a1accd6d222732.tar.bz2 SMAPI-a78b1935928919694dfe8de823a1accd6d222732.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Events')
51 files changed, 444 insertions, 88 deletions
diff --git a/src/SMAPI/Events/BuildingListChangedEventArgs.cs b/src/SMAPI/Events/BuildingListChangedEventArgs.cs index 9bc691fc..0237342f 100644 --- a/src/SMAPI/Events/BuildingListChangedEventArgs.cs +++ b/src/SMAPI/Events/BuildingListChangedEventArgs.cs @@ -29,7 +29,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The buildings added to the location.</param> /// <param name="removed">The buildings removed from the location.</param> - public BuildingListChangedEventArgs(GameLocation location, IEnumerable<Building> added, IEnumerable<Building> removed) + internal BuildingListChangedEventArgs(GameLocation location, IEnumerable<Building> added, IEnumerable<Building> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs index 3ee0560b..99369cae 100644 --- a/src/SMAPI/Events/ContentEvents.cs +++ b/src/SMAPI/Events/ContentEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,7 +25,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 +39,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index 56a4fa3f..5626ff81 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -1,10 +1,13 @@ +#if !SMAPI_3_0_STRICT 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 +16,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 +26,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 +117,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/CursorMovedEventArgs.cs b/src/SMAPI/Events/CursorMovedEventArgs.cs index 453743b9..43ff90ce 100644 --- a/src/SMAPI/Events/CursorMovedEventArgs.cs +++ b/src/SMAPI/Events/CursorMovedEventArgs.cs @@ -21,7 +21,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="oldPosition">The previous cursor position.</param> /// <param name="newPosition">The new cursor position.</param> - public CursorMovedEventArgs(ICursorPosition oldPosition, ICursorPosition newPosition) + internal CursorMovedEventArgs(ICursorPosition oldPosition, ICursorPosition newPosition) { this.OldPosition = oldPosition; this.NewPosition = newPosition; diff --git a/src/SMAPI/Events/DebrisListChangedEventArgs.cs b/src/SMAPI/Events/DebrisListChangedEventArgs.cs index 1337bd3b..68328885 100644 --- a/src/SMAPI/Events/DebrisListChangedEventArgs.cs +++ b/src/SMAPI/Events/DebrisListChangedEventArgs.cs @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The debris added to the location.</param> /// <param name="removed">The debris removed from the location.</param> - public DebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed) + internal DebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/EventArgsClickableMenuChanged.cs b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs index 2a2aa163..a0b903b7 100644 --- a/src/SMAPI/Events/EventArgsClickableMenuChanged.cs +++ b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using StardewValley.Menus; namespace StardewModdingAPI.Events @@ -29,3 +30,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsClickableMenuClosed.cs b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs index 5e6585f0..77db69ea 100644 --- a/src/SMAPI/Events/EventArgsClickableMenuClosed.cs +++ b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using StardewValley.Menus; namespace StardewModdingAPI.Events @@ -24,3 +25,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerButtonPressed.cs b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs index 3243b80b..949446e1 100644 --- a/src/SMAPI/Events/EventArgsControllerButtonPressed.cs +++ b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerButtonReleased.cs b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs index e05a080b..d6d6d840 100644 --- a/src/SMAPI/Events/EventArgsControllerButtonReleased.cs +++ b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs index a2087733..33be2fa3 100644 --- a/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs +++ b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -35,3 +36,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs index d2eecbec..e90ff712 100644 --- a/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs +++ b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -35,3 +36,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index 0cafdba5..837de2f8 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; @@ -60,3 +61,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsIntChanged.cs b/src/SMAPI/Events/EventArgsIntChanged.cs index a018695c..76ec6d08 100644 --- a/src/SMAPI/Events/EventArgsIntChanged.cs +++ b/src/SMAPI/Events/EventArgsIntChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; namespace StardewModdingAPI.Events @@ -28,3 +29,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsInventoryChanged.cs b/src/SMAPI/Events/EventArgsInventoryChanged.cs index 3a2354b6..488dd23f 100644 --- a/src/SMAPI/Events/EventArgsInventoryChanged.cs +++ b/src/SMAPI/Events/EventArgsInventoryChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -39,3 +40,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsKeyPressed.cs b/src/SMAPI/Events/EventArgsKeyPressed.cs index d9d81e10..6204d821 100644 --- a/src/SMAPI/Events/EventArgsKeyPressed.cs +++ b/src/SMAPI/Events/EventArgsKeyPressed.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework.Input; @@ -24,3 +25,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs index 14e397ce..2c3203b1 100644 --- a/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs +++ b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework.Input; @@ -29,3 +30,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLevelUp.cs b/src/SMAPI/Events/EventArgsLevelUp.cs index e9a697e7..06c70088 100644 --- a/src/SMAPI/Events/EventArgsLevelUp.cs +++ b/src/SMAPI/Events/EventArgsLevelUp.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Enums; @@ -51,3 +52,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs b/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs index e8184ebe..25e84722 100644 --- a/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs +++ b/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -37,3 +38,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs index 3bb387d5..9ca2e3e2 100644 --- a/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs +++ b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -38,3 +39,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLocationsChanged.cs b/src/SMAPI/Events/EventArgsLocationsChanged.cs index 20984f45..1a59e612 100644 --- a/src/SMAPI/Events/EventArgsLocationsChanged.cs +++ b/src/SMAPI/Events/EventArgsLocationsChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -31,3 +32,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsMineLevelChanged.cs b/src/SMAPI/Events/EventArgsMineLevelChanged.cs index c82fed35..c63b04e9 100644 --- a/src/SMAPI/Events/EventArgsMineLevelChanged.cs +++ b/src/SMAPI/Events/EventArgsMineLevelChanged.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; namespace StardewModdingAPI.Events { @@ -28,3 +29,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsMouseStateChanged.cs b/src/SMAPI/Events/EventArgsMouseStateChanged.cs index 57298164..09f3f759 100644 --- a/src/SMAPI/Events/EventArgsMouseStateChanged.cs +++ b/src/SMAPI/Events/EventArgsMouseStateChanged.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -40,3 +41,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsPlayerWarped.cs b/src/SMAPI/Events/EventArgsPlayerWarped.cs index 93026aea..d1aa1588 100644 --- a/src/SMAPI/Events/EventArgsPlayerWarped.cs +++ b/src/SMAPI/Events/EventArgsPlayerWarped.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewValley; @@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsValueChanged.cs b/src/SMAPI/Events/EventArgsValueChanged.cs index 1d25af49..7bfac7a2 100644 --- a/src/SMAPI/Events/EventArgsValueChanged.cs +++ b/src/SMAPI/Events/EventArgsValueChanged.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; namespace StardewModdingAPI.Events { @@ -28,4 +29,5 @@ namespace StardewModdingAPI.Events this.NewValue = newValue; } } -}
\ No newline at end of file +} +#endif diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs index 952b3570..39b77f99 100644 --- a/src/SMAPI/Events/GameEvents.cs +++ b/src/SMAPI/Events/GameEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,56 +25,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 +116,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs index 53f04822..be29bf11 100644 --- a/src/SMAPI/Events/GraphicsEvents.cs +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,7 +25,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 +39,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 +64,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 +89,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 +114,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index 4c1781a5..255b9c8a 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,14 +25,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 +50,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/InventoryChangedEventArgs.cs b/src/SMAPI/Events/InventoryChangedEventArgs.cs index a081611b..874c2e48 100644 --- a/src/SMAPI/Events/InventoryChangedEventArgs.cs +++ b/src/SMAPI/Events/InventoryChangedEventArgs.cs @@ -23,6 +23,9 @@ namespace StardewModdingAPI.Events /// <summary>The items whose stack sizes changed, with the relative change.</summary> public IEnumerable<ItemStackSizeChange> QuantityChanged { get; } + /// <summary>Whether the affected player is the local one.</summary> + public bool IsLocalPlayer => this.Player.IsLocalPlayer; + /********* ** Public methods @@ -30,7 +33,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="player">The player whose inventory changed.</param> /// <param name="changedItems">The inventory changes.</param> - public InventoryChangedEventArgs(Farmer player, ItemStackChange[] changedItems) + internal InventoryChangedEventArgs(Farmer player, ItemStackChange[] changedItems) { this.Player = player; this.Added = changedItems diff --git a/src/SMAPI/Events/LargeTerrainFeatureListChangedEventArgs.cs b/src/SMAPI/Events/LargeTerrainFeatureListChangedEventArgs.cs index 63b12687..c7d55bf8 100644 --- a/src/SMAPI/Events/LargeTerrainFeatureListChangedEventArgs.cs +++ b/src/SMAPI/Events/LargeTerrainFeatureListChangedEventArgs.cs @@ -29,7 +29,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The large terrain features added to the location.</param> /// <param name="removed">The large terrain features removed from the location.</param> - public LargeTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<LargeTerrainFeature> added, IEnumerable<LargeTerrainFeature> removed) + internal LargeTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<LargeTerrainFeature> added, IEnumerable<LargeTerrainFeature> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/LevelChangedEventArgs.cs b/src/SMAPI/Events/LevelChangedEventArgs.cs index 174094c7..c7303603 100644 --- a/src/SMAPI/Events/LevelChangedEventArgs.cs +++ b/src/SMAPI/Events/LevelChangedEventArgs.cs @@ -22,6 +22,9 @@ namespace StardewModdingAPI.Events /// <summary>The new skill level.</summary> public int NewLevel { get; } + /// <summary>Whether the affected player is the local one.</summary> + public bool IsLocalPlayer => this.Player.IsLocalPlayer; + /********* ** Public methods @@ -31,7 +34,7 @@ namespace StardewModdingAPI.Events /// <param name="skill">The skill whose level changed.</param> /// <param name="oldLevel">The previous skill level.</param> /// <param name="newLevel">The new skill level.</param> - public LevelChangedEventArgs(Farmer player, SkillType skill, int oldLevel, int newLevel) + internal LevelChangedEventArgs(Farmer player, SkillType skill, int oldLevel, int newLevel) { this.Player = player; this.Skill = skill; diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs index 81f547ae..e0bcd853 100644 --- a/src/SMAPI/Events/LocationEvents.cs +++ b/src/SMAPI/Events/LocationEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,21 +25,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 +61,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/LocationListChangedEventArgs.cs b/src/SMAPI/Events/LocationListChangedEventArgs.cs index e93f0a80..1ebb3e2d 100644 --- a/src/SMAPI/Events/LocationListChangedEventArgs.cs +++ b/src/SMAPI/Events/LocationListChangedEventArgs.cs @@ -24,7 +24,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="added">The added locations.</param> /// <param name="removed">The removed locations.</param> - public LocationListChangedEventArgs(IEnumerable<GameLocation> added, IEnumerable<GameLocation> removed) + internal LocationListChangedEventArgs(IEnumerable<GameLocation> added, IEnumerable<GameLocation> removed) { this.Added = added.ToArray(); this.Removed = removed.ToArray(); diff --git a/src/SMAPI/Events/MenuChangedEventArgs.cs b/src/SMAPI/Events/MenuChangedEventArgs.cs index e1c049a2..977ba38b 100644 --- a/src/SMAPI/Events/MenuChangedEventArgs.cs +++ b/src/SMAPI/Events/MenuChangedEventArgs.cs @@ -22,7 +22,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="oldMenu">The previous menu.</param> /// <param name="newMenu">The current menu.</param> - public MenuChangedEventArgs(IClickableMenu oldMenu, IClickableMenu newMenu) + internal MenuChangedEventArgs(IClickableMenu oldMenu, IClickableMenu newMenu) { this.OldMenu = oldMenu; this.NewMenu = newMenu; diff --git a/src/SMAPI/Events/MenuEvents.cs b/src/SMAPI/Events/MenuEvents.cs index 362b5070..e36cb498 100644 --- a/src/SMAPI/Events/MenuEvents.cs +++ b/src/SMAPI/Events/MenuEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,14 +25,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 +50,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/MineEvents.cs b/src/SMAPI/Events/MineEvents.cs index f5565a76..954c844a 100644 --- a/src/SMAPI/Events/MineEvents.cs +++ b/src/SMAPI/Events/MineEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,7 +25,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 +39,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/MouseWheelScrolledEventArgs.cs b/src/SMAPI/Events/MouseWheelScrolledEventArgs.cs index 3ab9d412..0c736b39 100644 --- a/src/SMAPI/Events/MouseWheelScrolledEventArgs.cs +++ b/src/SMAPI/Events/MouseWheelScrolledEventArgs.cs @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events /// <param name="position">The cursor position.</param> /// <param name="oldValue">The old scroll value.</param> /// <param name="newValue">The new scroll value.</param> - public MouseWheelScrolledEventArgs(ICursorPosition position, int oldValue, int newValue) + internal MouseWheelScrolledEventArgs(ICursorPosition position, int oldValue, int newValue) { this.Position = position; this.OldValue = oldValue; diff --git a/src/SMAPI/Events/MultiplayerEvents.cs b/src/SMAPI/Events/MultiplayerEvents.cs index 49de380e..7e8328a4 100644 --- a/src/SMAPI/Events/MultiplayerEvents.cs +++ b/src/SMAPI/Events/MultiplayerEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,28 +25,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 +72,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/NpcListChangedEventArgs.cs b/src/SMAPI/Events/NpcListChangedEventArgs.cs index eca28244..a9ec2a3b 100644 --- a/src/SMAPI/Events/NpcListChangedEventArgs.cs +++ b/src/SMAPI/Events/NpcListChangedEventArgs.cs @@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The NPCs added to the location.</param> /// <param name="removed">The NPCs removed from the location.</param> - public NpcListChangedEventArgs(GameLocation location, IEnumerable<NPC> added, IEnumerable<NPC> removed) + internal NpcListChangedEventArgs(GameLocation location, IEnumerable<NPC> added, IEnumerable<NPC> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/ObjectListChangedEventArgs.cs b/src/SMAPI/Events/ObjectListChangedEventArgs.cs index 55a4034f..d0cf9e7b 100644 --- a/src/SMAPI/Events/ObjectListChangedEventArgs.cs +++ b/src/SMAPI/Events/ObjectListChangedEventArgs.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The objects added to the location.</param> /// <param name="removed">The objects removed from the location.</param> - public ObjectListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, Object>> added, IEnumerable<KeyValuePair<Vector2, Object>> removed) + internal ObjectListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, Object>> added, IEnumerable<KeyValuePair<Vector2, Object>> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs index bfc1b569..1193675f 100644 --- a/src/SMAPI/Events/PlayerEvents.cs +++ b/src/SMAPI/Events/PlayerEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,21 +25,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 +62,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/SaveEvents.cs b/src/SMAPI/Events/SaveEvents.cs index 731bf9d1..156d3047 100644 --- a/src/SMAPI/Events/SaveEvents.cs +++ b/src/SMAPI/Events/SaveEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,42 +25,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 +94,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/SpecialisedEvents.cs b/src/SMAPI/Events/SpecialisedEvents.cs index bdf25ccb..0dd726e9 100644 --- a/src/SMAPI/Events/SpecialisedEvents.cs +++ b/src/SMAPI/Events/SpecialisedEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,7 +25,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 +39,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/TerrainFeatureListChangedEventArgs.cs b/src/SMAPI/Events/TerrainFeatureListChangedEventArgs.cs index 562b1d3c..0992633e 100644 --- a/src/SMAPI/Events/TerrainFeatureListChangedEventArgs.cs +++ b/src/SMAPI/Events/TerrainFeatureListChangedEventArgs.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI.Events /// <param name="location">The location which changed.</param> /// <param name="added">The terrain features added to the location.</param> /// <param name="removed">The terrain features removed from the location.</param> - public TerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> added, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> removed) + internal TerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> added, IEnumerable<KeyValuePair<Vector2, TerrainFeature>> removed) { this.Location = location; this.Added = added.ToArray(); diff --git a/src/SMAPI/Events/TimeChangedEventArgs.cs b/src/SMAPI/Events/TimeChangedEventArgs.cs index fd472092..d8349bd8 100644 --- a/src/SMAPI/Events/TimeChangedEventArgs.cs +++ b/src/SMAPI/Events/TimeChangedEventArgs.cs @@ -21,7 +21,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="oldTime">The previous time of day in 24-hour notation (like 1600 for 4pm).</param> /// <param name="newTime">The current time of day in 24-hour notation (like 1600 for 4pm).</param> - public TimeChangedEventArgs(int oldTime, int newTime) + internal TimeChangedEventArgs(int oldTime, int newTime) { this.OldTime = oldTime; this.NewTime = newTime; diff --git a/src/SMAPI/Events/TimeEvents.cs b/src/SMAPI/Events/TimeEvents.cs index 311ffe9e..61491dc8 100644 --- a/src/SMAPI/Events/TimeEvents.cs +++ b/src/SMAPI/Events/TimeEvents.cs @@ -1,9 +1,12 @@ +#if !SMAPI_3_0_STRICT 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 +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 @@ -19,14 +25,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 +50,12 @@ 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; } } } +#endif diff --git a/src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs b/src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs index 5638bdb7..95ae59d8 100644 --- a/src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs +++ b/src/SMAPI/Events/UnvalidatedUpdateTickedEventArgs.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Construct an instance.</summary> /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> - public UnvalidatedUpdateTickedEventArgs(uint ticks) + internal UnvalidatedUpdateTickedEventArgs(uint ticks) { this.Ticks = ticks; this.IsOneSecond = this.IsMultipleOf(60); diff --git a/src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs b/src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs index ebadbb99..4ed781e0 100644 --- a/src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs +++ b/src/SMAPI/Events/UnvalidatedUpdateTickingEventArgs.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Construct an instance.</summary> /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> - public UnvalidatedUpdateTickingEventArgs(uint ticks) + internal UnvalidatedUpdateTickingEventArgs(uint ticks) { this.Ticks = ticks; this.IsOneSecond = this.IsMultipleOf(60); diff --git a/src/SMAPI/Events/UpdateTickedEventArgs.cs b/src/SMAPI/Events/UpdateTickedEventArgs.cs index 56912643..3466b731 100644 --- a/src/SMAPI/Events/UpdateTickedEventArgs.cs +++ b/src/SMAPI/Events/UpdateTickedEventArgs.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Construct an instance.</summary> /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> - public UpdateTickedEventArgs(uint ticks) + internal UpdateTickedEventArgs(uint ticks) { this.Ticks = ticks; this.IsOneSecond = this.IsMultipleOf(60); diff --git a/src/SMAPI/Events/UpdateTickingEventArgs.cs b/src/SMAPI/Events/UpdateTickingEventArgs.cs index 5998fd9b..d4913268 100644 --- a/src/SMAPI/Events/UpdateTickingEventArgs.cs +++ b/src/SMAPI/Events/UpdateTickingEventArgs.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Events *********/ /// <summary>Construct an instance.</summary> /// <param name="ticks">The number of ticks elapsed since the game started, including the current tick.</param> - public UpdateTickingEventArgs(uint ticks) + internal UpdateTickingEventArgs(uint ticks) { this.Ticks = ticks; this.IsOneSecond = this.IsMultipleOf(60); diff --git a/src/SMAPI/Events/WarpedEventArgs.cs b/src/SMAPI/Events/WarpedEventArgs.cs index 1b1c7381..95c53ad9 100644 --- a/src/SMAPI/Events/WarpedEventArgs.cs +++ b/src/SMAPI/Events/WarpedEventArgs.cs @@ -18,6 +18,9 @@ namespace StardewModdingAPI.Events /// <summary>The player's current location.</summary> public GameLocation NewLocation { get; } + /// <summary>Whether the affected player is the local one.</summary> + public bool IsLocalPlayer => this.Player.IsLocalPlayer; + /********* @@ -27,7 +30,7 @@ namespace StardewModdingAPI.Events /// <param name="player">The player who warped to a new location.</param> /// <param name="oldLocation">The player's previous location.</param> /// <param name="newLocation">The player's current location.</param> - public WarpedEventArgs(Farmer player, GameLocation oldLocation, GameLocation newLocation) + internal WarpedEventArgs(Farmer player, GameLocation oldLocation, GameLocation newLocation) { this.Player = player; this.NewLocation = newLocation; diff --git a/src/SMAPI/Events/WindowResizedEventArgs.cs b/src/SMAPI/Events/WindowResizedEventArgs.cs index a990ba9d..1852636a 100644 --- a/src/SMAPI/Events/WindowResizedEventArgs.cs +++ b/src/SMAPI/Events/WindowResizedEventArgs.cs @@ -22,7 +22,7 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="oldSize">The previous window size.</param> /// <param name="newSize">The current window size.</param> - public WindowResizedEventArgs(Point oldSize, Point newSize) + internal WindowResizedEventArgs(Point oldSize, Point newSize) { this.OldSize = oldSize; this.NewSize = newSize; |