summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Events
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-07-08 12:54:06 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-07-08 12:54:06 -0400
commit1edd98aef027faa768f56cf0b3591e64e20ba096 (patch)
treeaec210e2b44c9654f29572dd084206a4598896e1 /src/StardewModdingAPI/Events
parent36930ffd7d363d6afd7f8cac4918c7d1c1c3e339 (diff)
parent8743c4115aa142113d791f2d2cd9ba811dcada2c (diff)
downloadSMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.tar.gz
SMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.tar.bz2
SMAPI-1edd98aef027faa768f56cf0b3591e64e20ba096.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Events')
-rw-r--r--src/StardewModdingAPI/Events/ContentEvents.cs65
-rw-r--r--src/StardewModdingAPI/Events/EventArgsCommand.cs4
-rw-r--r--src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs2
-rw-r--r--src/StardewModdingAPI/Events/EventArgsInput.cs126
-rw-r--r--src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs4
-rw-r--r--src/StardewModdingAPI/Events/EventArgsNewDay.cs4
-rw-r--r--src/StardewModdingAPI/Events/EventArgsStringChanged.cs4
-rw-r--r--src/StardewModdingAPI/Events/GameEvents.cs30
-rw-r--r--src/StardewModdingAPI/Events/InputEvents.cs45
-rw-r--r--src/StardewModdingAPI/Events/PlayerEvents.cs10
-rw-r--r--src/StardewModdingAPI/Events/TimeEvents.cs19
11 files changed, 229 insertions, 84 deletions
diff --git a/src/StardewModdingAPI/Events/ContentEvents.cs b/src/StardewModdingAPI/Events/ContentEvents.cs
index 8fa9ae3c..4b4e2ad0 100644
--- a/src/StardewModdingAPI/Events/ContentEvents.cs
+++ b/src/StardewModdingAPI/Events/ContentEvents.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework;
namespace StardewModdingAPI.Events
@@ -8,21 +6,6 @@ namespace StardewModdingAPI.Events
/// <summary>Events raised when the game loads content.</summary>
public static class ContentEvents
{
- /*********
- ** Properties
- *********/
- /// <summary>Tracks the installed mods.</summary>
- private static ModRegistry ModRegistry;
-
- /// <summary>Encapsulates monitoring and logging.</summary>
- private static IMonitor Monitor;
-
- /// <summary>The mods using the experimental API for which a warning has been raised.</summary>
- private static readonly HashSet<string> WarnedMods = new HashSet<string>();
-
- /// <summary>The backing field for <see cref="AfterAssetLoaded"/>.</summary>
- [SuppressMessage("ReSharper", "InconsistentNaming")]
- private static event EventHandler<IContentEventHelper> _AfterAssetLoaded;
/*********
** Events
@@ -30,35 +13,10 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the content language changes.</summary>
public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged;
- /// <summary>Raised when an XNB file is being read into the cache. Mods can change the data here before it's cached.</summary>
-#if EXPERIMENTAL
- public
-#else
- internal
-#endif
- static event EventHandler<IContentEventHelper> AfterAssetLoaded
- {
- add
- {
- ContentEvents.RaiseContentExperimentalWarning();
- ContentEvents._AfterAssetLoaded += value;
- }
- remove => ContentEvents._AfterAssetLoaded -= value;
- }
-
/*********
** Internal methods
*********/
- /// <summary>Injects types required for backwards compatibility.</summary>
- /// <param name="modRegistry">Tracks the installed mods.</param>
- /// <param name="monitor">Encapsulates monitoring and logging.</param>
- internal static void Shim(ModRegistry modRegistry, IMonitor monitor)
- {
- ContentEvents.ModRegistry = modRegistry;
- ContentEvents.Monitor = monitor;
- }
-
/// <summary>Raise an <see cref="AfterLocaleChanged"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
/// <param name="oldLocale">The previous locale.</param>
@@ -67,28 +25,5 @@ namespace StardewModdingAPI.Events
{
monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterLocaleChanged)}", ContentEvents.AfterLocaleChanged?.GetInvocationList(), null, new EventArgsValueChanged<string>(oldLocale, newLocale));
}
-
- /// <summary>Raise an <see cref="AfterAssetLoaded"/> event.</summary>
- /// <param name="monitor">Encapsulates monitoring and logging.</param>
- /// <param name="contentHelper">Encapsulates access and changes to content being read from a data file.</param>
- internal static void InvokeAfterAssetLoaded(IMonitor monitor, IContentEventHelper contentHelper)
- {
- monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterAssetLoaded)}", ContentEvents._AfterAssetLoaded?.GetInvocationList(), null, contentHelper);
- }
-
-
- /*********
- ** Private methods
- *********/
- /// <summary>Raise an 'experimental API' warning for a mod using the content API.</summary>
- private static void RaiseContentExperimentalWarning()
- {
- string modName = ContentEvents.ModRegistry.GetModFromStack() ?? "An unknown mod";
- if (!ContentEvents.WarnedMods.Contains(modName))
- {
- ContentEvents.WarnedMods.Add(modName);
- ContentEvents.Monitor.Log($"{modName} used the undocumented and experimental content API, which may change or be removed without warning.", LogLevel.Warn);
- }
- }
}
}
diff --git a/src/StardewModdingAPI/Events/EventArgsCommand.cs b/src/StardewModdingAPI/Events/EventArgsCommand.cs
index 88a9e5a3..f0435904 100644
--- a/src/StardewModdingAPI/Events/EventArgsCommand.cs
+++ b/src/StardewModdingAPI/Events/EventArgsCommand.cs
@@ -1,4 +1,5 @@
-using System;
+#if !SMAPI_2_0
+using System;
namespace StardewModdingAPI.Events
{
@@ -24,3 +25,4 @@ namespace StardewModdingAPI.Events
}
}
}
+#endif \ No newline at end of file
diff --git a/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs b/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs
index 699d90be..c34fc4ab 100644
--- a/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs
+++ b/src/StardewModdingAPI/Events/EventArgsFarmerChanged.cs
@@ -1,3 +1,4 @@
+#if !SMAPI_2_0
using System;
using SFarmer = StardewValley.Farmer;
@@ -29,3 +30,4 @@ namespace StardewModdingAPI.Events
}
}
}
+#endif \ No newline at end of file
diff --git a/src/StardewModdingAPI/Events/EventArgsInput.cs b/src/StardewModdingAPI/Events/EventArgsInput.cs
new file mode 100644
index 00000000..e5eb7372
--- /dev/null
+++ b/src/StardewModdingAPI/Events/EventArgsInput.cs
@@ -0,0 +1,126 @@
+#if SMAPI_2_0
+using System;
+using System.Linq;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Input;
+using StardewModdingAPI.Utilities;
+using StardewValley;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Event arguments when a button is pressed or released.</summary>
+ public class EventArgsInput : EventArgs
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The button on the controller, keyboard, or mouse.</summary>
+ public SButton Button { get; }
+
+ /// <summary>The current cursor position.</summary>
+ public ICursorPosition Cursor { get; set; }
+
+ /// <summary>Whether the input is considered a 'click' by the game for enabling action.</summary>
+ public bool IsClick { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="button">The button on the controller, keyboard, or mouse.</param>
+ /// <param name="cursor">The cursor position.</param>
+ /// <param name="isClick">Whether the input is considered a 'click' by the game for enabling action.</param>
+ public EventArgsInput(SButton button, ICursorPosition cursor, bool isClick)
+ {
+ this.Button = button;
+ this.Cursor = cursor;
+ this.IsClick = isClick;
+ }
+
+ /// <summary>Prevent the game from handling the vurrent button press. This doesn't prevent other mods from receiving the event.</summary>
+ public void SuppressButton()
+ {
+ this.SuppressButton(this.Button);
+ }
+
+ /// <summary>Prevent the game from handling a button press. This doesn't prevent other mods from receiving the event.</summary>
+ /// <param name="button">The button to suppress.</param>
+ public void SuppressButton(SButton button)
+ {
+ // keyboard
+ if (this.Button.TryGetKeyboard(out Keys key))
+ Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Except(new[] { key }).ToArray());
+
+ // controller
+ else if (this.Button.TryGetController(out Buttons controllerButton))
+ {
+ var newState = GamePad.GetState(PlayerIndex.One);
+ var thumbsticks = Game1.oldPadState.ThumbSticks;
+ var triggers = Game1.oldPadState.Triggers;
+ var buttons = Game1.oldPadState.Buttons;
+ var dpad = Game1.oldPadState.DPad;
+
+ switch (controllerButton)
+ {
+ // d-pad
+ case Buttons.DPadDown:
+ dpad = new GamePadDPad(dpad.Up, newState.DPad.Down, dpad.Left, dpad.Right);
+ break;
+ case Buttons.DPadLeft:
+ dpad = new GamePadDPad(dpad.Up, dpad.Down, newState.DPad.Left, dpad.Right);
+ break;
+ case Buttons.DPadRight:
+ dpad = new GamePadDPad(dpad.Up, dpad.Down, dpad.Left, newState.DPad.Right);
+ break;
+ case Buttons.DPadUp:
+ dpad = new GamePadDPad(newState.DPad.Up, dpad.Down, dpad.Left, dpad.Right);
+ break;
+
+ // trigger
+ case Buttons.LeftTrigger:
+ triggers = new GamePadTriggers(newState.Triggers.Left, triggers.Right);
+ break;
+ case Buttons.RightTrigger:
+ triggers = new GamePadTriggers(triggers.Left, newState.Triggers.Right);
+ break;
+
+ // thumbstick
+ case Buttons.LeftThumbstickDown:
+ case Buttons.LeftThumbstickLeft:
+ case Buttons.LeftThumbstickRight:
+ case Buttons.LeftThumbstickUp:
+ thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Left, thumbsticks.Right);
+ break;
+ case Buttons.RightThumbstickDown:
+ case Buttons.RightThumbstickLeft:
+ case Buttons.RightThumbstickRight:
+ case Buttons.RightThumbstickUp:
+ thumbsticks = new GamePadThumbSticks(newState.ThumbSticks.Right, thumbsticks.Left);
+ break;
+
+ // buttons
+ default:
+ var mask =
+ (buttons.A == ButtonState.Pressed ? Buttons.A : 0)
+ | (buttons.B == ButtonState.Pressed ? Buttons.B : 0)
+ | (buttons.Back == ButtonState.Pressed ? Buttons.Back : 0)
+ | (buttons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0)
+ | (buttons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0)
+ | (buttons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0)
+ | (buttons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0)
+ | (buttons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0)
+ | (buttons.Start == ButtonState.Pressed ? Buttons.Start : 0)
+ | (buttons.X == ButtonState.Pressed ? Buttons.X : 0)
+ | (buttons.Y == ButtonState.Pressed ? Buttons.Y : 0);
+ mask = mask ^ controllerButton;
+ buttons = new GamePadButtons(mask);
+ break;
+ }
+
+ Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs b/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs
index 51d64016..d6fc4594 100644
--- a/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs
+++ b/src/StardewModdingAPI/Events/EventArgsLoadedGameChanged.cs
@@ -1,4 +1,5 @@
-using System;
+#if !SMAPI_2_0
+using System;
namespace StardewModdingAPI.Events
{
@@ -23,3 +24,4 @@ namespace StardewModdingAPI.Events
}
}
}
+#endif \ No newline at end of file
diff --git a/src/StardewModdingAPI/Events/EventArgsNewDay.cs b/src/StardewModdingAPI/Events/EventArgsNewDay.cs
index aba837e4..5bd2ba66 100644
--- a/src/StardewModdingAPI/Events/EventArgsNewDay.cs
+++ b/src/StardewModdingAPI/Events/EventArgsNewDay.cs
@@ -1,4 +1,5 @@
-using System;
+#if !SMAPI_2_0
+using System;
namespace StardewModdingAPI.Events
{
@@ -33,3 +34,4 @@ namespace StardewModdingAPI.Events
}
}
}
+#endif \ No newline at end of file
diff --git a/src/StardewModdingAPI/Events/EventArgsStringChanged.cs b/src/StardewModdingAPI/Events/EventArgsStringChanged.cs
index 85b6fab5..1498cb71 100644
--- a/src/StardewModdingAPI/Events/EventArgsStringChanged.cs
+++ b/src/StardewModdingAPI/Events/EventArgsStringChanged.cs
@@ -1,4 +1,5 @@
-using System;
+#if !SMAPI_2_0
+using System;
namespace StardewModdingAPI.Events
{
@@ -27,3 +28,4 @@ namespace StardewModdingAPI.Events
}
}
}
+#endif \ No newline at end of file
diff --git a/src/StardewModdingAPI/Events/GameEvents.cs b/src/StardewModdingAPI/Events/GameEvents.cs
index 8e3cf662..557b451f 100644
--- a/src/StardewModdingAPI/Events/GameEvents.cs
+++ b/src/StardewModdingAPI/Events/GameEvents.cs
@@ -11,6 +11,7 @@ namespace StardewModdingAPI.Events
/*********
** Properties
*********/
+#if !SMAPI_2_0
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
@@ -29,6 +30,7 @@ namespace StardewModdingAPI.Events
/// <summary>The backing field for <see cref="FirstUpdateTick"/>.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
private static event EventHandler _FirstUpdateTick;
+#endif
/*********
@@ -40,13 +42,14 @@ namespace StardewModdingAPI.Events
/// <summary>Raised during launch after configuring Stardew Valley, loading it into memory, and opening the game window. The window is still blank by this point.</summary>
internal static event EventHandler GameLoadedInternal;
+#if !SMAPI_2_0
/// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called after <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary>
[Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the " + nameof(GameEvents.Initialize) + " event, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")]
public static event EventHandler Initialize
{
add
{
- GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.Initialize)}", "1.10", DeprecationLevel.Info);
+ GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.Initialize)}", "1.10", DeprecationLevel.PendingRemoval);
GameEvents._Initialize += value;
}
remove => GameEvents._Initialize -= value;
@@ -58,7 +61,7 @@ namespace StardewModdingAPI.Events
{
add
{
- GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.LoadContent)}", "1.10", DeprecationLevel.Info);
+ GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.LoadContent)}", "1.10", DeprecationLevel.PendingRemoval);
GameEvents._LoadContent += value;
}
remove => GameEvents._LoadContent -= value;
@@ -70,7 +73,7 @@ namespace StardewModdingAPI.Events
{
add
{
- GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", "1.12", DeprecationLevel.Info);
+ GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", "1.12", DeprecationLevel.PendingRemoval);
GameEvents._GameLoaded += value;
}
remove => GameEvents._GameLoaded -= value;
@@ -82,11 +85,12 @@ namespace StardewModdingAPI.Events
{
add
{
- GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.FirstUpdateTick)}", "1.12", DeprecationLevel.Info);
+ GameEvents.DeprecationManager.Warn($"{nameof(GameEvents)}.{nameof(GameEvents.FirstUpdateTick)}", "1.12", DeprecationLevel.PendingRemoval);
GameEvents._FirstUpdateTick += value;
}
remove => GameEvents._FirstUpdateTick -= value;
}
+#endif
/// <summary>Raised when the game updates its state (≈60 times per second).</summary>
public static event EventHandler UpdateTick;
@@ -113,42 +117,52 @@ namespace StardewModdingAPI.Events
/*********
** Internal methods
*********/
+#if !SMAPI_2_0
/// <summary>Injects types required for backwards compatibility.</summary>
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Shim(DeprecationManager deprecationManager)
{
GameEvents.DeprecationManager = deprecationManager;
}
+#endif
- /// <summary>Raise an <see cref="Initialize"/> event.</summary>
- /// <param name="monitor">Encapsulates logging and monitoring.</param>
- internal static void InvokeInitialize(IMonitor monitor)
+ /// <summary>Raise an <see cref="InitializeInternal"/> event.</summary>
+ /// <param name="monitor">Encapsulates logging and monitoring.</param>
+ internal static void InvokeInitialize(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.InitializeInternal)}", GameEvents.InitializeInternal?.GetInvocationList());
+#if !SMAPI_2_0
monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.Initialize)}", GameEvents._Initialize?.GetInvocationList());
+#endif
}
+#if !SMAPI_2_0
/// <summary>Raise a <see cref="LoadContent"/> event.</summary>
/// <param name="monitor">Encapsulates logging and monitoring.</param>
internal static void InvokeLoadContent(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.LoadContent)}", GameEvents._LoadContent?.GetInvocationList());
}
+#endif
- /// <summary>Raise a <see cref="GameLoaded"/> event.</summary>
+ /// <summary>Raise a <see cref="GameLoadedInternal"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
internal static void InvokeGameLoaded(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoadedInternal)}", GameEvents.GameLoadedInternal?.GetInvocationList());
+#if !SMAPI_2_0
monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", GameEvents._GameLoaded?.GetInvocationList());
+#endif
}
+#if !SMAPI_2_0
/// <summary>Raise a <see cref="FirstUpdateTick"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
internal static void InvokeFirstUpdateTick(IMonitor monitor)
{
monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.FirstUpdateTick)}", GameEvents._FirstUpdateTick?.GetInvocationList());
}
+#endif
/// <summary>Raise an <see cref="UpdateTick"/> event.</summary>
/// <param name="monitor">Encapsulates logging and monitoring.</param>
diff --git a/src/StardewModdingAPI/Events/InputEvents.cs b/src/StardewModdingAPI/Events/InputEvents.cs
new file mode 100644
index 00000000..285487af
--- /dev/null
+++ b/src/StardewModdingAPI/Events/InputEvents.cs
@@ -0,0 +1,45 @@
+#if SMAPI_2_0
+using System;
+using StardewModdingAPI.Framework;
+using StardewModdingAPI.Utilities;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Events raised when the player uses a controller, keyboard, or mouse button.</summary>
+ public static class InputEvents
+ {
+ /*********
+ ** Events
+ *********/
+ /// <summary>Raised when the player presses a button on the keyboard, controller, or mouse.</summary>
+ public static event EventHandler<EventArgsInput> ButtonPressed;
+
+ /// <summary>Raised when the player releases a keyboard key on the keyboard, controller, or mouse.</summary>
+ public static event EventHandler<EventArgsInput> ButtonReleased;
+
+
+ /*********
+ ** Internal methods
+ *********/
+ /// <summary>Raise a <see cref="ButtonPressed"/> event.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ /// <param name="button">The button on the controller, keyboard, or mouse.</param>
+ /// <param name="cursor">The cursor position.</param>
+ /// <param name="isClick">Whether the input is considered a 'click' by the game for enabling action.</param>
+ internal static void InvokeButtonPressed(IMonitor monitor, SButton button, ICursorPosition cursor, bool isClick)
+ {
+ monitor.SafelyRaiseGenericEvent($"{nameof(InputEvents)}.{nameof(InputEvents.ButtonPressed)}", InputEvents.ButtonPressed?.GetInvocationList(), null, new EventArgsInput(button, cursor, isClick));
+ }
+
+ /// <summary>Raise a <see cref="ButtonReleased"/> event.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ /// <param name="button">The button on the controller, keyboard, or mouse.</param>
+ /// <param name="cursor">The cursor position.</param>
+ /// <param name="isClick">Whether the input is considered a 'click' by the game for enabling action.</param>
+ internal static void InvokeButtonReleased(IMonitor monitor, SButton button, ICursorPosition cursor, bool isClick)
+ {
+ monitor.SafelyRaiseGenericEvent($"{nameof(InputEvents)}.{nameof(InputEvents.ButtonReleased)}", InputEvents.ButtonReleased?.GetInvocationList(), null, new EventArgsInput(button, cursor, isClick));
+ }
+ }
+}
+#endif \ No newline at end of file
diff --git a/src/StardewModdingAPI/Events/PlayerEvents.cs b/src/StardewModdingAPI/Events/PlayerEvents.cs
index 37649fee..acbdc562 100644
--- a/src/StardewModdingAPI/Events/PlayerEvents.cs
+++ b/src/StardewModdingAPI/Events/PlayerEvents.cs
@@ -15,6 +15,7 @@ namespace StardewModdingAPI.Events
/*********
** Properties
*********/
+#if !SMAPI_2_0
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
@@ -25,18 +26,20 @@ namespace StardewModdingAPI.Events
/// <summary>The backing field for <see cref="FarmerChanged"/>.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
private static event EventHandler<EventArgsFarmerChanged> _FarmerChanged;
+#endif
/*********
** Events
*********/
+#if !SMAPI_2_0
/// <summary>Raised after the player loads a saved game.</summary>
[Obsolete("Use " + nameof(SaveEvents) + "." + nameof(SaveEvents.AfterLoad) + " instead")]
public static event EventHandler<EventArgsLoadedGameChanged> LoadedGame
{
add
{
- PlayerEvents.DeprecationManager.Warn($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.LoadedGame)}", "1.6", DeprecationLevel.Info);
+ PlayerEvents.DeprecationManager.Warn($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.LoadedGame)}", "1.6", DeprecationLevel.PendingRemoval);
PlayerEvents._LoadedGame += value;
}
remove => PlayerEvents._LoadedGame -= value;
@@ -48,11 +51,12 @@ namespace StardewModdingAPI.Events
{
add
{
- PlayerEvents.DeprecationManager.Warn($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.FarmerChanged)}", "1.6", DeprecationLevel.Info);
+ PlayerEvents.DeprecationManager.Warn($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.FarmerChanged)}", "1.6", DeprecationLevel.PendingRemoval);
PlayerEvents._FarmerChanged += value;
}
remove => PlayerEvents._FarmerChanged -= value;
}
+#endif
/// <summary>Raised after the player's inventory changes in any way (added or removed item, sorted, etc).</summary>
public static event EventHandler<EventArgsInventoryChanged> InventoryChanged;
@@ -64,6 +68,7 @@ namespace StardewModdingAPI.Events
/*********
** Internal methods
*********/
+#if !SMAPI_2_0
/// <summary>Injects types required for backwards compatibility.</summary>
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Shim(DeprecationManager deprecationManager)
@@ -87,6 +92,7 @@ namespace StardewModdingAPI.Events
{
monitor.SafelyRaiseGenericEvent($"{nameof(PlayerEvents)}.{nameof(PlayerEvents.FarmerChanged)}", PlayerEvents._FarmerChanged?.GetInvocationList(), null, new EventArgsFarmerChanged(priorFarmer, newFarmer));
}
+#endif
/// <summary>Raise an <see cref="InventoryChanged"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
diff --git a/src/StardewModdingAPI/Events/TimeEvents.cs b/src/StardewModdingAPI/Events/TimeEvents.cs
index 5dadf567..f0fdb4f2 100644
--- a/src/StardewModdingAPI/Events/TimeEvents.cs
+++ b/src/StardewModdingAPI/Events/TimeEvents.cs
@@ -11,6 +11,7 @@ namespace StardewModdingAPI.Events
/*********
** Properties
*********/
+#if !SMAPI_2_0
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
@@ -29,6 +30,8 @@ namespace StardewModdingAPI.Events
/// <summary>The backing field for <see cref="YearOfGameChanged"/>.</summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
private static event EventHandler<EventArgsIntChanged> _YearOfGameChanged;
+#endif
+
/*********
** Events
@@ -39,13 +42,14 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after the in-game clock changes.</summary>
public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged;
+#if !SMAPI_2_0
/// <summary>Raised after the day-of-month value changes, including when loading a save. This may happen before save; in most cases you should use <see cref="AfterDayStarted"/> instead.</summary>
[Obsolete("Use " + nameof(TimeEvents) + "." + nameof(TimeEvents.AfterDayStarted) + " or " + nameof(SaveEvents) + " instead")]
public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged
{
add
{
- TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.DayOfMonthChanged)}", "1.14", DeprecationLevel.Info);
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.DayOfMonthChanged)}", "1.14", DeprecationLevel.PendingRemoval);
TimeEvents._DayOfMonthChanged += value;
}
remove => TimeEvents._DayOfMonthChanged -= value;
@@ -57,7 +61,7 @@ namespace StardewModdingAPI.Events
{
add
{
- TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.YearOfGameChanged)}", "1.14", DeprecationLevel.Info);
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.YearOfGameChanged)}", "1.14", DeprecationLevel.PendingRemoval);
TimeEvents._YearOfGameChanged += value;
}
remove => TimeEvents._YearOfGameChanged -= value;
@@ -69,7 +73,7 @@ namespace StardewModdingAPI.Events
{
add
{
- TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.SeasonOfYearChanged)}", "1.14", DeprecationLevel.Info);
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.SeasonOfYearChanged)}", "1.14", DeprecationLevel.PendingRemoval);
TimeEvents._SeasonOfYearChanged += value;
}
remove => TimeEvents._SeasonOfYearChanged -= value;
@@ -81,22 +85,25 @@ namespace StardewModdingAPI.Events
{
add
{
- TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", "1.6", DeprecationLevel.Info);
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", "1.6", DeprecationLevel.PendingRemoval);
TimeEvents._OnNewDay += value;
}
remove => TimeEvents._OnNewDay -= value;
}
+#endif
/*********
** Internal methods
*********/
+#if !SMAPI_2_0
/// <summary>Injects types required for backwards compatibility.</summary>
/// <param name="deprecationManager">Manages deprecation warnings.</param>
internal static void Shim(DeprecationManager deprecationManager)
{
TimeEvents.DeprecationManager = deprecationManager;
}
+#endif
/// <summary>Raise an <see cref="AfterDayStarted"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
@@ -105,7 +112,7 @@ namespace StardewModdingAPI.Events
monitor.SafelyRaisePlainEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.AfterDayStarted)}", TimeEvents.AfterDayStarted?.GetInvocationList(), null, EventArgs.Empty);
}
- /// <summary>Raise a <see cref="InvokeDayOfMonthChanged"/> event.</summary>
+ /// <summary>Raise a <see cref="TimeOfDayChanged"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
/// <param name="priorTime">The previous time in military time format (e.g. 6:00pm is 1800).</param>
/// <param name="newTime">The current time in military time format (e.g. 6:10pm is 1810).</param>
@@ -114,6 +121,7 @@ namespace StardewModdingAPI.Events
monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.TimeOfDayChanged)}", TimeEvents.TimeOfDayChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorTime, newTime));
}
+#if !SMAPI_2_0
/// <summary>Raise a <see cref="DayOfMonthChanged"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
/// <param name="priorDay">The previous day value.</param>
@@ -150,5 +158,6 @@ namespace StardewModdingAPI.Events
{
monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", TimeEvents._OnNewDay?.GetInvocationList(), null, new EventArgsNewDay(priorDay, newDay, isTransitioning));
}
+#endif
}
}