summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-23 18:57:43 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-23 18:57:43 -0400
commitbcaf5b21c1e64ddca29b27d2b96652a3d925d8ff (patch)
tree4ebcb4c3fce0bc6b16b03ba73cdb405fa162d380 /src/StardewModdingAPI
parent7f8d738e86ae602edc91f0fa80643ee0cf47b089 (diff)
downloadSMAPI-bcaf5b21c1e64ddca29b27d2b96652a3d925d8ff.tar.gz
SMAPI-bcaf5b21c1e64ddca29b27d2b96652a3d925d8ff.tar.bz2
SMAPI-bcaf5b21c1e64ddca29b27d2b96652a3d925d8ff.zip
remove Initialize/LoadContent overrides & deprecate related events (#265)
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Events/GameEvents.cs48
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs24
-rw-r--r--src/StardewModdingAPI/Program.cs1
3 files changed, 45 insertions, 28 deletions
diff --git a/src/StardewModdingAPI/Events/GameEvents.cs b/src/StardewModdingAPI/Events/GameEvents.cs
index 715083b9..47c1275b 100644
--- a/src/StardewModdingAPI/Events/GameEvents.cs
+++ b/src/StardewModdingAPI/Events/GameEvents.cs
@@ -7,17 +7,26 @@ namespace StardewModdingAPI.Events
public static class GameEvents
{
/*********
+ ** Properties
+ *********/
+ /// <summary>Manages deprecation warnings.</summary>
+ private static DeprecationManager DeprecationManager;
+
+
+ /*********
** Events
*********/
/// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called during <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary>
+ [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the " + nameof(Initialize) + " event, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")]
public static event EventHandler Initialize;
- /// <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>
- public static event EventHandler GameLoaded;
-
/// <summary>Raised before XNA loads or reloads graphics resources. Called during <see cref="Microsoft.Xna.Framework.Game.LoadContent"/>.</summary>
+ [Obsolete("The " + nameof(Mod) + "." + nameof(Mod.Entry) + " method is now called after the " + nameof(LoadContent) + " event, so any contained logic can be done directly in " + nameof(Mod.Entry) + ".")]
public static event EventHandler LoadContent;
+ /// <summary>Raised during launch after configuring Stardew Valley, loading it into memory, and opening the game window. The window is still blank by this point.</summary>
+ public static event EventHandler GameLoaded;
+
/// <summary>Raised during the first game update tick.</summary>
public static event EventHandler FirstUpdateTick;
@@ -46,25 +55,46 @@ namespace StardewModdingAPI.Events
/*********
** Internal methods
*********/
- /// <summary>Raise a <see cref="GameLoaded"/> event.</summary>
- /// <param name="monitor">Encapsulates monitoring and logging.</param>
- internal static void InvokeGameLoaded(IMonitor monitor)
+ /// <summary>Injects types required for backwards compatibility.</summary>
+ /// <param name="deprecationManager">Manages deprecation warnings.</param>
+ internal static void Shim(DeprecationManager deprecationManager)
{
- monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", GameEvents.GameLoaded?.GetInvocationList());
+ GameEvents.DeprecationManager = deprecationManager;
}
/// <summary>Raise an <see cref="Initialize"/> event.</summary>
/// <param name="monitor">Encapsulates logging and monitoring.</param>
internal static void InvokeInitialize(IMonitor monitor)
{
- monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.Initialize)}", GameEvents.Initialize?.GetInvocationList());
+ if (GameEvents.Initialize == null)
+ return;
+
+ string name = $"{nameof(GameEvents)}.{nameof(GameEvents.Initialize)}";
+ Delegate[] handlers = GameEvents.Initialize.GetInvocationList();
+
+ GameEvents.DeprecationManager.WarnForEvent(handlers, name, "1.10", DeprecationLevel.Info);
+ monitor.SafelyRaisePlainEvent(name, handlers);
}
/// <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());
+ if (GameEvents.LoadContent == null)
+ return;
+
+ string name = $"{nameof(GameEvents)}.{nameof(GameEvents.LoadContent)}";
+ Delegate[] handlers = GameEvents.LoadContent.GetInvocationList();
+
+ GameEvents.DeprecationManager.WarnForEvent(handlers, name, "1.10", DeprecationLevel.Info);
+ monitor.SafelyRaisePlainEvent(name, handlers);
+ }
+
+ /// <summary>Raise a <see cref="GameLoaded"/> event.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ internal static void InvokeGameLoaded(IMonitor monitor)
+ {
+ monitor.SafelyRaisePlainEvent($"{nameof(GameEvents)}.{nameof(GameEvents.GameLoaded)}", GameEvents.GameLoaded?.GetInvocationList());
}
/// <summary>Raise an <see cref="UpdateTick"/> event.</summary>
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index 0b4d7494..0bbab904 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -48,7 +48,7 @@ namespace StardewModdingAPI.Framework
** Game state
****/
/// <summary>Arrays of pressed controller buttons indexed by <see cref="PlayerIndex"/>.</summary>
- private Buttons[][] PreviouslyPressedButtons;
+ private readonly Buttons[][] PreviouslyPressedButtons = { new Buttons[0], new Buttons[0], new Buttons[0], new Buttons[0] };
/// <summary>A record of the keyboard state (i.e. the up/down state for each button) as of the latest tick.</summary>
private KeyboardState KStateNow;
@@ -173,31 +173,17 @@ namespace StardewModdingAPI.Framework
/****
** Intercepted methods & events
****/
- /// <summary>The method called during game launch after configuring XNA or MonoGame. The game window hasn't been opened by this point.</summary>
- protected override void Initialize()
- {
- this.PreviouslyPressedButtons = new Buttons[4][];
- for (var i = 0; i < 4; ++i)
- this.PreviouslyPressedButtons[i] = new Buttons[0];
-
- base.Initialize();
- GameEvents.InvokeInitialize(this.Monitor);
- }
-
- /// <summary>The method called before XNA or MonoGame loads or reloads graphics resources.</summary>
- protected override void LoadContent()
- {
- base.LoadContent();
- GameEvents.InvokeLoadContent(this.Monitor);
- }
-
/// <summary>The method called when the game is updating its state. This happens roughly 60 times per second.</summary>
/// <param name="gameTime">A snapshot of the game timing state.</param>
protected override void Update(GameTime gameTime)
{
// raise game loaded
if (this.FirstUpdate)
+ {
+ GameEvents.InvokeInitialize(this.Monitor);
+ GameEvents.InvokeLoadContent(this.Monitor);
GameEvents.InvokeGameLoaded(this.Monitor);
+ }
// update SMAPI events
this.UpdateEventCalls();
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index 58850dc3..909a817c 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -120,6 +120,7 @@ namespace StardewModdingAPI
Log.Shim(this.DeprecationManager, this.GetSecondaryMonitor("legacy mod"), this.ModRegistry);
Mod.Shim(this.DeprecationManager);
ContentEvents.Shim(this.ModRegistry, this.Monitor);
+ GameEvents.Shim(this.DeprecationManager);
PlayerEvents.Shim(this.DeprecationManager);
TimeEvents.Shim(this.DeprecationManager);
#pragma warning restore 618