summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-02-24 19:56:08 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 16:59:29 -0400
commitbad2ac2a29b8775be97133e4c4cfb67a4a7406ee (patch)
tree9cc61caa21be489a9eb6b67368e2c40aca17af80 /src/SMAPI/Framework
parent4a297e29eb0c97be799ee3939e9747dc1c631427 (diff)
downloadSMAPI-bad2ac2a29b8775be97133e4c4cfb67a4a7406ee.tar.gz
SMAPI-bad2ac2a29b8775be97133e4c4cfb67a4a7406ee.tar.bz2
SMAPI-bad2ac2a29b8775be97133e4c4cfb67a4a7406ee.zip
remove deprecated APIs (#606)
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/Content/AssetDataForDictionary.cs33
-rw-r--r--src/SMAPI/Framework/DeprecationManager.cs29
-rw-r--r--src/SMAPI/Framework/Events/EventManager.cs260
-rw-r--r--src/SMAPI/Framework/Events/ManagedEvent.cs105
-rw-r--r--src/SMAPI/Framework/Events/ManagedEventBase.cs93
-rw-r--r--src/SMAPI/Framework/ModHelpers/ModHelper.cs71
-rw-r--r--src/SMAPI/Framework/ModLoading/ModResolver.cs4
-rw-r--r--src/SMAPI/Framework/SCore.cs40
-rw-r--r--src/SMAPI/Framework/SGame.cs207
-rw-r--r--src/SMAPI/Framework/SMultiplayer.cs18
10 files changed, 59 insertions, 801 deletions
diff --git a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs
index 11a2564c..a331f38a 100644
--- a/src/SMAPI/Framework/Content/AssetDataForDictionary.cs
+++ b/src/SMAPI/Framework/Content/AssetDataForDictionary.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Linq;
namespace StardewModdingAPI.Framework.Content
{
@@ -18,37 +17,5 @@ namespace StardewModdingAPI.Framework.Content
/// <param name="onDataReplaced">A callback to invoke when the data is replaced (if any).</param>
public AssetDataForDictionary(string locale, string assetName, IDictionary<TKey, TValue> data, Func<string, string> getNormalisedPath, Action<IDictionary<TKey, TValue>> onDataReplaced)
: base(locale, assetName, data, getNormalisedPath, onDataReplaced) { }
-
-#if !SMAPI_3_0_STRICT
- /// <summary>Add or replace an entry in the dictionary.</summary>
- /// <param name="key">The entry key.</param>
- /// <param name="value">The entry value.</param>
- [Obsolete("Access " + nameof(AssetData<IDictionary<TKey, TValue>>.Data) + "field directly.")]
- public void Set(TKey key, TValue value)
- {
- SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.PendingRemoval);
- this.Data[key] = value;
- }
-
- /// <summary>Add or replace an entry in the dictionary.</summary>
- /// <param name="key">The entry key.</param>
- /// <param name="value">A callback which accepts the current value and returns the new value.</param>
- [Obsolete("Access " + nameof(AssetData<IDictionary<TKey, TValue>>.Data) + "field directly.")]
- public void Set(TKey key, Func<TValue, TValue> value)
- {
- SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.PendingRemoval);
- this.Data[key] = value(this.Data[key]);
- }
-
- /// <summary>Dynamically replace values in the dictionary.</summary>
- /// <param name="replacer">A lambda which takes the current key and value for an entry, and returns the new value.</param>
- [Obsolete("Access " + nameof(AssetData<IDictionary<TKey, TValue>>.Data) + "field directly.")]
- public void Set(Func<TKey, TValue, TValue> replacer)
- {
- SCore.DeprecationManager.Warn($"AssetDataForDictionary.{nameof(Set)}", "2.10", DeprecationLevel.PendingRemoval);
- foreach (var pair in this.Data.ToArray())
- this.Data[pair.Key] = replacer(pair.Key, pair.Value);
- }
-#endif
}
}
diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs
index 984bb487..636b1979 100644
--- a/src/SMAPI/Framework/DeprecationManager.cs
+++ b/src/SMAPI/Framework/DeprecationManager.cs
@@ -14,11 +14,7 @@ namespace StardewModdingAPI.Framework
private readonly HashSet<string> LoggedDeprecations = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
/// <summary>Encapsulates monitoring and logging for a given module.</summary>
-#if !SMAPI_3_0_STRICT
- private readonly Monitor Monitor;
-#else
private readonly IMonitor Monitor;
-#endif
/// <summary>Tracks the installed mods.</summary>
private readonly ModRegistry ModRegistry;
@@ -26,11 +22,6 @@ namespace StardewModdingAPI.Framework
/// <summary>The queued deprecation warnings to display.</summary>
private readonly IList<DeprecationWarning> QueuedWarnings = new List<DeprecationWarning>();
-#if !SMAPI_3_0_STRICT
- /// <summary>Whether the one-time deprecation message has been shown.</summary>
- private bool DeprecationHeaderShown = false;
-#endif
-
/*********
** Public methods
@@ -38,11 +29,7 @@ namespace StardewModdingAPI.Framework
/// <summary>Construct an instance.</summary>
/// <param name="monitor">Encapsulates monitoring and logging for a given module.</param>
/// <param name="modRegistry">Tracks the installed mods.</param>
-#if !SMAPI_3_0_STRICT
- public DeprecationManager(Monitor monitor, ModRegistry modRegistry)
-#else
public DeprecationManager(IMonitor monitor, ModRegistry modRegistry)
-#endif
{
this.Monitor = monitor;
this.ModRegistry = modRegistry;
@@ -81,26 +68,10 @@ namespace StardewModdingAPI.Framework
/// <summary>Print any queued messages.</summary>
public void PrintQueued()
{
-#if !SMAPI_3_0_STRICT
- if (!this.DeprecationHeaderShown && this.QueuedWarnings.Any())
- {
- this.Monitor.Newline();
- this.Monitor.Log("Some of your mods will break in the upcoming SMAPI 3.0. Please update your mods now, or notify the author if no update is available. See https://mods.smapi.io for links to the latest versions.", LogLevel.Warn);
- this.Monitor.Newline();
- this.DeprecationHeaderShown = true;
- }
-#endif
-
foreach (DeprecationWarning warning in this.QueuedWarnings.OrderBy(p => p.ModName).ThenBy(p => p.NounPhrase))
{
// build message
-#if SMAPI_3_0_STRICT
string message = $"{warning.ModName} uses deprecated code ({warning.NounPhrase} is deprecated since SMAPI {warning.Version}).";
-#else
- string message = warning.NounPhrase == "legacy events"
- ? $"{warning.ModName ?? "An unknown mod"} will break in the upcoming SMAPI 3.0 (legacy events are deprecated since SMAPI {warning.Version})."
- : $"{warning.ModName ?? "An unknown mod"} will break in the upcoming SMAPI 3.0 ({warning.NounPhrase} is deprecated since SMAPI {warning.Version}).";
-#endif
// get log level
LogLevel level;
diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs
index 13244601..23879f1d 100644
--- a/src/SMAPI/Framework/Events/EventManager.cs
+++ b/src/SMAPI/Framework/Events/EventManager.cs
@@ -1,7 +1,4 @@
using System.Diagnostics.CodeAnalysis;
-#if !SMAPI_3_0_STRICT
-using Microsoft.Xna.Framework.Input;
-#endif
using StardewModdingAPI.Events;
namespace StardewModdingAPI.Framework.Events
@@ -167,196 +164,6 @@ namespace StardewModdingAPI.Framework.Events
public readonly ManagedEvent<UnvalidatedUpdateTickedEventArgs> UnvalidatedUpdateTicked;
-#if !SMAPI_3_0_STRICT
- /*********
- ** Events (old)
- *********/
- /****
- ** ContentEvents
- ****/
- /// <summary>Raised after the content language changes.</summary>
- public readonly ManagedEvent<EventArgsValueChanged<string>> Legacy_LocaleChanged;
-
- /****
- ** ControlEvents
- ****/
- /// <summary>Raised when the <see cref="KeyboardState"/> changes. That happens when the player presses or releases a key.</summary>
- public readonly ManagedEvent<EventArgsKeyboardStateChanged> Legacy_KeyboardChanged;
-
- /// <summary>Raised after the player presses a keyboard key.</summary>
- public readonly ManagedEvent<EventArgsKeyPressed> Legacy_KeyPressed;
-
- /// <summary>Raised after the player releases a keyboard key.</summary>
- public readonly ManagedEvent<EventArgsKeyPressed> Legacy_KeyReleased;
-
- /// <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 readonly ManagedEvent<EventArgsMouseStateChanged> Legacy_MouseChanged;
-
- /// <summary>The player pressed a controller button. This event isn't raised for trigger buttons.</summary>
- public readonly ManagedEvent<EventArgsControllerButtonPressed> Legacy_ControllerButtonPressed;
-
- /// <summary>The player released a controller button. This event isn't raised for trigger buttons.</summary>
- public readonly ManagedEvent<EventArgsControllerButtonReleased> Legacy_ControllerButtonReleased;
-
- /// <summary>The player pressed a controller trigger button.</summary>
- public readonly ManagedEvent<EventArgsControllerTriggerPressed> Legacy_ControllerTriggerPressed;
-
- /// <summary>The player released a controller trigger button.</summary>
- public readonly ManagedEvent<EventArgsControllerTriggerReleased> Legacy_ControllerTriggerReleased;
-
- /****
- ** GameEvents
- ****/
- /// <summary>Raised once after the game initialises and all <see cref="IMod.Entry"/> methods have been called.</summary>
- public readonly ManagedEvent Legacy_FirstUpdateTick;
-
- /// <summary>Raised when the game updates its state (≈60 times per second).</summary>
- public readonly ManagedEvent Legacy_UpdateTick;
-
- /// <summary>Raised every other tick (≈30 times per second).</summary>
- public readonly ManagedEvent Legacy_SecondUpdateTick;
-
- /// <summary>Raised every fourth tick (≈15 times per second).</summary>
- public readonly ManagedEvent Legacy_FourthUpdateTick;
-
- /// <summary>Raised every eighth tick (≈8 times per second).</summary>
- public readonly ManagedEvent Legacy_EighthUpdateTick;
-
- /// <summary>Raised every 15th tick (≈4 times per second).</summary>
- public readonly ManagedEvent Legacy_QuarterSecondTick;
-
- /// <summary>Raised every 30th tick (≈twice per second).</summary>
- public readonly ManagedEvent Legacy_HalfSecondTick;
-
- /// <summary>Raised every 60th tick (≈once per second).</summary>
- public readonly ManagedEvent Legacy_OneSecondTick;
-
- /****
- ** GraphicsEvents
- ****/
- /// <summary>Raised after the game window is resized.</summary>
- public readonly ManagedEvent Legacy_Resize;
-
- /// <summary>Raised before drawing the world to the screen.</summary>
- public readonly ManagedEvent Legacy_OnPreRenderEvent;
-
- /// <summary>Raised after drawing the world to the screen.</summary>
- public readonly ManagedEvent Legacy_OnPostRenderEvent;
-
- /// <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 readonly ManagedEvent Legacy_OnPreRenderHudEvent;
-
- /// <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 readonly ManagedEvent Legacy_OnPostRenderHudEvent;
-
- /// <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 readonly ManagedEvent Legacy_OnPreRenderGuiEvent;
-
- /// <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 readonly ManagedEvent Legacy_OnPostRenderGuiEvent;
-
- /****
- ** InputEvents
- ****/
- /// <summary>Raised after the player presses a button on the keyboard, controller, or mouse.</summary>
- public readonly ManagedEvent<EventArgsInput> Legacy_ButtonPressed;
-
- /// <summary>Raised after the player releases a keyboard key on the keyboard, controller, or mouse.</summary>
- public readonly ManagedEvent<EventArgsInput> Legacy_ButtonReleased;
-
- /****
- ** LocationEvents
- ****/
- /// <summary>Raised after a game location is added or removed.</summary>
- public readonly ManagedEvent<EventArgsLocationsChanged> Legacy_LocationsChanged;
-
- /// <summary>Raised after buildings are added or removed in a location.</summary>
- public readonly ManagedEvent<EventArgsLocationBuildingsChanged> Legacy_BuildingsChanged;
-
- /// <summary>Raised after objects are added or removed in a location.</summary>
- public readonly ManagedEvent<EventArgsLocationObjectsChanged> Legacy_ObjectsChanged;
-
- /****
- ** MenuEvents
- ****/
- /// <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 readonly ManagedEvent<EventArgsClickableMenuChanged> Legacy_MenuChanged;
-
- /// <summary>Raised after a game menu is closed.</summary>
- public readonly ManagedEvent<EventArgsClickableMenuClosed> Legacy_MenuClosed;
-
- /****
- ** MultiplayerEvents
- ****/
- /// <summary>Raised before the game syncs changes from other players.</summary>
- public readonly ManagedEvent Legacy_BeforeMainSync;
-
- /// <summary>Raised after the game syncs changes from other players.</summary>
- public readonly ManagedEvent Legacy_AfterMainSync;
-
- /// <summary>Raised before the game broadcasts changes to other players.</summary>
- public readonly ManagedEvent Legacy_BeforeMainBroadcast;
-
- /// <summary>Raised after the game broadcasts changes to other players.</summary>
- public readonly ManagedEvent Legacy_AfterMainBroadcast;
-
- /****
- ** MineEvents
- ****/
- /// <summary>Raised after the player warps to a new level of the mine.</summary>
- public readonly ManagedEvent<EventArgsMineLevelChanged> Legacy_MineLevelChanged;
-
- /****
- ** PlayerEvents
- ****/
- /// <summary>Raised after the player's inventory changes in any way (added or removed item, sorted, etc).</summary>
- public readonly ManagedEvent<EventArgsInventoryChanged> Legacy_InventoryChanged;
-
- /// <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 readonly ManagedEvent<EventArgsLevelUp> Legacy_LeveledUp;
-
- /// <summary>Raised after the player warps to a new location.</summary>
- public readonly ManagedEvent<EventArgsPlayerWarped> Legacy_PlayerWarped;
-
-
- /****
- ** SaveEvents
- ****/
- /// <summary>Raised before the game creates the save file.</summary>
- public readonly ManagedEvent Legacy_BeforeCreateSave;
-
- /// <summary>Raised after the game finishes creating the save file.</summary>
- public readonly ManagedEvent Legacy_AfterCreateSave;
-
- /// <summary>Raised before the game begins writes data to the save file.</summary>
- public readonly ManagedEvent Legacy_BeforeSave;
-
- /// <summary>Raised after the game finishes writing data to the save file.</summary>
- public readonly ManagedEvent Legacy_AfterSave;
-
- /// <summary>Raised after the player loads a save slot.</summary>
- public readonly ManagedEvent Legacy_AfterLoad;
-
- /// <summary>Raised after the game returns to the title screen.</summary>
- public readonly ManagedEvent Legacy_AfterReturnToTitle;
-
- /****
- ** SpecialisedEvents
- ****/
- /// <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 readonly ManagedEvent Legacy_UnvalidatedUpdateTick;
-
- /****
- ** TimeEvents
- ****/
- /// <summary>Raised after the game begins a new day, including when loading a save.</summary>
- public readonly ManagedEvent Legacy_AfterDayStarted;
-
- /// <summary>Raised after the in-game clock changes.</summary>
- public readonly ManagedEvent<EventArgsIntChanged> Legacy_TimeOfDayChanged;
-#endif
-
-
/*********
** Public methods
*********/
@@ -367,9 +174,6 @@ namespace StardewModdingAPI.Framework.Events
{
// create shortcut initialisers
ManagedEvent<TEventArgs> ManageEventOf<TEventArgs>(string typeName, string eventName) => new ManagedEvent<TEventArgs>($"{typeName}.{eventName}", monitor, modRegistry);
-#if !SMAPI_3_0_STRICT
- ManagedEvent ManageEvent(string typeName, string eventName) => new ManagedEvent($"{typeName}.{eventName}", monitor, modRegistry);
-#endif
// init events (new)
this.MenuChanged = ManageEventOf<MenuChangedEventArgs>(nameof(IModEvents.Display), nameof(IDisplayEvents.MenuChanged));
@@ -422,70 +226,6 @@ namespace StardewModdingAPI.Framework.Events
this.LoadStageChanged = ManageEventOf<LoadStageChangedEventArgs>(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.LoadStageChanged));
this.UnvalidatedUpdateTicking = ManageEventOf<UnvalidatedUpdateTickingEventArgs>(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicking));
this.UnvalidatedUpdateTicked = ManageEventOf<UnvalidatedUpdateTickedEventArgs>(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicked));
-
-#if !SMAPI_3_0_STRICT
- // init events (old)
- this.Legacy_LocaleChanged = ManageEventOf<EventArgsValueChanged<string>>(nameof(ContentEvents), nameof(ContentEvents.AfterLocaleChanged));
-
- this.Legacy_ControllerButtonPressed = ManageEventOf<EventArgsControllerButtonPressed>(nameof(ControlEvents), nameof(ControlEvents.ControllerButtonPressed));
- this.Legacy_ControllerButtonReleased = ManageEventOf<EventArgsControllerButtonReleased>(nameof(ControlEvents), nameof(ControlEvents.ControllerButtonReleased));
- this.Legacy_ControllerTriggerPressed = ManageEventOf<EventArgsControllerTriggerPressed>(nameof(ControlEvents), nameof(ControlEvents.ControllerTriggerPressed));
- this.Legacy_ControllerTriggerReleased = ManageEventOf<EventArgsControllerTriggerReleased>(nameof(ControlEvents), nameof(ControlEvents.ControllerTriggerReleased));
- this.Legacy_KeyboardChanged = ManageEventOf<EventArgsKeyboardStateChanged>(nameof(ControlEvents), nameof(ControlEvents.KeyboardChanged));
- this.Legacy_KeyPressed = ManageEventOf<EventArgsKeyPressed>(nameof(ControlEvents), nameof(ControlEvents.KeyPressed));
- this.Legacy_KeyReleased = ManageEventOf<EventArgsKeyPressed>(nameof(ControlEvents), nameof(ControlEvents.KeyReleased));
- this.Legacy_MouseChanged = ManageEventOf<EventArgsMouseStateChanged>(nameof(ControlEvents), nameof(ControlEvents.MouseChanged));
-
- this.Legacy_FirstUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.FirstUpdateTick));
- this.Legacy_UpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.UpdateTick));
- this.Legacy_SecondUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.SecondUpdateTick));
- this.Legacy_FourthUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.FourthUpdateTick));
- this.Legacy_EighthUpdateTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.EighthUpdateTick));
- this.Legacy_QuarterSecondTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.QuarterSecondTick));
- this.Legacy_HalfSecondTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.HalfSecondTick));
- this.Legacy_OneSecondTick = ManageEvent(nameof(GameEvents), nameof(GameEvents.OneSecondTick));
-
- this.Legacy_Resize = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.Resize));
- this.Legacy_OnPreRenderEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPreRenderEvent));
- this.Legacy_OnPostRenderEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPostRenderEvent));
- this.Legacy_OnPreRenderHudEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPreRenderHudEvent));
- this.Legacy_OnPostRenderHudEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPostRenderHudEvent));
- this.Legacy_OnPreRenderGuiEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPreRenderGuiEvent));
- this.Legacy_OnPostRenderGuiEvent = ManageEvent(nameof(GraphicsEvents), nameof(GraphicsEvents.OnPostRenderGuiEvent));
-
- this.Legacy_ButtonPressed = ManageEventOf<EventArgsInput>(nameof(InputEvents), nameof(InputEvents.ButtonPressed));
- this.Legacy_ButtonReleased = ManageEventOf<EventArgsInput>(nameof(InputEvents), nameof(InputEvents.ButtonReleased));
-
- this.Legacy_LocationsChanged = ManageEventOf<EventArgsLocationsChanged>(nameof(LocationEvents), nameof(LocationEvents.LocationsChanged));
- this.Legacy_BuildingsChanged = ManageEventOf<EventArgsLocationBuildingsChanged>(nameof(LocationEvents), nameof(LocationEvents.BuildingsChanged));
- this.Legacy_ObjectsChanged = ManageEventOf<EventArgsLocationObjectsChanged>(nameof(LocationEvents), nameof(LocationEvents.ObjectsChanged));
-
- this.Legacy_MenuChanged = ManageEventOf<EventArgsClickableMenuChanged>(nameof(MenuEvents), nameof(MenuEvents.MenuChanged));
- this.Legacy_MenuClosed = ManageEventOf<EventArgsClickableMenuClosed>(nameof(MenuEvents), nameof(MenuEvents.MenuClosed));
-
- this.Legacy_BeforeMainBroadcast = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.BeforeMainBroadcast));
- this.Legacy_AfterMainBroadcast = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.AfterMainBroadcast));
- this.Legacy_BeforeMainSync = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.BeforeMainSync));
- this.Legacy_AfterMainSync = ManageEvent(nameof(MultiplayerEvents), nameof(MultiplayerEvents.AfterMainSync));
-
- this.Legacy_MineLevelChanged = ManageEventOf<EventArgsMineLevelChanged>(nameof(MineEvents), nameof(MineEvents.MineLevelChanged));
-
- this.Legacy_InventoryChanged = ManageEventOf<EventArgsInventoryChanged>(nameof(PlayerEvents), nameof(PlayerEvents.InventoryChanged));
- this.Legacy_LeveledUp = ManageEventOf<EventArgsLevelUp>(nameof(PlayerEvents), nameof(PlayerEvents.LeveledUp));
- this.Legacy_PlayerWarped = ManageEventOf<EventArgsPlayerWarped>(nameof(PlayerEvents), nameof(PlayerEvents.Warped));
-
- this.Legacy_BeforeCreateSave = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.BeforeCreate));
- this.Legacy_AfterCreateSave = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterCreate));
- this.Legacy_BeforeSave = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.BeforeSave));
- this.Legacy_AfterSave = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterSave));
- this.Legacy_AfterLoad = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterLoad));
- this.Legacy_AfterReturnToTitle = ManageEvent(nameof(SaveEvents), nameof(SaveEvents.AfterReturnToTitle));
-
- this.Legacy_UnvalidatedUpdateTick = ManageEvent(nameof(SpecialisedEvents), nameof(SpecialisedEvents.UnvalidatedUpdateTick));
-
- this.Legacy_AfterDayStarted = ManageEvent(nameof(TimeEvents), nameof(TimeEvents.AfterDayStarted));
- this.Legacy_TimeOfDayChanged = ManageEventOf<EventArgsIntChanged>(nameof(TimeEvents), nameof(TimeEvents.TimeOfDayChanged));
-#endif
}
}
}
diff --git a/src/SMAPI/Framework/Events/ManagedEvent.cs b/src/SMAPI/Framework/Events/ManagedEvent.cs
index f9e7f6ec..2afe7a03 100644
--- a/src/SMAPI/Framework/Events/ManagedEvent.cs
+++ b/src/SMAPI/Framework/Events/ManagedEvent.cs
@@ -1,11 +1,12 @@
using System;
+using System.Collections.Generic;
using System.Linq;
namespace StardewModdingAPI.Framework.Events
{
/// <summary>An event wrapper which intercepts and logs errors in handler code.</summary>
/// <typeparam name="TEventArgs">The event arguments type.</typeparam>
- internal class ManagedEvent<TEventArgs> : ManagedEventBase<EventHandler<TEventArgs>>
+ internal class ManagedEvent<TEventArgs>
{
/*********
** Fields
@@ -13,6 +14,21 @@ namespace StardewModdingAPI.Framework.Events
/// <summary>The underlying event.</summary>
private event EventHandler<TEventArgs> Event;
+ /// <summary>A human-readable name for the event.</summary>
+ private readonly string EventName;
+
+ /// <summary>Writes messages to the log.</summary>
+ private readonly IMonitor Monitor;
+
+ /// <summary>The mod registry with which to identify mods.</summary>
+ protected readonly ModRegistry ModRegistry;
+
+ /// <summary>The display names for the mods which added each delegate.</summary>
+ private readonly IDictionary<EventHandler<TEventArgs>, IModMetadata> SourceMods = new Dictionary<EventHandler<TEventArgs>, IModMetadata>();
+
+ /// <summary>The cached invocation list.</summary>
+ private EventHandler<TEventArgs>[] CachedInvocationList;
+
/*********
** Public methods
@@ -22,7 +38,17 @@ namespace StardewModdingAPI.Framework.Events
/// <param name="monitor">Writes messages to the log.</param>
/// <param name="modRegistry">The mod registry with which to identify mods.</param>
public ManagedEvent(string eventName, IMonitor monitor, ModRegistry modRegistry)
- : base(eventName, monitor, modRegistry) { }
+ {
+ this.EventName = eventName;
+ this.Monitor = monitor;
+ this.ModRegistry = modRegistry;
+ }
+
+ /// <summary>Get whether anything is listening to the event.</summary>
+ public bool HasListeners()
+ {
+ return this.CachedInvocationList?.Length > 0;
+ }
/// <summary>Add an event handler.</summary>
/// <param name="handler">The event handler.</param>
@@ -91,71 +117,50 @@ namespace StardewModdingAPI.Framework.Events
}
}
}
- }
-
-#if !SMAPI_3_0_STRICT
- /// <summary>An event wrapper which intercepts and logs errors in handler code.</summary>
- internal class ManagedEvent : ManagedEventBase<EventHandler>
- {
- /*********
- ** Fields
- *********/
- /// <summary>The underlying event.</summary>
- private event EventHandler Event;
/*********
- ** Public methods
+ ** Private methods
*********/
- /// <summary>Construct an instance.</summary>
- /// <param name="eventName">A human-readable name for the event.</param>
- /// <param name="monitor">Writes messages to the log.</param>
- /// <param name="modRegistry">The mod registry with which to identify mods.</param>
- public ManagedEvent(string eventName, IMonitor monitor, ModRegistry modRegistry)
- : base(eventName, monitor, modRegistry) { }
-
- /// <summary>Add an event handler.</summary>
+ /// <summary>Track an event handler.</summary>
+ /// <param name="mod">The mod which added the handler.</param>
/// <param name="handler">The event handler.</param>
- public void Add(EventHandler handler)
+ /// <param name="invocationList">The updated event invocation list.</param>
+ protected void AddTracking(IModMetadata mod, EventHandler<TEventArgs> handler, IEnumerable<EventHandler<TEventArgs>> invocationList)
{
- this.Add(handler, this.ModRegistry.GetFromStack());
+ this.SourceMods[handler] = mod;
+ this.CachedInvocationList = invocationList?.ToArray() ?? new EventHandler<TEventArgs>[0];
}
- /// <summary>Add an event handler.</summary>
+ /// <summary>Remove tracking for an event handler.</summary>
/// <param name="handler">The event handler.</param>
- /// <param name="mod">The mod which added the event handler.</param>
- public void Add(EventHandler handler, IModMetadata mod)
+ /// <param name="invocationList">The updated event invocation list.</param>
+ protected void RemoveTracking(EventHandler<TEventArgs> handler, IEnumerable<EventHandler<TEventArgs>> invocationList)
{
- this.Event += handler;
- this.AddTracking(mod, handler, this.Event?.GetInvocationList().Cast<EventHandler>());
+ this.CachedInvocationList = invocationList?.ToArray() ?? new EventHandler<TEventArgs>[0];
+ if (!this.CachedInvocationList.Contains(handler)) // don't remove if there's still a reference to the removed handler (e.g. it was added twice and removed once)
+ this.SourceMods.Remove(handler);
}
- /// <summary>Remove an event handler.</summary>
+ /// <summary>Get the mod which registered the given event handler, if available.</summary>
/// <param name="handler">The event handler.</param>
- public void Remove(EventHandler handler)
+ protected IModMetadata GetSourceMod(EventHandler<TEventArgs> handler)
{
- this.Event -= handler;
- this.RemoveTracking(handler, this.Event?.GetInvocationList().Cast<EventHandler>());
+ return this.SourceMods.TryGetValue(handler, out IModMetadata mod)
+ ? mod
+ : null;
}
- /// <summary>Raise the event and notify all handlers.</summary>
- public void Raise()
+ /// <summary>Log an exception from an event handler.</summary>
+ /// <param name="handler">The event handler instance.</param>
+ /// <param name="ex">The exception that was raised.</param>
+ protected void LogError(EventHandler<TEventArgs> handler, Exception ex)
{
- if (this.Event == null)
- return;
-
- foreach (EventHandler handler in this.CachedInvocationList)
- {
- try
- {
- handler.Invoke(null, EventArgs.Empty);
- }
- catch (Exception ex)
- {
- this.LogError(handler, ex);
- }
- }
+ IModMetadata mod = this.GetSourceMod(handler);
+ if (mod != null)
+ mod.LogAsMod($"This mod failed in the {this.EventName} event. Technical details: \n{ex.GetLogSummary()}", LogLevel.Error);
+ else
+ this.Monitor.Log($"A mod failed in the {this.EventName} event. Technical details: \n{ex.GetLogSummary()}", LogLevel.Error);
}
}
-#endif
}
diff --git a/src/SMAPI/Framework/Events/ManagedEventBase.cs b/src/SMAPI/Framework/Events/ManagedEventBase.cs
deleted file mode 100644
index c8c3516b..00000000
--- a/src/SMAPI/Framework/Events/ManagedEventBase.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace StardewModdingAPI.Framework.Events
-{
- /// <summary>The base implementation for an event wrapper which intercepts and logs errors in handler code.</summary>
- internal abstract class ManagedEventBase<TEventHandler>
- {
- /*********
- ** Fields
- *********/
- /// <summary>A human-readable name for the event.</summary>
- private readonly string EventName;
-
- /// <summary>Writes messages to the log.</summary>
- private readonly IMonitor Monitor;
-
- /// <summary>The mod registry with which to identify mods.</summary>
- protected readonly ModRegistry ModRegistry;
-
- /// <summary>The display names for the mods which added each delegate.</summary>
- private readonly IDictionary<TEventHandler, IModMetadata> SourceMods = new Dictionary<TEventHandler, IModMetadata>();
-
- /// <summary>The cached invocation list.</summary>
- protected TEventHandler[] CachedInvocationList { get; private set; }
-
-
- /*********
- ** Public methods
- *********/
- /// <summary>Get whether anything is listening to the event.</summary>
- public bool HasListeners()
- {
- return this.CachedInvocationList?.Length > 0;
- }
-
- /*********
- ** Protected methods
- *********/
- /// <summary>Construct an instance.</summary>
- /// <param name="eventName">A human-readable name for the event.</param>
- /// <param name="monitor">Writes messages to the log.</param>
- /// <param name="modRegistry">The mod registry with which to identify mods.</param>
- protected ManagedEventBase(string eventName, IMonitor monitor, ModRegistry modRegistry)
- {
- this.EventName = eventName;
- this.Monitor = monitor;
- this.ModRegistry = modRegistry;
- }
-
- /// <summary>Track an event handler.</summary>
- /// <param name="mod">The mod which added the handler.</param>
- /// <param name="handler">The event handler.</param>
- /// <param name="invocationList">The updated event invocation list.</param>
- protected void AddTracking(IModMetadata mod, TEventHandler handler, IEnumerable<TEventHandler> invocationList)
- {
- this.SourceMods[handler] = mod;
- this.CachedInvocationList = invocationList?.ToArray() ?? new TEventHandler[0];
- }
-
- /// <summary>Remove tracking for an event handler.</summary>
- /// <param name="handler">The event handler.</param>
- /// <param name="invocationList">The updated event invocation list.</param>
- protected void RemoveTracking(TEventHandler handler, IEnumerable<TEventHandler> invocationList)
- {
- this.CachedInvocationList = invocationList?.ToArray() ?? new TEventHandler[0];
- if (!this.CachedInvocationList.Contains(handler)) // don't remove if there's still a reference to the removed handler (e.g. it was added twice and removed once)
- this.SourceMods.Remove(handler);
- }
-
- /// <summary>Get the mod which registered the given event handler, if available.</summary>
- /// <param name="handler">The event handler.</param>
- protected IModMetadata GetSourceMod(TEventHandler handler)
- {
- return this.SourceMods.TryGetValue(handler, out IModMetadata mod)
- ? mod
- : null;
- }
-
- /// <summary>Log an exception from an event handler.</summary>
- /// <param name="handler">The event handler instance.</param>
- /// <param name="ex">The exception that was raised.</param>
- protected void LogError(TEventHandler handler, Exception ex)
- {
- IModMetadata mod = this.GetSourceMod(handler);
- if (mod != null)
- mod.LogAsMod($"This mod failed in the {this.EventName} event. Technical details: \n{ex.GetLogSummary()}", LogLevel.Error);
- else
- this.Monitor.Log($"A mod failed in the {this.EventName} event. Technical details: \n{ex.GetLogSummary()}", LogLevel.Error);
- }
- }
-}
diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
index 6c9838c9..86e8eb28 100644
--- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
@@ -1,11 +1,8 @@
using System;
-using System.Collections.Generic;
using System.IO;
using StardewModdingAPI.Events;
using StardewModdingAPI.Framework.Input;
using StardewModdingAPI.Toolkit.Serialisation;
-using StardewModdingAPI.Toolkit.Serialisation.Models;
-using StardewModdingAPI.Toolkit.Utilities;
namespace StardewModdingAPI.Framework.ModHelpers
{
@@ -18,11 +15,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>The full path to the mod's folder.</summary>
public string DirectoryPath { get; }
-#if !SMAPI_3_0_STRICT
- /// <summary>Encapsulates SMAPI's JSON file parsing.</summary>
- private readonly JsonHelper JsonHelper;
-#endif
-
/// <summary>Manages access to events raised by SMAPI, which let your mod react when something happens in the game.</summary>
public IModEvents Events { get; }
@@ -60,7 +52,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>Construct an instance.</summary>
/// <param name="modID">The mod's unique ID.</param>
/// <param name="modDirectory">The full path to the mod's folder.</param>
- /// <param name="jsonHelper">Encapsulate SMAPI's JSON parsing.</param>
/// <param name="inputState">Manages the game's input state.</param>
/// <param name="events">Manages access to events raised by SMAPI.</param>
/// <param name="contentHelper">An API for loading content assets.</param>
@@ -73,7 +64,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <param name="translationHelper">An API for reading translations stored in the mod's <c>i18n</c> folder.</param>
/// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
/// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
- public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper)
+ public ModHelper(string modID, string modDirectory, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper)
: base(modID)
{
// validate directory
@@ -94,9 +85,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
this.Multiplayer = multiplayer ?? throw new ArgumentNullException(nameof(multiplayer));
this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper));
this.Events = events;
-#if !SMAPI_3_0_STRICT
- this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
-#endif
}
/****
@@ -121,63 +109,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
this.Data.WriteJsonFile("config.json", config);
}
-#if !SMAPI_3_0_STRICT
- /****
- ** Generic JSON files
- ****/
- /// <summary>Read a JSON file.</summary>
- /// <typeparam name="TModel">The model type.</typeparam>
- /// <param name="path">The file path relative to the mod directory.</param>
- /// <returns>Returns the deserialised model, or <c>null</c> if the file doesn't exist or is empty.</returns>
- [Obsolete("Use " + nameof(ModHelper.Data) + "." + nameof(IDataHelper.ReadJsonFile) + " instead")]
- public TModel ReadJsonFile<TModel>(string path)
- where TModel : class
- {
- path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path));
- return this.JsonHelper.ReadJsonFileIfExists(path, out TModel data)
- ? data
- : null;
- }
-
- /// <summary>Save to a JSON file.</summary>
- /// <typeparam name="TModel">The model type.</typeparam>
- /// <param name="path">The file path relative to the mod directory.</param>
- /// <param name="model">The model to save.</param>
- [Obsolete("Use " + nameof(ModHelper.Data) + "." + nameof(IDataHelper.WriteJsonFile) + " instead")]
- public void WriteJsonFile<TModel>(string path, TModel model)
- where TModel : class
- {
- path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path));
- this.JsonHelper.WriteJsonFile(path, model);
- }
-#endif
-
- /****
- ** Content packs
- ****/
-#if !SMAPI_3_0_STRICT
- /// <summary>Manually create a transitional content pack to support pre-SMAPI content packs. This provides a way to access legacy content packs using the SMAPI content pack APIs, but the content pack will not be visible in the log or validated by SMAPI.</summary>
- /// <param name="directoryPath">The absolute directory path containing the content pack files.</param>
- /// <param name="id">The content pack's unique ID.</param>
- /// <param name="name">The content pack name.</param>
- /// <param name="description">The content pack description.</param>
- /// <param name="author">The content pack author's name.</param>
- /// <param name="version">The content pack version.</param>
- [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateTemporary) + " instead")]
- public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version)
- {
- SCore.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.PendingRemoval);
- return this.ContentPacks.CreateTemporary(directoryPath, id, name, description, author, version);
- }
-
- /// <summary>Get all content packs loaded for this mod.</summary>
- [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.GetOwned) + " instead")]
- public IEnumerable<IContentPack> GetContentPacks()
- {
- return this.ContentPacks.GetOwned();
- }
-#endif
-
/****
** Disposal
****/
diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs
index 75d3849d..f2002530 100644
--- a/src/SMAPI/Framework/ModLoading/ModResolver.cs
+++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs
@@ -147,12 +147,8 @@ namespace StardewModdingAPI.Framework.ModLoading
string actualFilename = new DirectoryInfo(mod.DirectoryPath).GetFiles(mod.Manifest.EntryDll).FirstOrDefault()?.Name;
if (actualFilename != mod.Manifest.EntryDll)
{
-#if SMAPI_3_0_STRICT
mod.SetStatus(ModMetadataStatus.Failed, $"its {nameof(IManifest.EntryDll)} value '{mod.Manifest.EntryDll}' doesn't match the actual file capitalisation '{actualFilename}'. The capitalisation must match for crossplatform compatibility.");
continue;
-#else
- SCore.DeprecationManager.Warn(mod.DisplayName, $"{nameof(IManifest.EntryDll)} value with case-insensitive capitalisation", "2.11", DeprecationLevel.PendingRemoval);
-#endif
}
}
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index 5dd52992..06a2e0af 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -190,24 +190,6 @@ namespace StardewModdingAPI.Framework
// initialise SMAPI
try
{
-#if !SMAPI_3_0_STRICT
- // hook up events
- ContentEvents.Init(this.EventManager);
- ControlEvents.Init(this.EventManager);
- GameEvents.Init(this.EventManager);
- GraphicsEvents.Init(this.EventManager);
- InputEvents.Init(this.EventManager);
- LocationEvents.Init(this.EventManager);
- MenuEvents.Init(this.EventManager);
- MineEvents.Init(this.EventManager);
- MultiplayerEvents.Init(this.EventManager);
- PlayerEvents.Init(this.EventManager);
- SaveEvents.Init(this.EventManager);
- SpecialisedEvents.Init(this.EventManager);
- TimeEvents.Init(this.EventManager);
-#endif
-
- // init JSON parser
JsonConverter[] converters = {
new ColorConverter(),
new PointConverter(),
@@ -262,10 +244,6 @@ namespace StardewModdingAPI.Framework
// set window titles
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}";
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}";
-#if SMAPI_3_0_STRICT
- this.GameInstance.Window.Title += " [SMAPI 3.0 strict mode]";
- Console.Title += " [SMAPI 3.0 strict mode]";
-#endif
}
catch (Exception ex)
{
@@ -375,9 +353,6 @@ namespace StardewModdingAPI.Framework
private void InitialiseAfterGameStart()
{
// add headers
-#if SMAPI_3_0_STRICT
- this.Monitor.Log($"You're running SMAPI 3.0 strict mode, so most mods won't work correctly. If that wasn't intended, install the normal version of SMAPI from https://smapi.io instead.", LogLevel.Warn);
-#endif
if (this.Settings.DeveloperMode)
this.Monitor.Log($"You have SMAPI for developers, so the console will be much more verbose. You can disable developer mode by installing the non-developer version of SMAPI, or by editing {Constants.ApiConfigPath}.", LogLevel.Info);
if (!this.Settings.CheckForUpdates)
@@ -439,11 +414,6 @@ namespace StardewModdingAPI.Framework
int modsLoaded = this.ModRegistry.GetAll().Count();
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion} with {modsLoaded} mods";
Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion} with {modsLoaded} mods";
-#if SMAPI_3_0_STRICT
- this.GameInstance.Window.Title += " [SMAPI 3.0 strict mode]";
- Console.Title += " [SMAPI 3.0 strict mode]";
-#endif
-
// start SMAPI console
new Thread(this.RunConsoleLoop).Start();
@@ -926,14 +896,6 @@ namespace StardewModdingAPI.Framework
return false;
}
-#if !SMAPI_3_0_STRICT
- // add deprecation warning for old version format
- {
- if (mod.Manifest?.Version is Toolkit.SemanticVersion version && version.IsLegacyFormat)
- SCore.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.PendingRemoval);
- }
-#endif
-
// validate dependencies
// Although dependences are validated before mods are loaded, a dependency may have failed to load.
if (mod.Manifest.Dependencies?.Any() == true)
@@ -1039,7 +1001,7 @@ namespace StardewModdingAPI.Framework
return new ContentPack(packDirPath, packManifest, packContentHelper, this.Toolkit.JsonHelper);
}
- modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper);
+ modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper);
}
// init mod
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs
index 704eb6bc..b35e1d71 100644
--- a/src/SMAPI/Framework/SGame.cs
+++ b/src/SMAPI/Framework/SGame.cs
@@ -9,9 +9,6 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
-#if !SMAPI_3_0_STRICT
-using Microsoft.Xna.Framework.Input;
-#endif
using Netcode;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Events;
@@ -228,12 +225,7 @@ namespace StardewModdingAPI.Framework
// raise events
this.Events.LoadStageChanged.Raise(new LoadStageChangedEventArgs(oldStage, newStage));
if (newStage == LoadStage.None)
- {
this.Events.ReturnedToTitle.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- this.Events.Legacy_AfterReturnToTitle.Raise();
-#endif
- }
}
/// <summary>Constructor a content manager to read XNB files.</summary>
@@ -344,9 +336,6 @@ namespace StardewModdingAPI.Framework
SGame.TicksElapsed++;
base.Update(gameTime);
events.UnvalidatedUpdateTicked.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_UnvalidatedUpdateTick.Raise();
-#endif
return;
}
@@ -393,9 +382,6 @@ namespace StardewModdingAPI.Framework
// This should *always* run, even when suppressing mod events, since the game uses
// this too. For example, doing this after mod event suppression would prevent the
// user from doing anything on the overnight shipping screen.
-#if !SMAPI_3_0_STRICT
- SInputState previousInputState = this.Input.Clone();
-#endif
SInputState inputState = this.Input;
if (this.IsActive)
inputState.TrueUpdate();
@@ -416,9 +402,6 @@ namespace StardewModdingAPI.Framework
this.IsBetweenCreateEvents = true;
this.Monitor.Log("Context: before save creation.", LogLevel.Trace);
events.SaveCreating.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_BeforeCreateSave.Raise();
-#endif
}
// raise before-save
@@ -427,9 +410,6 @@ namespace StardewModdingAPI.Framework
this.IsBetweenSaveEvents = true;
this.Monitor.Log("Context: before save.", LogLevel.Trace);
events.Saving.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_BeforeSave.Raise();
-#endif
}
// suppress non-save events
@@ -437,9 +417,6 @@ namespace StardewModdingAPI.Framework
SGame.TicksElapsed++;
base.Update(gameTime);
events.UnvalidatedUpdateTicked.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_UnvalidatedUpdateTick.Raise();
-#endif
return;
}
if (this.IsBetweenCreateEvents)
@@ -449,9 +426,6 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Context: after save creation, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace);
this.OnLoadStageChanged(LoadStage.CreatedSaveFile);
events.SaveCreated.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_AfterCreateSave.Raise();
-#endif
}
if (this.IsBetweenSaveEvents)
{
@@ -460,10 +434,6 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Context: after save, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace);
events.Saved.RaiseEmpty();
events.DayStarted.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_AfterSave.Raise();
- events.Legacy_AfterDayStarted.Raise();
-#endif
}
/*********
@@ -492,15 +462,8 @@ namespace StardewModdingAPI.Framework
*********/
if (this.Watchers.LocaleWatcher.IsChanged)
{
- var was = this.Watchers.LocaleWatcher.PreviousValue;
- var now = this.Watchers.LocaleWatcher.CurrentValue;
-
- this.Monitor.Log($"Context: locale set to {now}.", LogLevel.Trace);
-
+ this.Monitor.Log($"Context: locale set to {this.Watchers.LocaleWatcher.CurrentValue}.", LogLevel.Trace);
this.OnLocaleChanged();
-#if !SMAPI_3_0_STRICT
- events.Legacy_LocaleChanged.Raise(new EventArgsValueChanged<string>(was.ToString(), now.ToString()));
-#endif
this.Watchers.LocaleWatcher.Reset();
}
@@ -527,10 +490,6 @@ namespace StardewModdingAPI.Framework
this.OnLoadStageChanged(LoadStage.Ready);
events.SaveLoaded.RaiseEmpty();
events.DayStarted.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_AfterLoad.Raise();
- events.Legacy_AfterDayStarted.Raise();
-#endif
}
/*********
@@ -549,9 +508,6 @@ namespace StardewModdingAPI.Framework
Point newSize = this.Watchers.WindowSizeWatcher.CurrentValue;
events.WindowResized.Raise(new WindowResizedEventArgs(oldSize, newSize));
-#if !SMAPI_3_0_STRICT
- events.Legacy_Resize.Raise();
-#endif
this.Watchers.WindowSizeWatcher.Reset();
}
@@ -610,23 +566,6 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: button {button} pressed.", LogLevel.Trace);
events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState));
-
-#if !SMAPI_3_0_STRICT
- // legacy events
- events.Legacy_ButtonPressed.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons));
- if (button.TryGetKeyboard(out Keys key))
- {
- if (key != Keys.None)
- events.Legacy_KeyPressed.Raise(new EventArgsKeyPressed(key));
- }
- else if (button.TryGetController(out Buttons controllerButton))
- {
- if (controllerButton == Buttons.LeftTrigger || controllerButton == Buttons.RightTrigger)
- events.Legacy_ControllerTriggerPressed.Raise(new EventArgsControllerTriggerPressed(PlayerIndex.One, controllerButton, controllerButton == Buttons.LeftTrigger ? inputState.RealController.Triggers.Left : inputState.RealController.Triggers.Right));
- else
- events.Legacy_ControllerButtonPressed.Raise(new EventArgsControllerButtonPressed(PlayerIndex.One, controllerButton));
- }
-#endif
}
else if (status == InputStatus.Released)
{
@@ -634,33 +573,8 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: button {button} released.", LogLevel.Trace);
events.ButtonReleased.Raise(new ButtonReleasedEventArgs(button, cursor, inputState));
-
-#if !SMAPI_3_0_STRICT
- // legacy events
- events.Legacy_ButtonReleased.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons));
- if (button.TryGetKeyboard(out Keys key))
- {
- if (key != Keys.None)
- events.Legacy_KeyReleased.Raise(new EventArgsKeyPressed(key));
- }
- else if (button.TryGetController(out Buttons controllerButton))
- {
- if (controllerButton == Buttons.LeftTrigger || controllerButton == Buttons.RightTrigger)
- events.Legacy_ControllerTriggerReleased.Raise(new EventArgsControllerTriggerReleased(PlayerIndex.One, controllerButton, controllerButton == Buttons.LeftTrigger ? inputState.RealController.Triggers.Left : inputState.RealController.Triggers.Right));
- else
- events.Legacy_ControllerButtonReleased.Raise(new EventArgsControllerButtonReleased(PlayerIndex.One, controllerButton));
- }
-#endif
}
}
-
-#if !SMAPI_3_0_STRICT
- // raise legacy state-changed events
- if (inputState.RealKeyboard != previousInputState.RealKeyboard)
- events.Legacy_KeyboardChanged.Raise(new EventArgsKeyboardStateChanged(previousInputState.RealKeyboard, inputState.RealKeyboard));
- if (inputState.RealMouse != previousInputState.RealMouse)
- events.Legacy_MouseChanged.Raise(new EventArgsMouseStateChanged(previousInputState.RealMouse, inputState.RealMouse, new Point((int)previousInputState.CursorPosition.ScreenPixels.X, (int)previousInputState.CursorPosition.ScreenPixels.Y), new Point((int)inputState.CursorPosition.ScreenPixels.X, (int)inputState.CursorPosition.ScreenPixels.Y)));
-#endif
}
}
@@ -678,12 +592,6 @@ namespace StardewModdingAPI.Framework
// raise menu events
events.MenuChanged.Raise(new MenuChangedEventArgs(was, now));
-#if !SMAPI_3_0_STRICT
- if (now != null)
- events.Legacy_MenuChanged.Raise(new EventArgsClickableMenuChanged(was, now));
- else
- events.Legacy_MenuClosed.Raise(new EventArgsClickableMenuClosed(was));
-#endif
}
/*********
@@ -711,9 +619,6 @@ namespace StardewModdingAPI.Framework
}
events.LocationListChanged.Raise(new LocationListChangedEventArgs(added, removed));
-#if !SMAPI_3_0_STRICT
- events.Legacy_LocationsChanged.Raise(new EventArgsLocationsChanged(added, removed));
-#endif
}
// raise location contents changed
@@ -730,9 +635,6 @@ namespace StardewModdingAPI.Framework
watcher.BuildingsWatcher.Reset();
events.BuildingListChanged.Raise(new BuildingListChangedEventArgs(location, added, removed));
-#if !SMAPI_3_0_STRICT
- events.Legacy_BuildingsChanged.Raise(new EventArgsLocationBuildingsChanged(location, added, removed));
-#endif
}
// debris changed
@@ -777,9 +679,6 @@ namespace StardewModdingAPI.Framework
watcher.ObjectsWatcher.Reset();
events.ObjectListChanged.Raise(new ObjectListChangedEventArgs(location, added, removed));
-#if !SMAPI_3_0_STRICT
- events.Legacy_ObjectsChanged.Raise(new EventArgsLocationObjectsChanged(location, added, removed));
-#endif
}
// terrain features changed
@@ -809,9 +708,6 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: time changed from {was} to {now}.", LogLevel.Trace);
events.TimeChanged.Raise(new TimeChangedEventArgs(was, now));
-#if !SMAPI_3_0_STRICT
- events.Legacy_TimeOfDayChanged.Raise(new EventArgsIntChanged(was, now));
-#endif
}
else
this.Watchers.TimeWatcher.Reset();
@@ -829,9 +725,6 @@ namespace StardewModdingAPI.Framework
GameLocation oldLocation = playerTracker.LocationWatcher.PreviousValue;
events.Warped.Raise(new WarpedEventArgs(playerTracker.Player, oldLocation, newLocation));
-#if !SMAPI_3_0_STRICT
- events.Legacy_PlayerWarped.Raise(new EventArgsPlayerWarped(oldLocation, newLocation));
-#endif
}
// raise player leveled up a skill
@@ -841,9 +734,6 @@ namespace StardewModdingAPI.Framework
this.Monitor.Log($"Events: player skill '{pair.Key}' changed from {pair.Value.PreviousValue} to {pair.Value.CurrentValue}.", LogLevel.Trace);
events.LevelChanged.Raise(new LevelChangedEventArgs(playerTracker.Player, pair.Key, pair.Value.PreviousValue, pair.Value.CurrentValue));
-#if !SMAPI_3_0_STRICT
- events.Legacy_LeveledUp.Raise(new EventArgsLevelUp((EventArgsLevelUp.LevelType)pair.Key, pair.Value.CurrentValue));
-#endif
}
// raise player inventory changed
@@ -853,9 +743,6 @@ namespace StardewModdingAPI.Framework
if (this.Monitor.IsVerbose)
this.Monitor.Log("Events: player inventory changed.", LogLevel.Trace);
events.InventoryChanged.Raise(new InventoryChangedEventArgs(playerTracker.Player, changedItems));
-#if !SMAPI_3_0_STRICT
- events.Legacy_InventoryChanged.Raise(new EventArgsInventoryChanged(Game1.player.Items, changedItems));
-#endif
}
// raise mine level changed
@@ -863,9 +750,6 @@ namespace StardewModdingAPI.Framework
{
if (this.Monitor.IsVerbose)
this.Monitor.Log($"Context: mine level changed to {mineLevel}.", LogLevel.Trace);
-#if !SMAPI_3_0_STRICT
- events.Legacy_MineLevelChanged.Raise(new EventArgsMineLevelChanged(playerTracker.MineLevelWatcher.PreviousValue, mineLevel));
-#endif
}
}
this.Watchers.CurrentPlayerTracker?.Reset();
@@ -910,25 +794,6 @@ namespace StardewModdingAPI.Framework
/*********
** Update events
*********/
-#if !SMAPI_3_0_STRICT
- events.Legacy_UnvalidatedUpdateTick.Raise();
- if (isFirstTick)
- events.Legacy_FirstUpdateTick.Raise();
- events.Legacy_UpdateTick.Raise();
- if (SGame.TicksElapsed % 2 == 0)
- events.Legacy_SecondUpdateTick.Raise();
- if (SGame.TicksElapsed % 4 == 0)
- events.Legacy_FourthUpdateTick.Raise();
- if (SGame.TicksElapsed % 8 == 0)
- events.Legacy_EighthUpdateTick.Raise();
- if (SGame.TicksElapsed % 15 == 0)
- events.Legacy_QuarterSecondTick.Raise();
- if (SGame.TicksElapsed % 30 == 0)
- events.Legacy_HalfSecondTick.Raise();
- if (SGame.TicksElapsed % 60 == 0)
- events.Legacy_OneSecondTick.Raise();
-#endif
-
this.UpdateCrashTimer.Reset();
}
catch (Exception ex)
@@ -1014,14 +879,8 @@ namespace StardewModdingAPI.Framework
try
{
events.RenderingActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPreRenderGuiEvent.Raise();
-#endif
activeClickableMenu.draw(Game1.spriteBatch);
events.RenderedActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderGuiEvent.Raise();
-#endif
}
catch (Exception ex)
{
@@ -1029,10 +888,6 @@ namespace StardewModdingAPI.Framework
activeClickableMenu.exitThisMenu();
}
events.Rendered.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderEvent.Raise();
-#endif
-
Game1.spriteBatch.End();
}
if (Game1.overlayMenu != null)
@@ -1055,14 +910,8 @@ namespace StardewModdingAPI.Framework
{
Game1.activeClickableMenu.drawBackground(Game1.spriteBatch);
events.RenderingActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPreRenderGuiEvent.Raise();
-#endif
Game1.activeClickableMenu.draw(Game1.spriteBatch);
events.RenderedActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderGuiEvent.Raise();
-#endif
}
catch (Exception ex)
{
@@ -1070,9 +919,6 @@ namespace StardewModdingAPI.Framework
Game1.activeClickableMenu.exitThisMenu();
}
events.Rendered.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderEvent.Raise();
-#endif
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
if ((double)Game1.options.zoomLevel != 1.0)
@@ -1097,9 +943,6 @@ namespace StardewModdingAPI.Framework
Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:Game1.cs.3686"), new Vector2(16f, 32f), new Color(0, (int)byte.MaxValue, 0));
Game1.spriteBatch.DrawString(Game1.dialogueFont, Game1.parseText(Game1.errorMessage, Game1.dialogueFont, Game1.graphics.GraphicsDevice.Viewport.Width), new Vector2(16f, 48f), Color.White);
events.Rendered.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderEvent.Raise();
-#endif
Game1.spriteBatch.End();
}
else if (Game1.currentMinigame != null)
@@ -1112,9 +955,6 @@ namespace StardewModdingAPI.Framework
Game1.spriteBatch.End();
}
this.drawOverlays(Game1.spriteBatch);
-#if !SMAPI_3_0_STRICT
- this.RaisePostRender(needsNewBatch: true);
-#endif
if ((double)Game1.options.zoomLevel == 1.0)
return;
this.GraphicsDevice.SetRenderTarget((RenderTarget2D)null);
@@ -1132,14 +972,8 @@ namespace StardewModdingAPI.Framework
try
{
events.RenderingActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPreRenderGuiEvent.Raise();
-#endif
Game1.activeClickableMenu.draw(Game1.spriteBatch);
events.RenderedActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderGuiEvent.Raise();
-#endif
}
catch (Exception ex)
{
@@ -1229,9 +1063,6 @@ namespace StardewModdingAPI.Framework
if (++batchOpens == 1)
events.Rendering.RaiseEmpty();
events.RenderingWorld.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPreRenderEvent.Raise();
-#endif
if (Game1.background != null)
Game1.background.draw(Game1.spriteBatch);
Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch);
@@ -1389,7 +1220,7 @@ namespace StardewModdingAPI.Framework
}
Game1.drawPlayerHeldObject(Game1.player);
}
- label_129:
+ label_129:
if ((Game1.player.UsingTool || Game1.pickingTool) && Game1.player.CurrentTool != null && ((!Game1.player.CurrentTool.Name.Equals("Seeds") || Game1.pickingTool) && (Game1.currentLocation.Map.GetLayer("Front").PickTile(new Location(Game1.player.getStandingX(), (int)Game1.player.Position.Y - 38), Game1.viewport.Size) != null && Game1.currentLocation.Map.GetLayer("Front").PickTile(new Location(Game1.player.getStandingX(), Game1.player.getStandingY()), Game1.viewport.Size) == null)))
Game1.drawTool(Game1.player);
if (Game1.currentLocation.Map.GetLayer("AlwaysFront") != null)
@@ -1544,14 +1375,8 @@ namespace StardewModdingAPI.Framework
if ((Game1.displayHUD || Game1.eventUp) && (Game1.currentBillboard == 0 && Game1.gameMode == (byte)3) && (!Game1.freezeControls && !Game1.panMode && !Game1.HostPaused))
{
events.RenderingHud.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPreRenderHudEvent.Raise();
-#endif
this.drawHUD();
events.RenderedHud.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderHudEvent.Raise();
-#endif
}
else if (Game1.activeClickableMenu == null && Game1.farmEvent == null)
Game1.spriteBatch.Draw(Game1.mouseCursors, new Vector2((float)Game1.getOldMouseX(), (float)Game1.getOldMouseY()), new Microsoft.Xna.Framework.Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)(4.0 + (double)Game1.dialogueButtonScale / 150.0), SpriteEffects.None, 1f);
@@ -1660,14 +1485,8 @@ namespace StardewModdingAPI.Framework
try
{
events.RenderingActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPreRenderGuiEvent.Raise();
-#endif
Game1.activeClickableMenu.draw(Game1.spriteBatch);
events.RenderedActiveMenu.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderGuiEvent.Raise();
-#endif
}
catch (Exception ex)
{
@@ -1684,9 +1503,6 @@ namespace StardewModdingAPI.Framework
}
events.Rendered.RaiseEmpty();
-#if !SMAPI_3_0_STRICT
- events.Legacy_OnPostRenderEvent.Raise();
-#endif
Game1.spriteBatch.End();
this.drawOverlays(Game1.spriteBatch);
this.renderScreenBuffer();
@@ -1694,24 +1510,5 @@ namespace StardewModdingAPI.Framework
}
}
}
-
- /****
- ** Methods
- ****/
-#if !SMAPI_3_0_STRICT
- /// <summary>Raise the <see cref="GraphicsEvents.OnPostRenderEvent"/> if there are any listeners.</summary>
- /// <param name="needsNewBatch">Whether to create a new sprite batch.</param>
- private void RaisePostRender(bool needsNewBatch = false)
- {
- if (this.Events.Legacy_OnPostRenderEvent.HasListeners())
- {
- if (needsNewBatch)
- Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
- this.Events.Legacy_OnPostRenderEvent.Raise();
- if (needsNewBatch)
- Game1.spriteBatch.End();
- }
- }
-#endif
}
}
diff --git a/src/SMAPI/Framework/SMultiplayer.cs b/src/SMAPI/Framework/SMultiplayer.cs
index dde71092..ffe2320b 100644
--- a/src/SMAPI/Framework/SMultiplayer.cs
+++ b/src/SMAPI/Framework/SMultiplayer.cs
@@ -89,24 +89,6 @@ namespace StardewModdingAPI.Framework
this.HostPeer = null;
}
-#if !SMAPI_3_0_STRICT
- /// <summary>Handle sync messages from other players and perform other initial sync logic.</summary>
- public override void UpdateEarly()
- {
- this.EventManager.Legacy_BeforeMainSync.Raise();
- base.UpdateEarly();
- this.EventManager.Legacy_AfterMainSync.Raise();
- }
-
- /// <summary>Broadcast sync messages to other players and perform other final sync logic.</summary>
- public override void UpdateLate(bool forceSync = false)
- {
- this.EventManager.Legacy_BeforeMainBroadcast.Raise();
- base.UpdateLate(forceSync);
- this.EventManager.Legacy_AfterMainBroadcast.Raise();
- }
-#endif
-
/// <summary>Initialise a client before the game connects to a remote server.</summary>
/// <param name="client">The client to initialise.</param>
public override Client InitClient(Client client)