From fb253941dfdd370d3081c6e46707424d993b300a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 25 Nov 2018 00:07:26 -0500 Subject: add support for propagating map asset changes --- src/SMAPI/Framework/ContentCoordinator.cs | 16 +++++++++------- .../Framework/ContentManagers/BaseContentManager.cs | 14 ++++++++------ src/SMAPI/Framework/ContentManagers/IContentManager.cs | 4 ++-- 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index 9eb7b5f9..08a32a9b 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -238,28 +238,30 @@ namespace StardewModdingAPI.Framework public IEnumerable InvalidateCache(Func predicate, bool dispose = false) { // invalidate cache - HashSet removedAssetNames = new HashSet(); + IDictionary removedAssetNames = new Dictionary(StringComparer.InvariantCultureIgnoreCase); foreach (IContentManager contentManager in this.ContentManagers) { - foreach (string name in contentManager.InvalidateCache(predicate, dispose)) - removedAssetNames.Add(name); + foreach (Tuple asset in contentManager.InvalidateCache(predicate, dispose)) + removedAssetNames[asset.Item1] = asset.Item2; } // reload core game assets int reloaded = 0; - foreach (string key in removedAssetNames) + foreach (var pair in removedAssetNames) { - if (this.CoreAssets.Propagate(this.MainContentManager, key)) // use an intercepted content manager + string key = pair.Key; + Type type = pair.Value; + if (this.CoreAssets.Propagate(this.MainContentManager, key, type)) // use an intercepted content manager reloaded++; } // report result if (removedAssetNames.Any()) - this.Monitor.Log($"Invalidated {removedAssetNames.Count} asset names: {string.Join(", ", removedAssetNames.OrderBy(p => p, StringComparer.InvariantCultureIgnoreCase))}. Reloaded {reloaded} core assets.", LogLevel.Trace); + this.Monitor.Log($"Invalidated {removedAssetNames.Count} asset names: {string.Join(", ", removedAssetNames.Keys.OrderBy(p => p, StringComparer.InvariantCultureIgnoreCase))}. Reloaded {reloaded} core assets.", LogLevel.Trace); else this.Monitor.Log("Invalidated 0 cache entries.", LogLevel.Trace); - return removedAssetNames; + return removedAssetNames.Keys; } /// Dispose held resources. diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs index 18aae05b..ed08f11c 100644 --- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs @@ -200,23 +200,25 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Purge matched assets from the cache. /// Matches the asset keys to invalidate. /// Whether to dispose invalidated assets. This should only be true when they're being invalidated as part of a dispose, to avoid crashing the game. - /// Returns the number of invalidated assets. - public IEnumerable InvalidateCache(Func predicate, bool dispose = false) + /// Returns the invalidated asset names and types. + public IEnumerable> InvalidateCache(Func predicate, bool dispose = false) { - HashSet removeAssetNames = new HashSet(StringComparer.InvariantCultureIgnoreCase); + Dictionary removeAssetNames = new Dictionary(StringComparer.InvariantCultureIgnoreCase); this.Cache.Remove((key, type) => { this.ParseCacheKey(key, out string assetName, out _); - if (removeAssetNames.Contains(assetName) || predicate(assetName, type)) + if (removeAssetNames.ContainsKey(assetName)) + return true; + if (predicate(assetName, type)) { - removeAssetNames.Add(assetName); + removeAssetNames[assetName] = type; return true; } return false; }); - return removeAssetNames; + return removeAssetNames.Select(p => Tuple.Create(p.Key, p.Value)); } /// Dispose held resources. diff --git a/src/SMAPI/Framework/ContentManagers/IContentManager.cs b/src/SMAPI/Framework/ContentManagers/IContentManager.cs index 1eb8b0ac..17618edd 100644 --- a/src/SMAPI/Framework/ContentManagers/IContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/IContentManager.cs @@ -80,7 +80,7 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Purge matched assets from the cache. /// Matches the asset keys to invalidate. /// Whether to dispose invalidated assets. This should only be true when they're being invalidated as part of a dispose, to avoid crashing the game. - /// Returns the number of invalidated assets. - IEnumerable InvalidateCache(Func predicate, bool dispose = false); + /// Returns the invalidated asset names and types. + IEnumerable> InvalidateCache(Func predicate, bool dispose = false); } } -- cgit From b34cbb5b860ac4cd4a4b9e564e6e53245be3e790 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 25 Nov 2018 13:14:45 -0500 Subject: fix error when leaving & rejoining a server in the same session --- docs/release-notes.md | 1 + src/SMAPI/Framework/SGame.cs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index 2f229d38..c2b58cd2 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,7 @@ ## Upcoming * For players: * Fixed cryptic error when running the installer from inside a zip file on Windows. + * Fixed error when leaving and rejoining a multiplayer server in the same session. * Fixed Console Commands' handling of tool upgrade levels for item commands. * For modders: diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 75cf4c52..9c6ff4dd 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -206,6 +206,15 @@ namespace StardewModdingAPI.Framework this.Events.ModMessageReceived.RaiseForMods(new ModMessageReceivedEventArgs(message), mod => mod != null && modIDs.Contains(mod.Manifest.UniqueID)); } + /// A callback raised when the player quits a save and returns to the title screen. + private void OnReturnedToTitle() + { + this.Monitor.Log("Context: returned to title", LogLevel.Trace); + this.Multiplayer.Peers.Clear(); + this.Events.ReturnedToTitle.RaiseEmpty(); + this.Events.Legacy_AfterReturnToTitle.Raise(); + } + /// Constructor a content manager to read XNB files. /// The service provider to use to locate services. /// The root directory to search for content. @@ -430,11 +439,7 @@ namespace StardewModdingAPI.Framework ** Load / return-to-title events *********/ if (wasWorldReady && !Context.IsWorldReady) - { - this.Monitor.Log("Context: returned to title", LogLevel.Trace); - this.Events.ReturnedToTitle.RaiseEmpty(); - this.Events.Legacy_AfterReturnToTitle.Raise(); - } + this.OnReturnedToTitle(); else if (!this.RaisedAfterLoadEvent && Context.IsWorldReady) { // print context -- cgit From e58681f1bccb02a5aa079a54a981fa05e39260c9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 28 Nov 2018 18:37:46 -0500 Subject: fix some map tilesheets not editable if not playing in English --- docs/release-notes.md | 1 + .../ContentManagers/BaseContentManager.cs | 6 ++--- .../ContentManagers/GameContentManager.cs | 27 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index cfcaf65c..2f5ecf5d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -8,6 +8,7 @@ * For modders: * Reloading a map asset will now update affected locations. * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. + * Fixed some map tilesheets not editable if not playing in English. * Fixed newlines in most manifest fields not being ignored. * For the web UI: diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs index ed08f11c..724a6e1c 100644 --- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs @@ -32,12 +32,12 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Whether the content coordinator has been disposed. private bool IsDisposed; - /// The language enum values indexed by locale code. - private readonly IDictionary LanguageCodes; - /// A callback to invoke when the content manager is being disposed. private readonly Action OnDisposing; + /// The language enum values indexed by locale code. + protected IDictionary LanguageCodes { get; } + /********* ** Accessors diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index a53840bc..4f3b6fbc 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using StardewModdingAPI.Framework.Content; +using StardewModdingAPI.Framework.Exceptions; using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Framework.Utilities; using StardewValley; @@ -52,7 +53,10 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The language code for which to load content. public override T Load(string assetName, LanguageCode language) { + // normalise asset name assetName = this.AssertAndNormaliseAssetName(assetName); + if (this.TryParseExplicitLanguageAssetKey(assetName, out string newAssetName, out LanguageCode newLanguage)) + return this.Load(newAssetName, newLanguage); // get from cache if (this.IsLoaded(assetName)) @@ -124,6 +128,29 @@ namespace StardewModdingAPI.Framework.ContentManagers return false; } + /// Parse an asset key that contains an explicit language into its asset name and language, if applicable. + /// The asset key to parse. + /// The asset name without the language code. + /// The language code removed from the asset name. + private bool TryParseExplicitLanguageAssetKey(string rawAsset, out string assetName, out LanguageCode language) + { + if (string.IsNullOrWhiteSpace(rawAsset)) + throw new SContentLoadException("The asset key is empty."); + + // extract language code + int splitIndex = rawAsset.LastIndexOf('.'); + if (splitIndex != -1 && this.LanguageCodes.TryGetValue(rawAsset.Substring(splitIndex + 1), out language)) + { + assetName = rawAsset.Substring(0, splitIndex); + return true; + } + + // no explicit language code found + assetName = rawAsset; + language = this.Language; + return false; + } + /// Load the initial asset from the registered . /// The basic asset metadata. /// Returns the loaded asset metadata, or null if no loader matched. -- cgit From dd15416d55a4ee6839e4343bc65cd3b08b467de7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 29 Nov 2018 23:06:36 -0500 Subject: fix RenderedWorld event not invoked before overlays are rendered --- docs/release-notes.md | 1 + src/SMAPI/Framework/SGame.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index 2f5ecf5d..ab60c6f8 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -10,6 +10,7 @@ * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. * Fixed some map tilesheets not editable if not playing in English. * Fixed newlines in most manifest fields not being ignored. + * Fixed `Display.RenderedWorld` event not invoked before overlays are rendered. * For the web UI: * Added stats to compatibility list. diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 9c6ff4dd..f76245a2 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -1345,6 +1345,7 @@ namespace StardewModdingAPI.Framework } Game1.spriteBatch.End(); } + this.Events.RenderedWorld.RaiseEmpty(); Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, (DepthStencilState)null, (RasterizerState)null); if (Game1.drawGrid) { @@ -1532,7 +1533,7 @@ namespace StardewModdingAPI.Framework string s = Game1.content.LoadString("Strings\\StringsFromCSFiles:DayTimeMoneyBox.cs.10378"); SpriteText.drawStringWithScrollBackground(Game1.spriteBatch, s, 96, 32, "", 1f, -1); } - this.Events.RenderedWorld.RaiseEmpty(); + this.Events.Rendered.RaiseEmpty(); this.Events.Legacy_OnPostRenderEvent.Raise(); Game1.spriteBatch.End(); -- cgit From a2a0469cd024e2fd4b35503db152ba1a6df712ec Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 3 Dec 2018 01:43:02 -0500 Subject: deprecate old events (#606) --- src/SMAPI/Events/ContentEvents.cs | 15 ++++++-- src/SMAPI/Events/ControlEvents.cs | 57 ++++++++++++++++++++++++++----- src/SMAPI/Events/GameEvents.cs | 57 ++++++++++++++++++++++++++----- src/SMAPI/Events/GraphicsEvents.cs | 51 ++++++++++++++++++++++----- src/SMAPI/Events/InputEvents.cs | 21 ++++++++++-- src/SMAPI/Events/LocationEvents.cs | 27 ++++++++++++--- src/SMAPI/Events/MenuEvents.cs | 21 ++++++++++-- src/SMAPI/Events/MineEvents.cs | 15 ++++++-- src/SMAPI/Events/MultiplayerEvents.cs | 33 +++++++++++++++--- src/SMAPI/Events/PlayerEvents.cs | 27 ++++++++++++--- src/SMAPI/Events/SaveEvents.cs | 45 ++++++++++++++++++++---- src/SMAPI/Events/SpecialisedEvents.cs | 15 ++++++-- src/SMAPI/Events/TimeEvents.cs | 21 ++++++++++-- src/SMAPI/Framework/DeprecationManager.cs | 6 ++++ src/SMAPI/Framework/SCore.cs | 26 +++++++------- src/SMAPI/IModHelper.cs | 1 - 16 files changed, 363 insertions(+), 75 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs index 3ee0560b..3bf3881b 100644 --- a/src/SMAPI/Events/ContentEvents.cs +++ b/src/SMAPI/Events/ContentEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when the game loads content. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class ContentEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// Raised after the content language changes. public static event EventHandler> AfterLocaleChanged { - add => ContentEvents.EventManager.Legacy_LocaleChanged.Add(value); + add + { + ContentEvents.DeprecationManager.WarnForOldEvents(); + ContentEvents.EventManager.Legacy_LocaleChanged.Add(value); + } remove => ContentEvents.EventManager.Legacy_LocaleChanged.Remove(value); } @@ -29,9 +38,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { ContentEvents.EventManager = eventManager; + ContentEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index 56a4fa3f..c50d5bea 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -1,10 +1,12 @@ using System; using Microsoft.Xna.Framework.Input; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when the player uses a controller, keyboard, or mouse. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class ControlEvents { /********* @@ -13,6 +15,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -20,56 +25,88 @@ namespace StardewModdingAPI.Events /// Raised when the changes. That happens when the player presses or releases a key. public static event EventHandler KeyboardChanged { - add => ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_KeyboardChanged.Add(value); + } remove => ControlEvents.EventManager.Legacy_KeyboardChanged.Remove(value); } /// Raised after the player presses a keyboard key. public static event EventHandler KeyPressed { - add => ControlEvents.EventManager.Legacy_KeyPressed.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_KeyPressed.Add(value); + } remove => ControlEvents.EventManager.Legacy_KeyPressed.Remove(value); } /// Raised after the player releases a keyboard key. public static event EventHandler KeyReleased { - add => ControlEvents.EventManager.Legacy_KeyReleased.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_KeyReleased.Add(value); + } remove => ControlEvents.EventManager.Legacy_KeyReleased.Remove(value); } /// Raised when the changes. That happens when the player moves the mouse, scrolls the mouse wheel, or presses/releases a button. public static event EventHandler MouseChanged { - add => ControlEvents.EventManager.Legacy_MouseChanged.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_MouseChanged.Add(value); + } remove => ControlEvents.EventManager.Legacy_MouseChanged.Remove(value); } /// The player pressed a controller button. This event isn't raised for trigger buttons. public static event EventHandler ControllerButtonPressed { - add => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerButtonPressed.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerButtonPressed.Remove(value); } /// The player released a controller button. This event isn't raised for trigger buttons. public static event EventHandler ControllerButtonReleased { - add => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerButtonReleased.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerButtonReleased.Remove(value); } /// The player pressed a controller trigger button. public static event EventHandler ControllerTriggerPressed { - add => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerTriggerPressed.Remove(value); } /// The player released a controller trigger button. public static event EventHandler ControllerTriggerReleased { - add => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value); + add + { + ControlEvents.DeprecationManager.WarnForOldEvents(); + ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Add(value); + } remove => ControlEvents.EventManager.Legacy_ControllerTriggerReleased.Remove(value); } @@ -79,9 +116,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { ControlEvents.EventManager = eventManager; + ControlEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs index 952b3570..13f6bfb0 100644 --- a/src/SMAPI/Events/GameEvents.cs +++ b/src/SMAPI/Events/GameEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when the game changes state. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class GameEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,56 +24,88 @@ namespace StardewModdingAPI.Events /// Raised when the game updates its state (≈60 times per second). public static event EventHandler UpdateTick { - add => GameEvents.EventManager.Legacy_UpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_UpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_UpdateTick.Remove(value); } /// Raised every other tick (≈30 times per second). public static event EventHandler SecondUpdateTick { - add => GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_SecondUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_SecondUpdateTick.Remove(value); } /// Raised every fourth tick (≈15 times per second). public static event EventHandler FourthUpdateTick { - add => GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_FourthUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_FourthUpdateTick.Remove(value); } /// Raised every eighth tick (≈8 times per second). public static event EventHandler EighthUpdateTick { - add => GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_EighthUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_EighthUpdateTick.Remove(value); } /// Raised every 15th tick (≈4 times per second). public static event EventHandler QuarterSecondTick { - add => GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_QuarterSecondTick.Add(value); + } remove => GameEvents.EventManager.Legacy_QuarterSecondTick.Remove(value); } /// Raised every 30th tick (≈twice per second). public static event EventHandler HalfSecondTick { - add => GameEvents.EventManager.Legacy_HalfSecondTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_HalfSecondTick.Add(value); + } remove => GameEvents.EventManager.Legacy_HalfSecondTick.Remove(value); } /// Raised every 60th tick (≈once per second). public static event EventHandler OneSecondTick { - add => GameEvents.EventManager.Legacy_OneSecondTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_OneSecondTick.Add(value); + } remove => GameEvents.EventManager.Legacy_OneSecondTick.Remove(value); } /// Raised once after the game initialises and all methods have been called. public static event EventHandler FirstUpdateTick { - add => GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value); + add + { + GameEvents.DeprecationManager.WarnForOldEvents(); + GameEvents.EventManager.Legacy_FirstUpdateTick.Add(value); + } remove => GameEvents.EventManager.Legacy_FirstUpdateTick.Remove(value); } @@ -78,9 +115,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { GameEvents.EventManager = eventManager; + GameEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs index 53f04822..de79e42e 100644 --- a/src/SMAPI/Events/GraphicsEvents.cs +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised during the game's draw loop, when the game is rendering content to the window. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class GraphicsEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// Raised after the game window is resized. public static event EventHandler Resize { - add => GraphicsEvents.EventManager.Legacy_Resize.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_Resize.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_Resize.Remove(value); } @@ -29,14 +38,22 @@ namespace StardewModdingAPI.Events /// Raised before drawing the world to the screen. public static event EventHandler OnPreRenderEvent { - add => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderEvent.Remove(value); } /// Raised after drawing the world to the screen. public static event EventHandler OnPostRenderEvent { - add => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderEvent.Remove(value); } @@ -46,14 +63,22 @@ namespace StardewModdingAPI.Events /// 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.) public static event EventHandler OnPreRenderHudEvent { - add => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderHudEvent.Remove(value); } /// 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.) public static event EventHandler OnPostRenderHudEvent { - add => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderHudEvent.Remove(value); } @@ -63,14 +88,22 @@ namespace StardewModdingAPI.Events /// Raised before drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen. public static event EventHandler OnPreRenderGuiEvent { - add => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPreRenderGuiEvent.Remove(value); } /// Raised after drawing a menu to the screen during a draw loop. This includes the game's internal menus like the title screen. public static event EventHandler OnPostRenderGuiEvent { - add => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value); + add + { + GraphicsEvents.DeprecationManager.WarnForOldEvents(); + GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Add(value); + } remove => GraphicsEvents.EventManager.Legacy_OnPostRenderGuiEvent.Remove(value); } @@ -80,9 +113,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { GraphicsEvents.EventManager = eventManager; + GraphicsEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index 4c1781a5..788dde62 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when the player uses a controller, keyboard, or mouse button. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class InputEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,14 +24,22 @@ namespace StardewModdingAPI.Events /// Raised when the player presses a button on the keyboard, controller, or mouse. public static event EventHandler ButtonPressed { - add => InputEvents.EventManager.Legacy_ButtonPressed.Add(value); + add + { + InputEvents.DeprecationManager.WarnForOldEvents(); + InputEvents.EventManager.Legacy_ButtonPressed.Add(value); + } remove => InputEvents.EventManager.Legacy_ButtonPressed.Remove(value); } /// Raised when the player releases a keyboard key on the keyboard, controller, or mouse. public static event EventHandler ButtonReleased { - add => InputEvents.EventManager.Legacy_ButtonReleased.Add(value); + add + { + InputEvents.DeprecationManager.WarnForOldEvents(); + InputEvents.EventManager.Legacy_ButtonReleased.Add(value); + } remove => InputEvents.EventManager.Legacy_ButtonReleased.Remove(value); } @@ -36,9 +49,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { InputEvents.EventManager = eventManager; + InputEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs index 81f547ae..4aad5387 100644 --- a/src/SMAPI/Events/LocationEvents.cs +++ b/src/SMAPI/Events/LocationEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when the player transitions between game locations, a location is added or removed, or the objects in the current location change. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class LocationEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,21 +24,33 @@ namespace StardewModdingAPI.Events /// Raised after a game location is added or removed. public static event EventHandler LocationsChanged { - add => LocationEvents.EventManager.Legacy_LocationsChanged.Add(value); + add + { + LocationEvents.DeprecationManager.WarnForOldEvents(); + LocationEvents.EventManager.Legacy_LocationsChanged.Add(value); + } remove => LocationEvents.EventManager.Legacy_LocationsChanged.Remove(value); } /// Raised after buildings are added or removed in a location. public static event EventHandler BuildingsChanged { - add => LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value); + add + { + LocationEvents.DeprecationManager.WarnForOldEvents(); + LocationEvents.EventManager.Legacy_BuildingsChanged.Add(value); + } remove => LocationEvents.EventManager.Legacy_BuildingsChanged.Remove(value); } /// Raised after objects are added or removed in a location. public static event EventHandler ObjectsChanged { - add => LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value); + add + { + LocationEvents.DeprecationManager.WarnForOldEvents(); + LocationEvents.EventManager.Legacy_ObjectsChanged.Add(value); + } remove => LocationEvents.EventManager.Legacy_ObjectsChanged.Remove(value); } @@ -43,9 +60,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { LocationEvents.EventManager = eventManager; + LocationEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MenuEvents.cs b/src/SMAPI/Events/MenuEvents.cs index 362b5070..502ec340 100644 --- a/src/SMAPI/Events/MenuEvents.cs +++ b/src/SMAPI/Events/MenuEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when a game menu is opened or closed (including internal menus like the title screen). + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class MenuEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,14 +24,22 @@ namespace StardewModdingAPI.Events /// Raised after a game menu is opened or replaced with another menu. This event is not invoked when a menu is closed. public static event EventHandler MenuChanged { - add => MenuEvents.EventManager.Legacy_MenuChanged.Add(value); + add + { + MenuEvents.DeprecationManager.WarnForOldEvents(); + MenuEvents.EventManager.Legacy_MenuChanged.Add(value); + } remove => MenuEvents.EventManager.Legacy_MenuChanged.Remove(value); } /// Raised after a game menu is closed. public static event EventHandler MenuClosed { - add => MenuEvents.EventManager.Legacy_MenuClosed.Add(value); + add + { + MenuEvents.DeprecationManager.WarnForOldEvents(); + MenuEvents.EventManager.Legacy_MenuClosed.Add(value); + } remove => MenuEvents.EventManager.Legacy_MenuClosed.Remove(value); } @@ -36,9 +49,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { MenuEvents.EventManager = eventManager; + MenuEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MineEvents.cs b/src/SMAPI/Events/MineEvents.cs index f5565a76..617c8013 100644 --- a/src/SMAPI/Events/MineEvents.cs +++ b/src/SMAPI/Events/MineEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when something happens in the mines. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class MineEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// Raised after the player warps to a new level of the mine. public static event EventHandler MineLevelChanged { - add => MineEvents.EventManager.Legacy_MineLevelChanged.Add(value); + add + { + MineEvents.DeprecationManager.WarnForOldEvents(); + MineEvents.EventManager.Legacy_MineLevelChanged.Add(value); + } remove => MineEvents.EventManager.Legacy_MineLevelChanged.Remove(value); } @@ -29,9 +38,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { MineEvents.EventManager = eventManager; + MineEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/MultiplayerEvents.cs b/src/SMAPI/Events/MultiplayerEvents.cs index 49de380e..14c58031 100644 --- a/src/SMAPI/Events/MultiplayerEvents.cs +++ b/src/SMAPI/Events/MultiplayerEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised during the multiplayer sync process. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class MultiplayerEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,28 +24,44 @@ namespace StardewModdingAPI.Events /// Raised before the game syncs changes from other players. public static event EventHandler BeforeMainSync { - add => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_BeforeMainSync.Remove(value); } /// Raised after the game syncs changes from other players. public static event EventHandler AfterMainSync { - add => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_AfterMainSync.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_AfterMainSync.Remove(value); } /// Raised before the game broadcasts changes to other players. public static event EventHandler BeforeMainBroadcast { - add => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_BeforeMainBroadcast.Remove(value); } /// Raised after the game broadcasts changes to other players. public static event EventHandler AfterMainBroadcast { - add => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value); + add + { + MultiplayerEvents.DeprecationManager.WarnForOldEvents(); + MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Add(value); + } remove => MultiplayerEvents.EventManager.Legacy_AfterMainBroadcast.Remove(value); } @@ -50,9 +71,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { MultiplayerEvents.EventManager = eventManager; + MultiplayerEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs index bfc1b569..4f5f4a37 100644 --- a/src/SMAPI/Events/PlayerEvents.cs +++ b/src/SMAPI/Events/PlayerEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when the player data changes. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class PlayerEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,21 +24,33 @@ namespace StardewModdingAPI.Events /// Raised after the player's inventory changes in any way (added or removed item, sorted, etc). public static event EventHandler InventoryChanged { - add => PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value); + add + { + PlayerEvents.DeprecationManager.WarnForOldEvents(); + PlayerEvents.EventManager.Legacy_InventoryChanged.Add(value); + } remove => PlayerEvents.EventManager.Legacy_InventoryChanged.Remove(value); } /// 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. public static event EventHandler LeveledUp { - add => PlayerEvents.EventManager.Legacy_LeveledUp.Add(value); + add + { + PlayerEvents.DeprecationManager.WarnForOldEvents(); + PlayerEvents.EventManager.Legacy_LeveledUp.Add(value); + } remove => PlayerEvents.EventManager.Legacy_LeveledUp.Remove(value); } /// Raised after the player warps to a new location. public static event EventHandler Warped { - add => PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value); + add + { + PlayerEvents.DeprecationManager.WarnForOldEvents(); + PlayerEvents.EventManager.Legacy_PlayerWarped.Add(value); + } remove => PlayerEvents.EventManager.Legacy_PlayerWarped.Remove(value); } @@ -44,9 +61,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { PlayerEvents.EventManager = eventManager; + PlayerEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/SaveEvents.cs b/src/SMAPI/Events/SaveEvents.cs index 731bf9d1..5b83efc8 100644 --- a/src/SMAPI/Events/SaveEvents.cs +++ b/src/SMAPI/Events/SaveEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised before and after the player saves/loads the game. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class SaveEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,42 +24,66 @@ namespace StardewModdingAPI.Events /// Raised before the game creates the save file. public static event EventHandler BeforeCreate { - add => SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_BeforeCreateSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_BeforeCreateSave.Remove(value); } /// Raised after the game finishes creating the save file. public static event EventHandler AfterCreate { - add => SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterCreateSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterCreateSave.Remove(value); } /// Raised before the game begins writes data to the save file. public static event EventHandler BeforeSave { - add => SaveEvents.EventManager.Legacy_BeforeSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_BeforeSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_BeforeSave.Remove(value); } /// Raised after the game finishes writing data to the save file. public static event EventHandler AfterSave { - add => SaveEvents.EventManager.Legacy_AfterSave.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterSave.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterSave.Remove(value); } /// Raised after the player loads a save slot. public static event EventHandler AfterLoad { - add => SaveEvents.EventManager.Legacy_AfterLoad.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterLoad.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterLoad.Remove(value); } /// Raised after the game returns to the title screen. public static event EventHandler AfterReturnToTitle { - add => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value); + add + { + SaveEvents.DeprecationManager.WarnForOldEvents(); + SaveEvents.EventManager.Legacy_AfterReturnToTitle.Add(value); + } remove => SaveEvents.EventManager.Legacy_AfterReturnToTitle.Remove(value); } @@ -64,9 +93,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { SaveEvents.EventManager = eventManager; + SaveEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/SpecialisedEvents.cs b/src/SMAPI/Events/SpecialisedEvents.cs index bdf25ccb..482ac62e 100644 --- a/src/SMAPI/Events/SpecialisedEvents.cs +++ b/src/SMAPI/Events/SpecialisedEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events serving specialised edge cases that shouldn't be used by most mods. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class SpecialisedEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,7 +24,11 @@ namespace StardewModdingAPI.Events /// 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. public static event EventHandler UnvalidatedUpdateTick { - add => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value); + add + { + SpecialisedEvents.DeprecationManager.WarnForOldEvents(); + SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Add(value); + } remove => SpecialisedEvents.EventManager.Legacy_UnvalidatedUpdateTick.Remove(value); } @@ -29,9 +38,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { SpecialisedEvents.EventManager = eventManager; + SpecialisedEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Events/TimeEvents.cs b/src/SMAPI/Events/TimeEvents.cs index 311ffe9e..cca6a056 100644 --- a/src/SMAPI/Events/TimeEvents.cs +++ b/src/SMAPI/Events/TimeEvents.cs @@ -1,9 +1,11 @@ using System; +using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; namespace StardewModdingAPI.Events { /// Events raised when the in-game date or time changes. + [Obsolete("Use " + nameof(Mod.Helper) + "." + nameof(IModHelper.Events) + " instead. See https://smapi.io/3.0 for more info.")] public static class TimeEvents { /********* @@ -12,6 +14,9 @@ namespace StardewModdingAPI.Events /// The core event manager. private static EventManager EventManager; + /// Manages deprecation warnings. + private static DeprecationManager DeprecationManager; + /********* ** Events @@ -19,14 +24,22 @@ namespace StardewModdingAPI.Events /// Raised after the game begins a new day, including when loading a save. public static event EventHandler AfterDayStarted { - add => TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value); + add + { + TimeEvents.DeprecationManager.WarnForOldEvents(); + TimeEvents.EventManager.Legacy_AfterDayStarted.Add(value); + } remove => TimeEvents.EventManager.Legacy_AfterDayStarted.Remove(value); } /// Raised after the in-game clock changes. public static event EventHandler TimeOfDayChanged { - add => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value); + add + { + TimeEvents.DeprecationManager.WarnForOldEvents(); + TimeEvents.EventManager.Legacy_TimeOfDayChanged.Add(value); + } remove => TimeEvents.EventManager.Legacy_TimeOfDayChanged.Remove(value); } @@ -36,9 +49,11 @@ namespace StardewModdingAPI.Events *********/ /// Initialise the events. /// The core event manager. - internal static void Init(EventManager eventManager) + /// Manages deprecation warnings. + internal static void Init(EventManager eventManager, DeprecationManager deprecationManager) { TimeEvents.EventManager = eventManager; + TimeEvents.DeprecationManager = deprecationManager; } } } diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs index 0fde67ee..be564c22 100644 --- a/src/SMAPI/Framework/DeprecationManager.cs +++ b/src/SMAPI/Framework/DeprecationManager.cs @@ -35,6 +35,12 @@ namespace StardewModdingAPI.Framework this.ModRegistry = modRegistry; } + /// Log a deprecation warning for the old-style events. + public void WarnForOldEvents() + { + this.Warn("legacy events", "2.9", DeprecationLevel.Notice); + } + /// Log a deprecation warning. /// A noun phrase describing what is deprecated. /// The SMAPI version which deprecated it. diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 4b95917b..827ed82c 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -181,19 +181,19 @@ namespace StardewModdingAPI.Framework try { // hook up events - ContentEvents.Init(this.EventManager); - ControlEvents.Init(this.EventManager); - GameEvents.Init(this.EventManager); - GraphicsEvents.Init(this.EventManager); - InputEvents.Init(this.EventManager); - LocationEvents.Init(this.EventManager); - MenuEvents.Init(this.EventManager); - MineEvents.Init(this.EventManager); - MultiplayerEvents.Init(this.EventManager); - PlayerEvents.Init(this.EventManager); - SaveEvents.Init(this.EventManager); - SpecialisedEvents.Init(this.EventManager); - TimeEvents.Init(this.EventManager); + ContentEvents.Init(this.EventManager, this.DeprecationManager); + ControlEvents.Init(this.EventManager, this.DeprecationManager); + GameEvents.Init(this.EventManager, this.DeprecationManager); + GraphicsEvents.Init(this.EventManager, this.DeprecationManager); + InputEvents.Init(this.EventManager, this.DeprecationManager); + LocationEvents.Init(this.EventManager, this.DeprecationManager); + MenuEvents.Init(this.EventManager, this.DeprecationManager); + MineEvents.Init(this.EventManager, this.DeprecationManager); + MultiplayerEvents.Init(this.EventManager, this.DeprecationManager); + PlayerEvents.Init(this.EventManager, this.DeprecationManager); + SaveEvents.Init(this.EventManager, this.DeprecationManager); + SpecialisedEvents.Init(this.EventManager, this.DeprecationManager); + TimeEvents.Init(this.EventManager, this.DeprecationManager); // init JSON parser JsonConverter[] converters = { diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs index e4b5d390..7e82e0d0 100644 --- a/src/SMAPI/IModHelper.cs +++ b/src/SMAPI/IModHelper.cs @@ -14,7 +14,6 @@ namespace StardewModdingAPI string DirectoryPath { get; } /// Manages access to events raised by SMAPI, which let your mod react when something happens in the game. - [Obsolete("This is an experimental interface which may change at any time. Don't depend on this for released mods.")] IModEvents Events { get; } /// An API for managing console commands. -- cgit From 3744e2f1e5505c9d15fb3bc985ad147a33621048 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 3 Dec 2018 02:39:20 -0500 Subject: add SMAPI 3.0 compatibility strict mode (#606) --- docs/technical-docs.md | 4 +- src/SMAPI.Mods.ConsoleCommands/ModEntry.cs | 4 +- src/SMAPI.Tests/Utilities/SemanticVersionTests.cs | 2 +- src/SMAPI/Context.cs | 2 +- src/SMAPI/Events/ContentEvents.cs | 2 + src/SMAPI/Events/ControlEvents.cs | 2 + src/SMAPI/Events/EventArgsClickableMenuChanged.cs | 2 + src/SMAPI/Events/EventArgsClickableMenuClosed.cs | 2 + .../Events/EventArgsControllerButtonPressed.cs | 2 + .../Events/EventArgsControllerButtonReleased.cs | 4 +- .../Events/EventArgsControllerTriggerPressed.cs | 2 + .../Events/EventArgsControllerTriggerReleased.cs | 4 +- src/SMAPI/Events/EventArgsInput.cs | 2 + src/SMAPI/Events/EventArgsIntChanged.cs | 2 + src/SMAPI/Events/EventArgsInventoryChanged.cs | 2 + src/SMAPI/Events/EventArgsKeyPressed.cs | 2 + src/SMAPI/Events/EventArgsKeyboardStateChanged.cs | 2 + src/SMAPI/Events/EventArgsLevelUp.cs | 2 + .../Events/EventArgsLocationBuildingsChanged.cs | 2 + .../Events/EventArgsLocationObjectsChanged.cs | 2 + src/SMAPI/Events/EventArgsLocationsChanged.cs | 2 + src/SMAPI/Events/EventArgsMineLevelChanged.cs | 4 +- src/SMAPI/Events/EventArgsMouseStateChanged.cs | 4 +- src/SMAPI/Events/EventArgsPlayerWarped.cs | 2 + src/SMAPI/Events/EventArgsValueChanged.cs | 6 +- src/SMAPI/Events/GameEvents.cs | 2 + src/SMAPI/Events/GraphicsEvents.cs | 2 + src/SMAPI/Events/InputEvents.cs | 2 + src/SMAPI/Events/LocationEvents.cs | 2 + src/SMAPI/Events/MenuEvents.cs | 2 + src/SMAPI/Events/MineEvents.cs | 2 + src/SMAPI/Events/MultiplayerEvents.cs | 2 + src/SMAPI/Events/PlayerEvents.cs | 2 + src/SMAPI/Events/SaveEvents.cs | 2 + src/SMAPI/Events/SpecialisedEvents.cs | 2 + src/SMAPI/Events/TimeEvents.cs | 2 + src/SMAPI/Framework/Events/EventManager.cs | 8 ++ src/SMAPI/Framework/ModHelpers/ModHelper.cs | 2 + .../ModLoading/InstructionHandleResult.cs | 2 +- src/SMAPI/Framework/ModLoading/ModWarning.cs | 2 +- src/SMAPI/Framework/SCore.cs | 21 ++++- src/SMAPI/Framework/SGame.cs | 102 +++++++++++++++++++-- src/SMAPI/Framework/SMultiplayer.cs | 2 + src/SMAPI/IModHelper.cs | 2 + src/SMAPI/Metadata/InstructionMetadata.cs | 3 + src/SMAPI/SemanticVersion.cs | 2 + src/SMAPI/StardewModdingAPI.csproj | 2 +- .../ISemanticVersion.cs | 2 + ...StardewModdingAPI.Toolkit.CoreInterfaces.csproj | 4 + src/StardewModdingAPI.Toolkit/SemanticVersion.cs | 20 ++-- .../StardewModdingAPI.Toolkit.csproj | 4 + 51 files changed, 229 insertions(+), 37 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/technical-docs.md b/docs/technical-docs.md index 5883ee00..1d69f868 100644 --- a/docs/technical-docs.md +++ b/docs/technical-docs.md @@ -105,8 +105,8 @@ SMAPI uses a small number of conditional compilation constants, which you can se flag | purpose ---- | ------- -`SMAPI_FOR_WINDOWS` | Indicates that SMAPI is being compiled on Windows for players on Windows. Set automatically in `crossplatform.targets`. - +`SMAPI_FOR_WINDOWS` | Whether SMAPI is being compiled on Windows for players on Windows. Set automatically in `crossplatform.targets`. +`SMAPI_3_0_STRICT` | Whether to exclude all deprecated APIs from compilation. This is useful for testing mods for SMAPI 3.0 compatibility. # SMAPI web services ## Overview diff --git a/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs b/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs index 7588043d..30951064 100644 --- a/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs +++ b/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs @@ -29,7 +29,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands helper.ConsoleCommands.Add(command.Name, command.Description, (name, args) => this.HandleCommand(command, name, args)); // hook events - GameEvents.UpdateTick += this.GameEvents_UpdateTick; + helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked; } @@ -39,7 +39,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands /// The method invoked when the game updates its state. /// The event sender. /// The event arguments. - private void GameEvents_UpdateTick(object sender, EventArgs e) + private void OnUpdateTicked(object sender, EventArgs e) { if (!Context.IsWorldReady) return; diff --git a/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs b/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs index 1782308b..2e7719eb 100644 --- a/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs +++ b/src/SMAPI.Tests/Utilities/SemanticVersionTests.cs @@ -47,7 +47,7 @@ namespace StardewModdingAPI.Tests.Utilities Assert.AreEqual(major, version.MajorVersion, "The major version doesn't match the given value."); Assert.AreEqual(minor, version.MinorVersion, "The minor version doesn't match the given value."); Assert.AreEqual(patch, version.PatchVersion, "The patch version doesn't match the given value."); - Assert.AreEqual(string.IsNullOrWhiteSpace(tag) ? null : tag.Trim(), version.Build, "The tag doesn't match the given value."); + Assert.AreEqual(string.IsNullOrWhiteSpace(tag) ? null : tag.Trim(), version.PrereleaseTag, "The tag doesn't match the given value."); return version.ToString(); } diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs index c7aed81d..cd1cf1c2 100644 --- a/src/SMAPI/Context.cs +++ b/src/SMAPI/Context.cs @@ -22,7 +22,7 @@ namespace StardewModdingAPI /// Whether is true and the player is free to move (e.g. not using a tool). public static bool CanPlayerMove => Context.IsPlayerFree && Game1.player.CanMove; - /// Whether the game is currently running the draw loop. This isn't relevant to most mods, since you should use to draw to the screen. + /// Whether the game is currently running the draw loop. This isn't relevant to most mods, since you should use events to draw to the screen. public static bool IsInDrawLoop { get; internal set; } /// Whether and the player loaded the save in multiplayer mode (regardless of whether any other players are connected). diff --git a/src/SMAPI/Events/ContentEvents.cs b/src/SMAPI/Events/ContentEvents.cs index 3bf3881b..99369cae 100644 --- a/src/SMAPI/Events/ContentEvents.cs +++ b/src/SMAPI/Events/ContentEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -46,3 +47,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/ControlEvents.cs b/src/SMAPI/Events/ControlEvents.cs index c50d5bea..5626ff81 100644 --- a/src/SMAPI/Events/ControlEvents.cs +++ b/src/SMAPI/Events/ControlEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework.Input; using StardewModdingAPI.Framework; @@ -124,3 +125,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsClickableMenuChanged.cs b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs index 5e00b86d..a0b903b7 100644 --- a/src/SMAPI/Events/EventArgsClickableMenuChanged.cs +++ b/src/SMAPI/Events/EventArgsClickableMenuChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewValley.Menus; @@ -29,3 +30,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsClickableMenuClosed.cs b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs index 65751da7..77db69ea 100644 --- a/src/SMAPI/Events/EventArgsClickableMenuClosed.cs +++ b/src/SMAPI/Events/EventArgsClickableMenuClosed.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewValley.Menus; @@ -24,3 +25,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerButtonPressed.cs b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs index 3243b80b..949446e1 100644 --- a/src/SMAPI/Events/EventArgsControllerButtonPressed.cs +++ b/src/SMAPI/Events/EventArgsControllerButtonPressed.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerButtonReleased.cs b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs index e05a080b..d6d6d840 100644 --- a/src/SMAPI/Events/EventArgsControllerButtonReleased.cs +++ b/src/SMAPI/Events/EventArgsControllerButtonReleased.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs index a2087733..33be2fa3 100644 --- a/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs +++ b/src/SMAPI/Events/EventArgsControllerTriggerPressed.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -35,3 +36,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs index d2eecbec..e90ff712 100644 --- a/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs +++ b/src/SMAPI/Events/EventArgsControllerTriggerReleased.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -35,3 +36,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index 0cafdba5..837de2f8 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; @@ -60,3 +61,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsIntChanged.cs b/src/SMAPI/Events/EventArgsIntChanged.cs index a018695c..76ec6d08 100644 --- a/src/SMAPI/Events/EventArgsIntChanged.cs +++ b/src/SMAPI/Events/EventArgsIntChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; namespace StardewModdingAPI.Events @@ -28,3 +29,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsInventoryChanged.cs b/src/SMAPI/Events/EventArgsInventoryChanged.cs index 3a2354b6..488dd23f 100644 --- a/src/SMAPI/Events/EventArgsInventoryChanged.cs +++ b/src/SMAPI/Events/EventArgsInventoryChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -39,3 +40,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsKeyPressed.cs b/src/SMAPI/Events/EventArgsKeyPressed.cs index d9d81e10..6204d821 100644 --- a/src/SMAPI/Events/EventArgsKeyPressed.cs +++ b/src/SMAPI/Events/EventArgsKeyPressed.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework.Input; @@ -24,3 +25,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs index 14e397ce..2c3203b1 100644 --- a/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs +++ b/src/SMAPI/Events/EventArgsKeyboardStateChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using Microsoft.Xna.Framework.Input; @@ -29,3 +30,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLevelUp.cs b/src/SMAPI/Events/EventArgsLevelUp.cs index e9a697e7..06c70088 100644 --- a/src/SMAPI/Events/EventArgsLevelUp.cs +++ b/src/SMAPI/Events/EventArgsLevelUp.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Enums; @@ -51,3 +52,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs b/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs index e8184ebe..25e84722 100644 --- a/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs +++ b/src/SMAPI/Events/EventArgsLocationBuildingsChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -37,3 +38,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs index 3bb387d5..9ca2e3e2 100644 --- a/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs +++ b/src/SMAPI/Events/EventArgsLocationObjectsChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -38,3 +39,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsLocationsChanged.cs b/src/SMAPI/Events/EventArgsLocationsChanged.cs index 20984f45..1a59e612 100644 --- a/src/SMAPI/Events/EventArgsLocationsChanged.cs +++ b/src/SMAPI/Events/EventArgsLocationsChanged.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using System.Collections.Generic; using System.Linq; @@ -31,3 +32,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsMineLevelChanged.cs b/src/SMAPI/Events/EventArgsMineLevelChanged.cs index c82fed35..c63b04e9 100644 --- a/src/SMAPI/Events/EventArgsMineLevelChanged.cs +++ b/src/SMAPI/Events/EventArgsMineLevelChanged.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; namespace StardewModdingAPI.Events { @@ -28,3 +29,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsMouseStateChanged.cs b/src/SMAPI/Events/EventArgsMouseStateChanged.cs index 57298164..09f3f759 100644 --- a/src/SMAPI/Events/EventArgsMouseStateChanged.cs +++ b/src/SMAPI/Events/EventArgsMouseStateChanged.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -40,3 +41,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsPlayerWarped.cs b/src/SMAPI/Events/EventArgsPlayerWarped.cs index 93026aea..d1aa1588 100644 --- a/src/SMAPI/Events/EventArgsPlayerWarped.cs +++ b/src/SMAPI/Events/EventArgsPlayerWarped.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewValley; @@ -30,3 +31,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/EventArgsValueChanged.cs b/src/SMAPI/Events/EventArgsValueChanged.cs index 1d25af49..7bfac7a2 100644 --- a/src/SMAPI/Events/EventArgsValueChanged.cs +++ b/src/SMAPI/Events/EventArgsValueChanged.cs @@ -1,4 +1,5 @@ -using System; +#if !SMAPI_3_0_STRICT +using System; namespace StardewModdingAPI.Events { @@ -28,4 +29,5 @@ namespace StardewModdingAPI.Events this.NewValue = newValue; } } -} \ No newline at end of file +} +#endif diff --git a/src/SMAPI/Events/GameEvents.cs b/src/SMAPI/Events/GameEvents.cs index 13f6bfb0..39b77f99 100644 --- a/src/SMAPI/Events/GameEvents.cs +++ b/src/SMAPI/Events/GameEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -123,3 +124,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/GraphicsEvents.cs b/src/SMAPI/Events/GraphicsEvents.cs index de79e42e..be29bf11 100644 --- a/src/SMAPI/Events/GraphicsEvents.cs +++ b/src/SMAPI/Events/GraphicsEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -121,3 +122,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/InputEvents.cs b/src/SMAPI/Events/InputEvents.cs index 788dde62..255b9c8a 100644 --- a/src/SMAPI/Events/InputEvents.cs +++ b/src/SMAPI/Events/InputEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -57,3 +58,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/LocationEvents.cs b/src/SMAPI/Events/LocationEvents.cs index 4aad5387..e0bcd853 100644 --- a/src/SMAPI/Events/LocationEvents.cs +++ b/src/SMAPI/Events/LocationEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -68,3 +69,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/MenuEvents.cs b/src/SMAPI/Events/MenuEvents.cs index 502ec340..e36cb498 100644 --- a/src/SMAPI/Events/MenuEvents.cs +++ b/src/SMAPI/Events/MenuEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -57,3 +58,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/MineEvents.cs b/src/SMAPI/Events/MineEvents.cs index 617c8013..954c844a 100644 --- a/src/SMAPI/Events/MineEvents.cs +++ b/src/SMAPI/Events/MineEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -46,3 +47,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/MultiplayerEvents.cs b/src/SMAPI/Events/MultiplayerEvents.cs index 14c58031..7e8328a4 100644 --- a/src/SMAPI/Events/MultiplayerEvents.cs +++ b/src/SMAPI/Events/MultiplayerEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -79,3 +80,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/PlayerEvents.cs b/src/SMAPI/Events/PlayerEvents.cs index 4f5f4a37..1193675f 100644 --- a/src/SMAPI/Events/PlayerEvents.cs +++ b/src/SMAPI/Events/PlayerEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -69,3 +70,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/SaveEvents.cs b/src/SMAPI/Events/SaveEvents.cs index 5b83efc8..156d3047 100644 --- a/src/SMAPI/Events/SaveEvents.cs +++ b/src/SMAPI/Events/SaveEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -101,3 +102,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/SpecialisedEvents.cs b/src/SMAPI/Events/SpecialisedEvents.cs index 482ac62e..0dd726e9 100644 --- a/src/SMAPI/Events/SpecialisedEvents.cs +++ b/src/SMAPI/Events/SpecialisedEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -46,3 +47,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Events/TimeEvents.cs b/src/SMAPI/Events/TimeEvents.cs index cca6a056..61491dc8 100644 --- a/src/SMAPI/Events/TimeEvents.cs +++ b/src/SMAPI/Events/TimeEvents.cs @@ -1,3 +1,4 @@ +#if !SMAPI_3_0_STRICT using System; using StardewModdingAPI.Framework; using StardewModdingAPI.Framework.Events; @@ -57,3 +58,4 @@ namespace StardewModdingAPI.Events } } } +#endif diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs index b9d1c453..0ad85adf 100644 --- a/src/SMAPI/Framework/Events/EventManager.cs +++ b/src/SMAPI/Framework/Events/EventManager.cs @@ -1,5 +1,7 @@ using System.Diagnostics.CodeAnalysis; +#if !SMAPI_3_0_STRICT using Microsoft.Xna.Framework.Input; +#endif using StardewModdingAPI.Events; namespace StardewModdingAPI.Framework.Events @@ -156,6 +158,7 @@ namespace StardewModdingAPI.Framework.Events public readonly ManagedEvent UnvalidatedUpdateTicked; +#if !SMAPI_3_0_STRICT /********* ** Events (old) *********/ @@ -342,6 +345,7 @@ namespace StardewModdingAPI.Framework.Events /// Raised after the in-game clock changes. public readonly ManagedEvent Legacy_TimeOfDayChanged; +#endif /********* @@ -354,7 +358,9 @@ namespace StardewModdingAPI.Framework.Events { // create shortcut initialisers ManagedEvent ManageEventOf(string typeName, string eventName) => new ManagedEvent($"{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(nameof(IModEvents.Display), nameof(IDisplayEvents.MenuChanged)); @@ -405,6 +411,7 @@ namespace StardewModdingAPI.Framework.Events this.UnvalidatedUpdateTicking = ManageEventOf(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicking)); this.UnvalidatedUpdateTicked = ManageEventOf(nameof(IModEvents.Specialised), nameof(ISpecialisedEvents.UnvalidatedUpdateTicked)); +#if !SMAPI_3_0_STRICT // init events (old) this.Legacy_LocaleChanged = ManageEventOf>(nameof(ContentEvents), nameof(ContentEvents.AfterLocaleChanged)); @@ -466,6 +473,7 @@ namespace StardewModdingAPI.Framework.Events this.Legacy_AfterDayStarted = ManageEvent(nameof(TimeEvents), nameof(TimeEvents.AfterDayStarted)); this.Legacy_TimeOfDayChanged = ManageEventOf(nameof(TimeEvents), nameof(TimeEvents.TimeOfDayChanged)); +#endif } } } diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index 5e190e55..cd7ac8ea 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -131,6 +131,7 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Data.WriteJsonFile("config.json", config); } +#if !SMAPI_3_0_STRICT /**** ** Generic JSON files ****/ @@ -199,6 +200,7 @@ namespace StardewModdingAPI.Framework.ModHelpers // create content pack return this.CreateContentPack(directoryPath, manifest); } +#endif /// Get all content packs loaded for this mod. public IEnumerable GetContentPacks() diff --git a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs index f3555c2d..6592760e 100644 --- a/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs +++ b/src/SMAPI/Framework/ModLoading/InstructionHandleResult.cs @@ -23,7 +23,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// The instruction is compatible, but uses the dynamic keyword which won't work on Linux/Mac. DetectedDynamic, - /// The instruction is compatible, but references which may impact stability. + /// The instruction is compatible, but references or which may impact stability. DetectedUnvalidatedUpdateTick, /// The instruction accesses the filesystem directly. diff --git a/src/SMAPI/Framework/ModLoading/ModWarning.cs b/src/SMAPI/Framework/ModLoading/ModWarning.cs index c62199b2..e643cb05 100644 --- a/src/SMAPI/Framework/ModLoading/ModWarning.cs +++ b/src/SMAPI/Framework/ModLoading/ModWarning.cs @@ -22,7 +22,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// The mod uses the dynamic keyword which won't work on Linux/Mac. UsesDynamic = 8, - /// The mod references which may impact stability. + /// The mod references or which may impact stability. UsesUnvalidatedUpdateTick = 16, /// The mod has no update keys set. diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 827ed82c..eff7cb3b 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -180,6 +180,7 @@ namespace StardewModdingAPI.Framework // initialise SMAPI try { +#if !SMAPI_3_0_STRICT // hook up events ContentEvents.Init(this.EventManager, this.DeprecationManager); ControlEvents.Init(this.EventManager, this.DeprecationManager); @@ -194,6 +195,7 @@ namespace StardewModdingAPI.Framework SaveEvents.Init(this.EventManager, this.DeprecationManager); SpecialisedEvents.Init(this.EventManager, this.DeprecationManager); TimeEvents.Init(this.EventManager, this.DeprecationManager); +#endif // init JSON parser JsonConverter[] converters = { @@ -216,7 +218,7 @@ namespace StardewModdingAPI.Framework // override game SGame.ConstructorHack = new SGameConstructorHack(this.Monitor, this.Reflection, this.Toolkit.JsonHelper); - this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.DeprecationManager, this.InitialiseAfterGameStart, this.Dispose); + this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose); StardewValley.Program.gamePtr = this.GameInstance; // add exit handler @@ -239,12 +241,13 @@ namespace StardewModdingAPI.Framework } }).Start(); - // hook into game events - ContentEvents.AfterLocaleChanged += (sender, e) => this.OnLocaleChanged(); - // 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) { @@ -348,8 +351,11 @@ 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 configured SMAPI to run in developer mode. The console may be much more verbose. You can disable developer mode by installing the non-developer version of SMAPI, or by editing {Constants.ApiConfigPath}.", LogLevel.Info); + 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) this.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn); if (!this.Monitor.WriteToConsole) @@ -409,6 +415,11 @@ 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(); diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index f76245a2..d15c5c3e 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -9,7 +9,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; using Netcode; using StardewModdingAPI.Enums; using StardewModdingAPI.Events; @@ -70,12 +69,15 @@ namespace StardewModdingAPI.Framework /// Whether the after-load events were raised for this session. private bool RaisedAfterLoadEvent; - /// Whether the game is saving and SMAPI has already raised . + /// Whether the game is saving and SMAPI has already raised . private bool IsBetweenSaveEvents; - /// Whether the game is creating the save file and SMAPI has already raised . + /// Whether the game is creating the save file and SMAPI has already raised . private bool IsBetweenCreateEvents; + /// A callback to invoke after the content language changes. + private readonly Action OnLocaleChanged; + /// A callback to invoke after the game finishes initialising. private readonly Action OnGameInitialised; @@ -138,9 +140,10 @@ namespace StardewModdingAPI.Framework /// Encapsulates SMAPI's JSON file parsing. /// Tracks the installed mods. /// Manages deprecation warnings. + /// A callback to invoke after the content language changes. /// A callback to invoke after the game finishes initialising. /// A callback to invoke when the game exits. - internal SGame(IMonitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, DeprecationManager deprecationManager, Action onGameInitialised, Action onGameExiting) + internal SGame(IMonitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, JsonHelper jsonHelper, ModRegistry modRegistry, DeprecationManager deprecationManager, Action onLocaleChanged, Action onGameInitialised, Action onGameExiting) { SGame.ConstructorHack = null; @@ -158,6 +161,7 @@ namespace StardewModdingAPI.Framework this.ModRegistry = modRegistry; this.Reflection = reflection; this.DeprecationManager = deprecationManager; + this.OnLocaleChanged = onLocaleChanged; this.OnGameInitialised = onGameInitialised; this.OnGameExiting = onGameExiting; Game1.input = new SInputState(); @@ -212,7 +216,9 @@ namespace StardewModdingAPI.Framework this.Monitor.Log("Context: returned to title", LogLevel.Trace); this.Multiplayer.Peers.Clear(); this.Events.ReturnedToTitle.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_AfterReturnToTitle.Raise(); +#endif } /// Constructor a content manager to read XNB files. @@ -296,7 +302,9 @@ namespace StardewModdingAPI.Framework this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed)); base.Update(gameTime); this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_UnvalidatedUpdateTick.Raise(); +#endif return; } @@ -343,7 +351,9 @@ 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(); @@ -364,7 +374,9 @@ namespace StardewModdingAPI.Framework this.IsBetweenCreateEvents = true; this.Monitor.Log("Context: before save creation.", LogLevel.Trace); this.Events.SaveCreating.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_BeforeCreateSave.Raise(); +#endif } // raise before-save @@ -373,14 +385,18 @@ namespace StardewModdingAPI.Framework this.IsBetweenSaveEvents = true; this.Monitor.Log("Context: before save.", LogLevel.Trace); this.Events.Saving.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_BeforeSave.Raise(); +#endif } // suppress non-save events this.Events.UnvalidatedUpdateTicking.Raise(new UnvalidatedUpdateTickingEventArgs(this.TicksElapsed)); base.Update(gameTime); this.Events.UnvalidatedUpdateTicked.Raise(new UnvalidatedUpdateTickedEventArgs(this.TicksElapsed)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_UnvalidatedUpdateTick.Raise(); +#endif return; } if (this.IsBetweenCreateEvents) @@ -389,7 +405,9 @@ namespace StardewModdingAPI.Framework this.IsBetweenCreateEvents = false; this.Monitor.Log($"Context: after save creation, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace); this.Events.SaveCreated.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_AfterCreateSave.Raise(); +#endif } if (this.IsBetweenSaveEvents) { @@ -398,9 +416,10 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Context: after save, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace); this.Events.Saved.RaiseEmpty(); this.Events.DayStarted.RaiseEmpty(); - +#if !SMAPI_3_0_STRICT this.Events.Legacy_AfterSave.Raise(); this.Events.Legacy_AfterDayStarted.Raise(); +#endif } /********* @@ -430,7 +449,11 @@ namespace StardewModdingAPI.Framework var now = this.Watchers.LocaleWatcher.CurrentValue; this.Monitor.Log($"Context: locale set to {now}.", LogLevel.Trace); + + this.OnLocaleChanged(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_LocaleChanged.Raise(new EventArgsValueChanged(was.ToString(), now.ToString())); +#endif this.Watchers.LocaleWatcher.Reset(); } @@ -457,9 +480,10 @@ namespace StardewModdingAPI.Framework this.RaisedAfterLoadEvent = true; this.Events.SaveLoaded.RaiseEmpty(); this.Events.DayStarted.RaiseEmpty(); - +#if !SMAPI_3_0_STRICT this.Events.Legacy_AfterLoad.Raise(); this.Events.Legacy_AfterDayStarted.Raise(); +#endif } /********* @@ -478,7 +502,9 @@ namespace StardewModdingAPI.Framework Point newSize = this.Watchers.WindowSizeWatcher.CurrentValue; this.Events.WindowResized.Raise(new WindowResizedEventArgs(oldSize, newSize)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_Resize.Raise(); +#endif this.Watchers.WindowSizeWatcher.Reset(); } @@ -527,9 +553,10 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Events: button {button} pressed.", LogLevel.Trace); this.Events.ButtonPressed.Raise(new ButtonPressedEventArgs(button, cursor, inputState)); - this.Events.Legacy_ButtonPressed.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons)); +#if !SMAPI_3_0_STRICT // legacy events + this.Events.Legacy_ButtonPressed.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons)); if (button.TryGetKeyboard(out Keys key)) { if (key != Keys.None) @@ -542,6 +569,7 @@ namespace StardewModdingAPI.Framework else this.Events.Legacy_ControllerButtonPressed.Raise(new EventArgsControllerButtonPressed(PlayerIndex.One, controllerButton)); } +#endif } else if (status == InputStatus.Released) { @@ -549,9 +577,10 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Events: button {button} released.", LogLevel.Trace); this.Events.ButtonReleased.Raise(new ButtonReleasedEventArgs(button, cursor, inputState)); - this.Events.Legacy_ButtonReleased.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons)); +#if !SMAPI_3_0_STRICT // legacy events + this.Events.Legacy_ButtonReleased.Raise(new EventArgsInput(button, cursor, inputState.SuppressButtons)); if (button.TryGetKeyboard(out Keys key)) { if (key != Keys.None) @@ -564,14 +593,17 @@ namespace StardewModdingAPI.Framework else this.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) this.Events.Legacy_KeyboardChanged.Raise(new EventArgsKeyboardStateChanged(previousInputState.RealKeyboard, inputState.RealKeyboard)); if (inputState.RealMouse != previousInputState.RealMouse) this.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 } } @@ -589,10 +621,12 @@ namespace StardewModdingAPI.Framework // raise menu events this.Events.MenuChanged.Raise(new MenuChangedEventArgs(was, now)); +#if !SMAPI_3_0_STRICT if (now != null) this.Events.Legacy_MenuChanged.Raise(new EventArgsClickableMenuChanged(was, now)); else this.Events.Legacy_MenuClosed.Raise(new EventArgsClickableMenuClosed(was)); +#endif } /********* @@ -620,7 +654,9 @@ namespace StardewModdingAPI.Framework } this.Events.LocationListChanged.Raise(new LocationListChangedEventArgs(added, removed)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_LocationsChanged.Raise(new EventArgsLocationsChanged(added, removed)); +#endif } // raise location contents changed @@ -637,7 +673,9 @@ namespace StardewModdingAPI.Framework watcher.BuildingsWatcher.Reset(); this.Events.BuildingListChanged.Raise(new BuildingListChangedEventArgs(location, added, removed)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_BuildingsChanged.Raise(new EventArgsLocationBuildingsChanged(location, added, removed)); +#endif } // debris changed @@ -682,7 +720,9 @@ namespace StardewModdingAPI.Framework watcher.ObjectsWatcher.Reset(); this.Events.ObjectListChanged.Raise(new ObjectListChangedEventArgs(location, added, removed)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_ObjectsChanged.Raise(new EventArgsLocationObjectsChanged(location, added, removed)); +#endif } // terrain features changed @@ -712,7 +752,9 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Events: time changed from {was} to {now}.", LogLevel.Trace); this.Events.TimeChanged.Raise(new TimeChangedEventArgs(was, now)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_TimeOfDayChanged.Raise(new EventArgsIntChanged(was, now)); +#endif } else this.Watchers.TimeWatcher.Reset(); @@ -730,7 +772,9 @@ namespace StardewModdingAPI.Framework GameLocation oldLocation = playerTracker.LocationWatcher.PreviousValue; this.Events.Warped.Raise(new WarpedEventArgs(playerTracker.Player, oldLocation, newLocation)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_PlayerWarped.Raise(new EventArgsPlayerWarped(oldLocation, newLocation)); +#endif } // raise player leveled up a skill @@ -740,7 +784,9 @@ namespace StardewModdingAPI.Framework this.Monitor.Log($"Events: player skill '{pair.Key}' changed from {pair.Value.PreviousValue} to {pair.Value.CurrentValue}.", LogLevel.Trace); this.Events.LevelChanged.Raise(new LevelChangedEventArgs(playerTracker.Player, pair.Key, pair.Value.PreviousValue, pair.Value.CurrentValue)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_LeveledUp.Raise(new EventArgsLevelUp((EventArgsLevelUp.LevelType)pair.Key, pair.Value.CurrentValue)); +#endif } // raise player inventory changed @@ -750,7 +796,9 @@ namespace StardewModdingAPI.Framework if (this.Monitor.IsVerbose) this.Monitor.Log("Events: player inventory changed.", LogLevel.Trace); this.Events.InventoryChanged.Raise(new InventoryChangedEventArgs(playerTracker.Player, changedItems)); +#if !SMAPI_3_0_STRICT this.Events.Legacy_InventoryChanged.Raise(new EventArgsInventoryChanged(Game1.player.Items, changedItems)); +#endif } // raise mine level changed @@ -758,7 +806,9 @@ namespace StardewModdingAPI.Framework { if (this.Monitor.IsVerbose) this.Monitor.Log($"Context: mine level changed to {mineLevel}.", LogLevel.Trace); +#if !SMAPI_3_0_STRICT this.Events.Legacy_MineLevelChanged.Raise(new EventArgsMineLevelChanged(playerTracker.MineLevelWatcher.PreviousValue, mineLevel)); +#endif } } this.Watchers.CurrentPlayerTracker?.Reset(); @@ -790,6 +840,7 @@ namespace StardewModdingAPI.Framework /********* ** Update events *********/ +#if !SMAPI_3_0_STRICT this.Events.Legacy_UnvalidatedUpdateTick.Raise(); if (this.TicksElapsed == 1) this.Events.Legacy_FirstUpdateTick.Raise(); @@ -806,6 +857,7 @@ namespace StardewModdingAPI.Framework this.Events.Legacy_HalfSecondTick.Raise(); if (this.CurrentUpdateTick % 60 == 0) this.Events.Legacy_OneSecondTick.Raise(); +#endif this.CurrentUpdateTick += 1; if (this.CurrentUpdateTick >= 60) this.CurrentUpdateTick = 0; @@ -895,10 +947,14 @@ namespace StardewModdingAPI.Framework try { this.Events.RenderingActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPreRenderGuiEvent.Raise(); +#endif activeClickableMenu.draw(Game1.spriteBatch); this.Events.RenderedActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderGuiEvent.Raise(); +#endif } catch (Exception ex) { @@ -906,7 +962,9 @@ namespace StardewModdingAPI.Framework activeClickableMenu.exitThisMenu(); } this.Events.Rendered.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderEvent.Raise(); +#endif Game1.spriteBatch.End(); } @@ -930,10 +988,14 @@ namespace StardewModdingAPI.Framework { Game1.activeClickableMenu.drawBackground(Game1.spriteBatch); this.Events.RenderingActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPreRenderGuiEvent.Raise(); +#endif Game1.activeClickableMenu.draw(Game1.spriteBatch); this.Events.RenderedActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderGuiEvent.Raise(); +#endif } catch (Exception ex) { @@ -941,7 +1003,9 @@ namespace StardewModdingAPI.Framework Game1.activeClickableMenu.exitThisMenu(); } this.Events.Rendered.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderEvent.Raise(); +#endif Game1.spriteBatch.End(); this.drawOverlays(Game1.spriteBatch); if ((double)Game1.options.zoomLevel != 1.0) @@ -966,7 +1030,9 @@ 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); this.Events.Rendered.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderEvent.Raise(); +#endif Game1.spriteBatch.End(); } else if (Game1.currentMinigame != null) @@ -979,7 +1045,9 @@ 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); @@ -997,10 +1065,14 @@ namespace StardewModdingAPI.Framework try { this.Events.RenderingActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPreRenderGuiEvent.Raise(); +#endif Game1.activeClickableMenu.draw(Game1.spriteBatch); this.Events.RenderedActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderGuiEvent.Raise(); +#endif } catch (Exception ex) { @@ -1090,7 +1162,9 @@ namespace StardewModdingAPI.Framework if (++batchOpens == 1) this.Events.Rendering.RaiseEmpty(); this.Events.RenderingWorld.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPreRenderEvent.Raise(); +#endif if (Game1.background != null) Game1.background.draw(Game1.spriteBatch); Game1.mapDisplayDevice.BeginScene(Game1.spriteBatch); @@ -1403,10 +1477,14 @@ namespace StardewModdingAPI.Framework if ((Game1.displayHUD || Game1.eventUp) && (Game1.currentBillboard == 0 && Game1.gameMode == (byte)3) && (!Game1.freezeControls && !Game1.panMode && !Game1.HostPaused)) { this.Events.RenderingHud.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPreRenderHudEvent.Raise(); +#endif this.drawHUD(); this.Events.RenderedHud.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.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); @@ -1515,10 +1593,14 @@ namespace StardewModdingAPI.Framework try { this.Events.RenderingActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPreRenderGuiEvent.Raise(); +#endif Game1.activeClickableMenu.draw(Game1.spriteBatch); this.Events.RenderedActiveMenu.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderGuiEvent.Raise(); +#endif } catch (Exception ex) { @@ -1535,7 +1617,9 @@ namespace StardewModdingAPI.Framework } this.Events.Rendered.RaiseEmpty(); +#if !SMAPI_3_0_STRICT this.Events.Legacy_OnPostRenderEvent.Raise(); +#endif Game1.spriteBatch.End(); this.drawOverlays(Game1.spriteBatch); this.renderScreenBuffer(); @@ -1555,6 +1639,7 @@ namespace StardewModdingAPI.Framework this.RaisedAfterLoadEvent = false; } +#if !SMAPI_3_0_STRICT /// Raise the if there are any listeners. /// Whether to create a new sprite batch. private void RaisePostRender(bool needsNewBatch = false) @@ -1568,5 +1653,6 @@ namespace StardewModdingAPI.Framework Game1.spriteBatch.End(); } } +#endif } } diff --git a/src/SMAPI/Framework/SMultiplayer.cs b/src/SMAPI/Framework/SMultiplayer.cs index 629fce1d..12cd2d46 100644 --- a/src/SMAPI/Framework/SMultiplayer.cs +++ b/src/SMAPI/Framework/SMultiplayer.cs @@ -82,6 +82,7 @@ namespace StardewModdingAPI.Framework this.OnModMessageReceived = onModMessageReceived; } +#if !SMAPI_3_0_STRICT /// Handle sync messages from other players and perform other initial sync logic. public override void UpdateEarly() { @@ -97,6 +98,7 @@ namespace StardewModdingAPI.Framework base.UpdateLate(forceSync); this.EventManager.Legacy_AfterMainBroadcast.Raise(); } +#endif /// Initialise a client before the game connects to a remote server. /// The client to initialise. diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs index 7e82e0d0..678339dc 100644 --- a/src/SMAPI/IModHelper.cs +++ b/src/SMAPI/IModHelper.cs @@ -56,6 +56,7 @@ namespace StardewModdingAPI /// The config settings to save. void WriteConfig(TConfig config) where TConfig : class, new(); +#if !SMAPI_3_0_STRICT /**** ** Generic JSON files ****/ @@ -88,5 +89,6 @@ namespace StardewModdingAPI /// Get all content packs loaded for this mod. IEnumerable GetContentPacks(); +#endif } } diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index ff8d54e3..c4ddf807 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -52,7 +52,10 @@ namespace StardewModdingAPI.Metadata new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.serializer), InstructionHandleResult.DetectedSaveSerialiser), new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.farmerSerializer), InstructionHandleResult.DetectedSaveSerialiser), new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.locationSerializer), InstructionHandleResult.DetectedSaveSerialiser), + new TypeFinder(typeof(ISpecialisedEvents).FullName, InstructionHandleResult.DetectedUnvalidatedUpdateTick), +#if !SMAPI_3_0_STRICT new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick), +#endif /**** ** detect paranoid issues diff --git a/src/SMAPI/SemanticVersion.cs b/src/SMAPI/SemanticVersion.cs index 401f62c2..f75105df 100644 --- a/src/SMAPI/SemanticVersion.cs +++ b/src/SMAPI/SemanticVersion.cs @@ -29,6 +29,7 @@ namespace StardewModdingAPI /// The patch version for backwards-compatible bug fixes. public int PatchVersion => this.Version.PatchVersion; +#if !SMAPI_3_0_STRICT /// An optional build tag. [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")] public string Build @@ -39,6 +40,7 @@ namespace StardewModdingAPI return this.Version.PrereleaseTag; } } +#endif /// An optional prerelease tag. public string PrereleaseTag => this.Version.PrereleaseTag; diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 5a098b8a..3696b54d 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -32,7 +32,7 @@ x86 false - DEBUG;TRACE + DEBUG;TRACE;SMAPI_3_0_STRICT true false $(SolutionDir)\..\bin\Debug\SMAPI diff --git a/src/StardewModdingAPI.Toolkit.CoreInterfaces/ISemanticVersion.cs b/src/StardewModdingAPI.Toolkit.CoreInterfaces/ISemanticVersion.cs index 6631b01d..0a6e5758 100644 --- a/src/StardewModdingAPI.Toolkit.CoreInterfaces/ISemanticVersion.cs +++ b/src/StardewModdingAPI.Toolkit.CoreInterfaces/ISemanticVersion.cs @@ -17,9 +17,11 @@ namespace StardewModdingAPI /// The patch version for backwards-compatible bug fixes. int PatchVersion { get; } +#if !SMAPI_3_0_STRICT /// An optional build tag. [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")] string Build { get; } +#endif /// An optional prerelease tag. string PrereleaseTag { get; } diff --git a/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj b/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj index 525931e5..539cb5d8 100644 --- a/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj +++ b/src/StardewModdingAPI.Toolkit.CoreInterfaces/StardewModdingAPI.Toolkit.CoreInterfaces.csproj @@ -8,6 +8,10 @@ ..\..\bin\$(Configuration)\SMAPI.Toolkit.CoreInterfaces\$(TargetFramework)\StardewModdingAPI.Toolkit.CoreInterfaces.xml + + $(DefineConstants);SMAPI_3_0_STRICT + + diff --git a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs index a7990d13..2d0bc033 100644 --- a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs +++ b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs @@ -39,9 +39,11 @@ namespace StardewModdingAPI.Toolkit /// The patch version for backwards-compatible bug fixes. public int PatchVersion { get; } +#if !SMAPI_3_0_STRICT /// An optional prerelease tag. [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")] public string Build => this.PrereleaseTag; +#endif /// An optional prerelease tag. public string PrereleaseTag { get; } @@ -114,7 +116,7 @@ namespace StardewModdingAPI.Toolkit { if (other == null) throw new ArgumentNullException(nameof(other)); - return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.Build); + return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.PrereleaseTag); } /// Indicates whether the current object is equal to another object of the same type. @@ -128,7 +130,7 @@ namespace StardewModdingAPI.Toolkit /// Whether this is a pre-release version. public bool IsPrerelease() { - return !string.IsNullOrWhiteSpace(this.Build); + return !string.IsNullOrWhiteSpace(this.PrereleaseTag); } /// Get whether this version is older than the specified version. @@ -187,7 +189,7 @@ namespace StardewModdingAPI.Toolkit : $"{this.MajorVersion}.{this.MinorVersion}"; // tag - string tag = this.Build; + string tag = this.PrereleaseTag; if (tag != null) result += $"-{tag}"; return result; @@ -241,11 +243,11 @@ namespace StardewModdingAPI.Toolkit return this.MinorVersion.CompareTo(otherMinor); if (this.PatchVersion != otherPatch) return this.PatchVersion.CompareTo(otherPatch); - if (this.Build == otherTag) + if (this.PrereleaseTag == otherTag) return same; // stable supercedes pre-release - bool curIsStable = string.IsNullOrWhiteSpace(this.Build); + bool curIsStable = string.IsNullOrWhiteSpace(this.PrereleaseTag); bool otherIsStable = string.IsNullOrWhiteSpace(otherTag); if (curIsStable) return curNewer; @@ -253,7 +255,7 @@ namespace StardewModdingAPI.Toolkit return curOlder; // compare two pre-release tag values - string[] curParts = this.Build.Split('.', '-'); + string[] curParts = this.PrereleaseTag.Split('.', '-'); string[] otherParts = otherTag.Split('.', '-'); for (int i = 0; i < curParts.Length; i++) { @@ -292,11 +294,11 @@ namespace StardewModdingAPI.Toolkit throw new FormatException($"{this} isn't a valid semantic version. The major, minor, and patch numbers can't be negative."); if (this.MajorVersion == 0 && this.MinorVersion == 0 && this.PatchVersion == 0) throw new FormatException($"{this} isn't a valid semantic version. At least one of the major, minor, and patch numbers must be more than zero."); - if (this.Build != null) + if (this.PrereleaseTag != null) { - if (this.Build.Trim() == "") + if (this.PrereleaseTag.Trim() == "") throw new FormatException($"{this} isn't a valid semantic version. The tag cannot be a blank string (but may be omitted)."); - if (!Regex.IsMatch(this.Build, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase)) + if (!Regex.IsMatch(this.PrereleaseTag, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase)) throw new FormatException($"{this} isn't a valid semantic version. The tag is invalid."); } } diff --git a/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj b/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj index 3fa28d19..29667b1e 100644 --- a/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj +++ b/src/StardewModdingAPI.Toolkit/StardewModdingAPI.Toolkit.csproj @@ -7,6 +7,10 @@ ..\..\bin\$(Configuration)\SMAPI.Toolkit\$(TargetFramework)\StardewModdingAPI.Toolkit.xml + + $(DefineConstants);SMAPI_3_0_STRICT + + -- cgit From efa7372a20146bf7b865a9bbe6750531da27a162 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 3 Dec 2018 02:47:27 -0500 Subject: fix build error in non-strict mode (#606) --- src/SMAPI/Framework/SGame.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index d15c5c3e..9ad8d188 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -9,6 +9,9 @@ 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; -- cgit From 06257a510f96db331855681c98d42af035fda018 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 4 Dec 2018 20:00:29 -0500 Subject: update version parsing code (#606) --- src/SMAPI/Framework/SCore.cs | 2 ++ src/StardewModdingAPI.Toolkit/SemanticVersion.cs | 20 +++++++++++------- .../Converters/SemanticVersionConverter.cs | 24 +++++++++++++++------- 3 files changed, 32 insertions(+), 14 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index eff7cb3b..5fb2dc61 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -902,11 +902,13 @@ 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) this.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice); } +#endif // validate dependencies // Although dependences are validated before mods are loaded, a dependency may have failed to load. diff --git a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs index 2d0bc033..19da0a76 100644 --- a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs +++ b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs @@ -39,17 +39,17 @@ namespace StardewModdingAPI.Toolkit /// The patch version for backwards-compatible bug fixes. public int PatchVersion { get; } + /// An optional prerelease tag. + public string PrereleaseTag { get; } + #if !SMAPI_3_0_STRICT /// An optional prerelease tag. [Obsolete("Use " + nameof(ISemanticVersion.PrereleaseTag) + " instead")] public string Build => this.PrereleaseTag; -#endif - - /// An optional prerelease tag. - public string PrereleaseTag { get; } /// Whether the version was parsed from the legacy object format. public bool IsLegacyFormat { get; } +#endif /********* @@ -59,15 +59,21 @@ namespace StardewModdingAPI.Toolkit /// The major version incremented for major API changes. /// The minor version incremented for backwards-compatible changes. /// The patch version for backwards-compatible fixes. - /// An optional prerelease tag. + /// An optional prerelease tag. /// Whether the version was parsed from the legacy object format. - public SemanticVersion(int major, int minor, int patch, string tag = null, bool isLegacyFormat = false) + public SemanticVersion(int major, int minor, int patch, string prereleaseTag = null +#if !SMAPI_3_0_STRICT + , bool isLegacyFormat = false +#endif + ) { this.MajorVersion = major; this.MinorVersion = minor; this.PatchVersion = patch; - this.PrereleaseTag = this.GetNormalisedTag(tag); + this.PrereleaseTag = this.GetNormalisedTag(prereleaseTag); +#if !SMAPI_3_0_STRICT this.IsLegacyFormat = isLegacyFormat; +#endif this.AssertValid(); } diff --git a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs b/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs index e0e185c9..aca06849 100644 --- a/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs +++ b/src/StardewModdingAPI.Toolkit/Serialisation/Converters/SemanticVersionConverter.cs @@ -63,14 +63,24 @@ namespace StardewModdingAPI.Toolkit.Serialisation.Converters /// The JSON object to read. private ISemanticVersion ReadObject(JObject obj) { - int major = obj.ValueIgnoreCase("MajorVersion"); - int minor = obj.ValueIgnoreCase("MinorVersion"); - int patch = obj.ValueIgnoreCase("PatchVersion"); - string build = obj.ValueIgnoreCase("Build"); - if (build == "0") - build = null; // '0' from incorrect examples in old SMAPI documentation + int major = obj.ValueIgnoreCase(nameof(ISemanticVersion.MajorVersion)); + int minor = obj.ValueIgnoreCase(nameof(ISemanticVersion.MinorVersion)); + int patch = obj.ValueIgnoreCase(nameof(ISemanticVersion.PatchVersion)); + string prereleaseTag = obj.ValueIgnoreCase(nameof(ISemanticVersion.PrereleaseTag)); +#if !SMAPI_3_0_STRICT + if (string.IsNullOrWhiteSpace(prereleaseTag)) + { + prereleaseTag = obj.ValueIgnoreCase("Build"); + if (prereleaseTag == "0") + prereleaseTag = null; // '0' from incorrect examples in old SMAPI documentation + } +#endif - return new SemanticVersion(major, minor, patch, build, isLegacyFormat: true); + return new SemanticVersion(major, minor, patch, prereleaseTag +#if !SMAPI_3_0_STRICT + , isLegacyFormat: true +#endif + ); } /// Read a JSON string. -- cgit From dad67e213e68eb85c534d7c1c4035dfde90ff822 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 4 Dec 2018 23:16:13 -0500 Subject: fix world events in the mines (#603) --- .../FieldWatchers/ComparableListWatcher.cs | 82 ++++++++++++++++++++++ .../StateTracking/FieldWatchers/WatcherFactory.cs | 8 +++ .../StateTracking/WorldLocationsTracker.cs | 50 +++++++++---- src/SMAPI/Framework/WatcherCore.cs | 3 +- src/SMAPI/StardewModdingAPI.csproj | 1 + 5 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs new file mode 100644 index 00000000..95e9ef16 --- /dev/null +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs @@ -0,0 +1,82 @@ +using System.Collections.Generic; +using System.Linq; + +namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers +{ + /// A watcher which detects changes to a collection of values using a specified instance. + internal class ComparableListWatcher : BaseDisposableWatcher, ICollectionWatcher + { + /********* + ** Properties + *********/ + /// The collection to watch. + private readonly ICollection CurrentValues; + + /// The values during the previous update. + private HashSet LastValues; + + /// The pairs added since the last reset. + private readonly List AddedImpl = new List(); + + /// The pairs demoved since the last reset. + private readonly List RemovedImpl = new List(); + + + /********* + ** Accessors + *********/ + /// Whether the value changed since the last reset. + public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; + + /// The values added since the last reset. + public IEnumerable Added => this.AddedImpl; + + /// The values removed since the last reset. + public IEnumerable Removed => this.RemovedImpl; + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The collection to watch. + /// The equality comparer which indicates whether two values are the same. + public ComparableListWatcher(ICollection values, IEqualityComparer comparer) + { + this.CurrentValues = values; + this.LastValues = new HashSet(comparer); + } + + /// Update the current value if needed. + public void Update() + { + this.AssertNotDisposed(); + + // optimise for zero items + if (this.CurrentValues.Count == 0) + { + if (this.LastValues.Count > 0) + { + this.AddedImpl.AddRange(this.LastValues); + this.LastValues.Clear(); + } + return; + } + + // detect changes + HashSet curValues = new HashSet(this.CurrentValues, this.LastValues.Comparer); + this.RemovedImpl.AddRange(from value in this.LastValues where !curValues.Contains(value) select value); + this.AddedImpl.AddRange(from value in curValues where !this.LastValues.Contains(value) select value); + this.LastValues = curValues; + } + + /// Set the current value as the baseline. + public void Reset() + { + this.AssertNotDisposed(); + + this.AddedImpl.Clear(); + this.RemovedImpl.Clear(); + } + } +} diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs index ab4ab0d5..8301351e 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs @@ -36,6 +36,14 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers return new ComparableWatcher(getValue, new ObjectReferenceComparer()); } + /// Get a watcher which detects when an object reference in a collection changes. + /// The value type. + /// The observable collection. + public static ComparableListWatcher ForReferenceList(ICollection collection) + { + return new ComparableListWatcher(collection, new ObjectReferenceComparer()); + } + /// Get a watcher for an observable collection. /// The value type. /// The observable collection. diff --git a/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs b/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs index 5a259663..d9d598f8 100644 --- a/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs +++ b/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -19,6 +18,9 @@ namespace StardewModdingAPI.Framework.StateTracking /// Tracks changes to the location list. private readonly ICollectionWatcher LocationListWatcher; + /// Tracks changes to the list of active mine locations. + private readonly ICollectionWatcher MineLocationListWatcher; + /// A lookup of the tracked locations. private IDictionary LocationDict { get; } = new Dictionary(new ObjectReferenceComparer()); @@ -50,24 +52,34 @@ namespace StardewModdingAPI.Framework.StateTracking *********/ /// Construct an instance. /// The game's list of locations. - public WorldLocationsTracker(ObservableCollection locations) + /// The game's list of active mine locations. + public WorldLocationsTracker(ObservableCollection locations, IList activeMineLocations) { this.LocationListWatcher = WatcherFactory.ForObservableCollection(locations); + this.MineLocationListWatcher = WatcherFactory.ForReferenceList(activeMineLocations); } /// Update the current value if needed. public void Update() { - // detect location changes + // detect added/removed locations + this.LocationListWatcher.Update(); + this.MineLocationListWatcher.Update(); if (this.LocationListWatcher.IsChanged) { this.Remove(this.LocationListWatcher.Removed); this.Add(this.LocationListWatcher.Added); } + if (this.MineLocationListWatcher.IsChanged) + { + this.Remove(this.MineLocationListWatcher.Removed); + this.Add(this.MineLocationListWatcher.Added); + } - // detect building changes + // detect building changed foreach (LocationTracker watcher in this.Locations.ToArray()) { + watcher.Update(); if (watcher.BuildingsWatcher.IsChanged) { this.Remove(watcher.BuildingsWatcher.Removed); @@ -75,7 +87,7 @@ namespace StardewModdingAPI.Framework.StateTracking } } - // detect building interior changed (e.g. construction completed) + // detect building interiors changed (e.g. construction completed) foreach (KeyValuePair pair in this.BuildingIndoors.Where(p => !object.Equals(p.Key.indoors.Value, p.Value))) { GameLocation oldIndoors = pair.Value; @@ -86,10 +98,6 @@ namespace StardewModdingAPI.Framework.StateTracking if (newIndoors != null) this.Removed.Add(newIndoors); } - - // update watchers - foreach (IWatcher watcher in this.Locations) - watcher.Update(); } /// Set the current location list as the baseline. @@ -98,21 +106,21 @@ namespace StardewModdingAPI.Framework.StateTracking this.Removed.Clear(); this.Added.Clear(); this.LocationListWatcher.Reset(); + this.MineLocationListWatcher.Reset(); } /// Set the current value as the baseline. public void Reset() { this.ResetLocationList(); - foreach (IWatcher watcher in this.Locations) + foreach (IWatcher watcher in this.GetWatchers()) watcher.Reset(); } /// Stop watching the player fields and release all references. public void Dispose() { - this.LocationListWatcher.Dispose(); - foreach (IWatcher watcher in this.Locations) + foreach (IWatcher watcher in this.GetWatchers()) watcher.Dispose(); } @@ -180,11 +188,11 @@ namespace StardewModdingAPI.Framework.StateTracking // remove old location if needed this.Remove(location); - // track change + // add location this.Added.Add(location); - - // add this.LocationDict[location] = new LocationTracker(location); + + // add buildings if (location is BuildableGameLocation buildableLocation) this.Add(buildableLocation.buildings); } @@ -219,5 +227,17 @@ namespace StardewModdingAPI.Framework.StateTracking this.Remove(buildableLocation.buildings); } } + + /**** + ** Helpers + ****/ + /// The underlying watchers. + private IEnumerable GetWatchers() + { + yield return this.LocationListWatcher; + yield return this.MineLocationListWatcher; + foreach (LocationTracker watcher in this.Locations) + yield return watcher; + } } } diff --git a/src/SMAPI/Framework/WatcherCore.cs b/src/SMAPI/Framework/WatcherCore.cs index e06423b9..8d29cf18 100644 --- a/src/SMAPI/Framework/WatcherCore.cs +++ b/src/SMAPI/Framework/WatcherCore.cs @@ -5,6 +5,7 @@ using StardewModdingAPI.Framework.Input; using StardewModdingAPI.Framework.StateTracking; using StardewModdingAPI.Framework.StateTracking.FieldWatchers; using StardewValley; +using StardewValley.Locations; using StardewValley.Menus; namespace StardewModdingAPI.Framework @@ -64,7 +65,7 @@ namespace StardewModdingAPI.Framework this.WindowSizeWatcher = WatcherFactory.ForEquatable(() => new Point(Game1.viewport.Width, Game1.viewport.Height)); this.TimeWatcher = WatcherFactory.ForEquatable(() => Game1.timeOfDay); this.ActiveMenuWatcher = WatcherFactory.ForReference(() => Game1.activeClickableMenu); - this.LocationsWatcher = new WorldLocationsTracker((ObservableCollection)Game1.locations); + this.LocationsWatcher = new WorldLocationsTracker((ObservableCollection)Game1.locations, MineShaft.activeMines); this.LocaleWatcher = WatcherFactory.ForGenericEquality(() => LocalizedContentManager.CurrentLanguageCode); this.Watchers.AddRange(new IWatcher[] { diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 3696b54d..49a88f37 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -205,6 +205,7 @@ + -- cgit From 699fc41a7d72ec680c35ab36f3e18d54639d9b93 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 4 Dec 2018 23:31:39 -0500 Subject: cleanup, add release note --- docs/release-notes.md | 1 + .../Framework/Commands/World/SetTimeCommand.cs | 2 +- .../StateTracking/FieldWatchers/ComparableListWatcher.cs | 3 ++- .../StateTracking/FieldWatchers/ComparableWatcher.cs | 13 +++++++------ .../StateTracking/FieldWatchers/NetCollectionWatcher.cs | 3 ++- .../StateTracking/FieldWatchers/NetDictionaryWatcher.cs | 2 +- .../StateTracking/FieldWatchers/NetValueWatcher.cs | 14 ++++++++------ .../FieldWatchers/ObservableCollectionWatcher.cs | 3 ++- 8 files changed, 24 insertions(+), 17 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index 5788fa9f..d7cb6680 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -11,6 +11,7 @@ * Added `IsLocalPlayer` to new player events. * Reloading a map asset will now update affected locations. * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. + * Fixed world events (like `ObjectListChanged`) not working in the mines. * Fixed some map tilesheets not editable if not playing in English. * Fixed newlines in most manifest fields not being ignored. * Fixed `Display.RenderedWorld` event not invoked before overlays are rendered. diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs index 7644ee46..a6075013 100644 --- a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs @@ -47,7 +47,7 @@ namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World { // define conversion between game time and TimeSpan TimeSpan ToTimeSpan(int value) => new TimeSpan(0, value / 100, value % 100, 0); - int FromTimeSpan(TimeSpan span) => (int)((span.Hours * 100) + span.Minutes); + int FromTimeSpan(TimeSpan span) => (span.Hours * 100) + span.Minutes; // transition to new time int intervals = (int)((ToTimeSpan(time) - ToTimeSpan(Game1.timeOfDay)).TotalMinutes / 10); diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs index 95e9ef16..2ea6609a 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs @@ -4,6 +4,7 @@ using System.Linq; namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers { /// A watcher which detects changes to a collection of values using a specified instance. + /// The value type within the collection. internal class ComparableListWatcher : BaseDisposableWatcher, ICollectionWatcher { /********* @@ -18,7 +19,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// The pairs added since the last reset. private readonly List AddedImpl = new List(); - /// The pairs demoved since the last reset. + /// The pairs removed since the last reset. private readonly List RemovedImpl = new List(); diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs index d51fc2ac..dda30a15 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs @@ -4,26 +4,27 @@ using System.Collections.Generic; namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers { /// A watcher which detects changes to a value using a specified instance. - internal class ComparableWatcher : IValueWatcher + /// The comparable value type. + internal class ComparableWatcher : IValueWatcher { /********* ** Properties *********/ /// Get the current value. - private readonly Func GetValue; + private readonly Func GetValue; /// The equality comparer. - private readonly IEqualityComparer Comparer; + private readonly IEqualityComparer Comparer; /********* ** Accessors *********/ /// The field value at the last reset. - public T PreviousValue { get; private set; } + public TValue PreviousValue { get; private set; } /// The latest value. - public T CurrentValue { get; private set; } + public TValue CurrentValue { get; private set; } /// Whether the value changed since the last reset. public bool IsChanged { get; private set; } @@ -35,7 +36,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// Construct an instance. /// Get the current value. /// The equality comparer which indicates whether two values are the same. - public ComparableWatcher(Func getValue, IEqualityComparer comparer) + public ComparableWatcher(Func getValue, IEqualityComparer comparer) { this.GetValue = getValue; this.Comparer = comparer; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs index 8a841a79..d3022a69 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs @@ -4,6 +4,7 @@ using Netcode; namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers { /// A watcher which detects changes to a Netcode collection. + /// The value type within the collection. internal class NetCollectionWatcher : BaseDisposableWatcher, ICollectionWatcher where TValue : class, INetObject { @@ -16,7 +17,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// The pairs added since the last reset. private readonly List AddedImpl = new List(); - /// The pairs demoved since the last reset. + /// The pairs removed since the last reset. private readonly List RemovedImpl = new List(); diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs index 7a2bf84e..7a7ab89d 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs @@ -20,7 +20,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// The pairs added since the last reset. private readonly IDictionary PairsAdded = new Dictionary(); - /// The pairs demoved since the last reset. + /// The pairs removed since the last reset. private readonly IDictionary PairsRemoved = new Dictionary(); /// The field being watched. diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs index 188ed9f3..85099988 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs @@ -3,13 +3,15 @@ using Netcode; namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers { /// A watcher which detects changes to a net value field. - internal class NetValueWatcher : BaseDisposableWatcher, IValueWatcher where TSelf : NetFieldBase + /// The value type wrapped by the net field. + /// The net field type. + internal class NetValueWatcher : BaseDisposableWatcher, IValueWatcher where TNetField : NetFieldBase { /********* ** Properties *********/ /// The field being watched. - private readonly NetFieldBase Field; + private readonly NetFieldBase Field; /********* @@ -19,10 +21,10 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers public bool IsChanged { get; private set; } /// The field value at the last reset. - public T PreviousValue { get; private set; } + public TValue PreviousValue { get; private set; } /// The latest value. - public T CurrentValue { get; private set; } + public TValue CurrentValue { get; private set; } /********* @@ -30,7 +32,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers *********/ /// Construct an instance. /// The field to watch. - public NetValueWatcher(NetFieldBase field) + public NetValueWatcher(NetFieldBase field) { this.Field = field; this.PreviousValue = field.Value; @@ -74,7 +76,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// The field being watched. /// The old field value. /// The new field value. - private void OnValueChanged(TSelf field, T oldValue, T newValue) + private void OnValueChanged(TNetField field, TValue oldValue, TValue newValue) { this.CurrentValue = newValue; this.IsChanged = true; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs index 34a97097..0c65789f 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs @@ -6,6 +6,7 @@ using System.Linq; namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers { /// A watcher which detects changes to an observable collection. + /// The value type within the collection. internal class ObservableCollectionWatcher : BaseDisposableWatcher, ICollectionWatcher { /********* @@ -17,7 +18,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// The pairs added since the last reset. private readonly List AddedImpl = new List(); - /// The pairs demoved since the last reset. + /// The pairs removed since the last reset. private readonly List RemovedImpl = new List(); -- cgit From aba15074b3d3ab6f655c976f84e9a597d0115efd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 5 Dec 2018 00:18:13 -0500 Subject: add helper.CreateTemporaryContentPack to replace deprecated transitional method --- docs/release-notes.md | 1 + src/SMAPI/Framework/ModHelpers/ModHelper.cs | 34 ++++++++++++++++++++++------- src/SMAPI/IModHelper.cs | 13 ++++++++++- 3 files changed, 39 insertions(+), 9 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index d7cb6680..6ac4e90b 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -9,6 +9,7 @@ * For modders: * Added ModDrop update keys (see [docs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Manifest#Update_checks)). * Added `IsLocalPlayer` to new player events. + * Added `helper.CreateTemporaryContentPack` to support permanent use cases for mods using the deprecated `helper.CreateTransitionalContentPack`. * Reloading a map asset will now update affected locations. * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. * Fixed world events (like `ObjectListChanged`) not working in the mines. diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs index cd7ac8ea..070d9c65 100644 --- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs @@ -21,8 +21,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /// Create a transitional content pack. private readonly Func CreateContentPack; +#if !SMAPI_3_0_STRICT /// Manages deprecation warnings. private readonly DeprecationManager DeprecationManager; +#endif /********* @@ -31,8 +33,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The full path to the mod's folder. public string DirectoryPath { get; } +#if !SMAPI_3_0_STRICT /// Encapsulates SMAPI's JSON file parsing. private readonly JsonHelper JsonHelper; +#endif /// Manages access to events raised by SMAPI, which let your mod react when something happens in the game. public IModEvents Events { get; } @@ -94,7 +98,6 @@ namespace StardewModdingAPI.Framework.ModHelpers // initialise this.DirectoryPath = modDirectory; - this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); this.Content = contentHelper ?? throw new ArgumentNullException(nameof(contentHelper)); this.Data = dataHelper ?? throw new ArgumentNullException(nameof(dataHelper)); this.Input = new InputHelper(modID, inputState); @@ -105,8 +108,11 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper)); this.ContentPacks = new Lazy(contentPacks); this.CreateContentPack = createContentPack; - this.DeprecationManager = deprecationManager; this.Events = events; +#if !SMAPI_3_0_STRICT + this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper)); + this.DeprecationManager = deprecationManager; +#endif } /**** @@ -160,23 +166,20 @@ namespace StardewModdingAPI.Framework.ModHelpers path = Path.Combine(this.DirectoryPath, PathUtilities.NormalisePathSeparators(path)); this.JsonHelper.WriteJsonFile(path, model); } +#endif /**** ** Content packs ****/ - /// 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. + /// Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. /// The absolute directory path containing the content pack files. /// The content pack's unique ID. /// The content pack name. /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("This method supports mods which previously had their own content packs, and shouldn't be used by new mods. It will be removed in SMAPI 3.0.")] - public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + public IContentPack CreateTemporaryContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) { - // raise deprecation notice - this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); - // validate if (string.IsNullOrWhiteSpace(directoryPath)) throw new ArgumentNullException(nameof(directoryPath)); @@ -200,6 +203,21 @@ namespace StardewModdingAPI.Framework.ModHelpers // create content pack return this.CreateContentPack(directoryPath, manifest); } + +#if !SMAPI_3_0_STRICT + /// 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. + /// The absolute directory path containing the content pack files. + /// The content pack's unique ID. + /// The content pack name. + /// The content pack description. + /// The content pack author's name. + /// The content pack version. + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")] + public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version) + { + this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice); + return this.CreateTemporaryContentPack(directoryPath, id, name, description, author, version); + } #endif /// Get all content packs loaded for this mod. diff --git a/src/SMAPI/IModHelper.cs b/src/SMAPI/IModHelper.cs index b7d06f56..fbe3d51f 100644 --- a/src/SMAPI/IModHelper.cs +++ b/src/SMAPI/IModHelper.cs @@ -73,10 +73,21 @@ namespace StardewModdingAPI /// The model to save. [Obsolete("Use " + nameof(IModHelper.Data) + "." + nameof(IDataHelper.WriteJsonFile) + " instead")] void WriteJsonFile(string path, TModel model) where TModel : class; +#endif /**** ** Content packs ****/ + /// Create a temporary content pack to read files from a directory. Temporary content packs will not appear in the SMAPI log and update checks will not be performed. + /// The absolute directory path containing the content pack files. + /// The content pack's unique ID. + /// The content pack name. + /// The content pack description. + /// The content pack author's name. + /// The content pack version. + IContentPack CreateTemporaryContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); + +#if !SMAPI_3_0_STRICT /// 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. /// The absolute directory path containing the content pack files. /// The content pack's unique ID. @@ -84,7 +95,7 @@ namespace StardewModdingAPI /// The content pack description. /// The content pack author's name. /// The content pack version. - [Obsolete("This method supports mods which previously had their own content packs, and shouldn't be used by new mods. It will be removed in SMAPI 3.0.")] + [Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.CreateTemporaryContentPack) + " instead")] IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version); #endif -- cgit From 0a009d6fdaaac65dcac4c43fc51342dbf0d1c577 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 5 Dec 2018 22:49:49 -0500 Subject: add friendly error when Steam isn't loaded --- docs/release-notes.md | 1 + src/SMAPI/Framework/SCore.cs | 31 ++++++++++++++++++++++++++++--- src/SMAPI/Framework/SGame.cs | 6 +++--- 3 files changed, 32 insertions(+), 6 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index 6ac4e90b..5ac702b1 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,7 @@ ## Upcoming * For players: * Added support for ModDrop in update checks and the mod compatibility list. + * Added friendly error when Steam isn't loaded (for Steam players). * Fixed cryptic error when running the installer from inside a zip file on Windows. * Fixed error when leaving and rejoining a multiplayer server in the same session. * Fixed Console Commands' handling of tool upgrade levels for item commands. diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 5fb2dc61..d4dffea5 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -99,6 +99,20 @@ namespace StardewModdingAPI.Framework new Regex(@"^static SerializableDictionary<.+>\(\) called\.$", RegexOptions.Compiled | RegexOptions.CultureInvariant), }; + /// Regex patterns which match console messages to show a more friendly error for. + private readonly Tuple[] ReplaceConsolePatterns = + { + Tuple.Create( + new Regex(@"^System\.InvalidOperationException: Steamworks is not initialized\.", RegexOptions.Compiled | RegexOptions.CultureInvariant), +#if SMAPI_FOR_WINDOWS + "Oops! Steam achievements won't work because Steam isn't loaded. You can launch the game through Steam to fix that (see 'Part 2: Configure Steam' in the install guide for more info: https://smapi.io/install).", +#else + "Oops! Steam achievements won't work because Steam isn't loaded. You can launch the game through Steam to fix that.", +#endif + LogLevel.Error + ) + }; + /// The mod toolkit used for generic mod interactions. private readonly ModToolkit Toolkit = new ModToolkit(); @@ -1275,9 +1289,9 @@ namespace StardewModdingAPI.Framework } /// Redirect messages logged directly to the console to the given monitor. - /// The monitor with which to log messages. + /// The monitor with which to log messages as the game. /// The message to log. - private void HandleConsoleMessage(IMonitor monitor, string message) + private void HandleConsoleMessage(IMonitor gameMonitor, string message) { // detect exception LogLevel level = message.Contains("Exception") ? LogLevel.Error : LogLevel.Trace; @@ -1286,8 +1300,19 @@ namespace StardewModdingAPI.Framework if (level != LogLevel.Error && this.SuppressConsolePatterns.Any(p => p.IsMatch(message))) return; + // show friendly error if applicable + foreach (var entry in this.ReplaceConsolePatterns) + { + if (entry.Item1.IsMatch(message)) + { + this.Monitor.Log(entry.Item2, entry.Item3); + gameMonitor.Log(message, LogLevel.Trace); + return; + } + } + // forward to monitor - monitor.Log(message, level); + gameMonitor.Log(message, level); } /// Show a 'press any key to exit' message, and exit when they press a key. diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 9ad8d188..7b3335b7 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -31,7 +31,7 @@ using StardewValley.TerrainFeatures; using StardewValley.Tools; using xTile.Dimensions; using xTile.Layers; -using Object = StardewValley.Object; +using SObject = StardewValley.Object; namespace StardewModdingAPI.Framework { @@ -718,8 +718,8 @@ namespace StardewModdingAPI.Framework if (watcher.ObjectsWatcher.IsChanged) { GameLocation location = watcher.Location; - KeyValuePair[] added = watcher.ObjectsWatcher.Added.ToArray(); - KeyValuePair[] removed = watcher.ObjectsWatcher.Removed.ToArray(); + KeyValuePair[] added = watcher.ObjectsWatcher.Added.ToArray(); + KeyValuePair[] removed = watcher.ObjectsWatcher.Removed.ToArray(); watcher.ObjectsWatcher.Reset(); this.Events.ObjectListChanged.Raise(new ObjectListChangedEventArgs(location, added, removed)); -- cgit From 05778734a21ce2a9f454ab71a455d44c9e940883 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 6 Dec 2018 17:48:27 -0500 Subject: move mod path into constants --- src/SMAPI/Constants.cs | 5 ++++- src/SMAPI/Framework/SCore.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index b71c6195..8667b63f 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -91,9 +91,12 @@ namespace StardewModdingAPI /// The file path which stores the detected update version for the next run. internal static string UpdateMarker => Path.Combine(Constants.InternalFilesPath, "StardewModdingAPI.update.marker"); - /// The full path to the folder containing mods. + /// The default full path to search for mods. internal static string DefaultModsPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods"); + /// The actual full path to search for mods. + internal static string ModsPath { get; set; } + /// The game's current semantic version. internal static ISemanticVersion GameVersion { get; } = new GameVersion(Constants.GetGameVersion()); diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index d4dffea5..53704bcf 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -117,7 +117,7 @@ namespace StardewModdingAPI.Framework private readonly ModToolkit Toolkit = new ModToolkit(); /// The path to search for mods. - private readonly string ModsPath; + private string ModsPath => Constants.ModsPath; /********* @@ -131,7 +131,7 @@ namespace StardewModdingAPI.Framework // init paths this.VerifyPath(modsPath); this.VerifyPath(Constants.LogDir); - this.ModsPath = modsPath; + Constants.ModsPath = modsPath; // init log file this.PurgeNormalLogs(); -- cgit From 2b97b9f701452bbcdc7bfb5c433b9906c595b195 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 6 Dec 2018 18:27:44 -0500 Subject: disable paranoid detection if paranoid warnings are disabled --- docs/release-notes.md | 2 + src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 9 ++- src/SMAPI/Framework/SCore.cs | 2 +- src/SMAPI/Metadata/InstructionMetadata.cs | 79 ++++++++++++------------ 4 files changed, 50 insertions(+), 42 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index 5ac702b1..cb9d0392 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -6,6 +6,7 @@ * Fixed cryptic error when running the installer from inside a zip file on Windows. * Fixed error when leaving and rejoining a multiplayer server in the same session. * Fixed Console Commands' handling of tool upgrade levels for item commands. + * Fixed empty "mods with warnings" list in some cases due to hidden warnings. * For modders: * Added ModDrop update keys (see [docs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Manifest#Update_checks)). @@ -13,6 +14,7 @@ * Added `helper.CreateTemporaryContentPack` to support permanent use cases for mods using the deprecated `helper.CreateTransitionalContentPack`. * Reloading a map asset will now update affected locations. * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. + * Disabled `TRACE` messages related to paranoid mode when it's disabled. * Fixed world events (like `ObjectListChanged`) not working in the mines. * Fixed some map tilesheets not editable if not playing in English. * Fixed newlines in most manifest fields not being ignored. diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index fdbfdd8d..7292cf3f 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -20,6 +20,9 @@ namespace StardewModdingAPI.Framework.ModLoading /// Encapsulates monitoring and logging. private readonly IMonitor Monitor; + /// Whether to detect paranoid mode issues. + private readonly bool ParanoidMode; + /// Metadata for mapping assemblies to the current platform. private readonly PlatformAssemblyMap AssemblyMap; @@ -39,9 +42,11 @@ namespace StardewModdingAPI.Framework.ModLoading /// Construct an instance. /// The current game platform. /// Encapsulates monitoring and logging. - public AssemblyLoader(Platform targetPlatform, IMonitor monitor) + /// Whether to detect paranoid mode issues. + public AssemblyLoader(Platform targetPlatform, IMonitor monitor, bool paranoidMode) { this.Monitor = monitor; + this.ParanoidMode = paranoidMode; this.AssemblyMap = this.TrackForDisposal(Constants.GetAssemblyMap(targetPlatform)); this.AssemblyDefinitionResolver = this.TrackForDisposal(new AssemblyDefinitionResolver()); this.AssemblyDefinitionResolver.AddSearchDirectory(Constants.ExecutionPath); @@ -275,7 +280,7 @@ namespace StardewModdingAPI.Framework.ModLoading // find (and optionally rewrite) incompatible instructions bool anyRewritten = false; - IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers().ToArray(); + IInstructionHandler[] handlers = new InstructionMetadata().GetHandlers(this.ParanoidMode).ToArray(); foreach (MethodDefinition method in this.GetMethods(module)) { // check method definition diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 53704bcf..800b9c09 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -726,7 +726,7 @@ namespace StardewModdingAPI.Framework // load mods IDictionary> skippedMods = new Dictionary>(); - using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor)) + using (AssemblyLoader modAssemblyLoader = new AssemblyLoader(Constants.Platform, this.Monitor, this.Settings.ParanoidWarnings)) { // init HashSet suppressUpdateChecks = new HashSet(this.Settings.SuppressUpdateChecks, StringComparer.InvariantCultureIgnoreCase); diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index c4ddf807..7c840b2f 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -24,54 +24,55 @@ namespace StardewModdingAPI.Metadata ** Public methods *********/ /// Get rewriters which detect or fix incompatible CIL instructions in mod assemblies. - public IEnumerable GetHandlers() + /// Whether to detect paranoid mode issues. + public IEnumerable GetHandlers(bool paranoidMode) { - return new IInstructionHandler[] - { - /**** - ** rewrite CIL to fix incompatible code - ****/ - // rewrite for crossplatform compatibility - new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true), + /**** + ** rewrite CIL to fix incompatible code + ****/ + // rewrite for crossplatform compatibility + yield return new MethodParentRewriter(typeof(SpriteBatch), typeof(SpriteBatchMethods), onlyIfPlatformChanged: true); - // rewrite for Stardew Valley 1.3 - new StaticFieldToConstantRewriter(typeof(Game1), "tileSize", Game1.tileSize), + // rewrite for Stardew Valley 1.3 + yield return new StaticFieldToConstantRewriter(typeof(Game1), "tileSize", Game1.tileSize); - /**** - ** detect mod issues - ****/ - // detect broken code - new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies), - new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies), + /**** + ** detect mod issues + ****/ + // detect broken code + yield return new ReferenceToMissingMemberFinder(this.ValidateReferencesToAssemblies); + yield return new ReferenceToMemberWithUnexpectedTypeFinder(this.ValidateReferencesToAssemblies); - /**** - ** detect code which may impact game stability - ****/ - new TypeFinder("Harmony.HarmonyInstance", InstructionHandleResult.DetectedGamePatch), - new TypeFinder("System.Runtime.CompilerServices.CallSite", InstructionHandleResult.DetectedDynamic), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.serializer), InstructionHandleResult.DetectedSaveSerialiser), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.farmerSerializer), InstructionHandleResult.DetectedSaveSerialiser), - new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.locationSerializer), InstructionHandleResult.DetectedSaveSerialiser), - new TypeFinder(typeof(ISpecialisedEvents).FullName, InstructionHandleResult.DetectedUnvalidatedUpdateTick), + /**** + ** detect code which may impact game stability + ****/ + yield return new TypeFinder("Harmony.HarmonyInstance", InstructionHandleResult.DetectedGamePatch); + yield return new TypeFinder("System.Runtime.CompilerServices.CallSite", InstructionHandleResult.DetectedDynamic); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.serializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.farmerSerializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new FieldFinder(typeof(SaveGame).FullName, nameof(SaveGame.locationSerializer), InstructionHandleResult.DetectedSaveSerialiser); + yield return new TypeFinder(typeof(ISpecialisedEvents).FullName, InstructionHandleResult.DetectedUnvalidatedUpdateTick); #if !SMAPI_3_0_STRICT - new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick), + yield return new EventFinder(typeof(SpecialisedEvents).FullName, nameof(SpecialisedEvents.UnvalidatedUpdateTick), InstructionHandleResult.DetectedUnvalidatedUpdateTick); #endif - - /**** - ** detect paranoid issues - ****/ + + /**** + ** detect paranoid issues + ****/ + if (paranoidMode) + { // filesystem access - new TypeFinder(typeof(System.IO.File).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileStream).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.Directory).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.DirectoryInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.DriveInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess), - new TypeFinder(typeof(System.IO.FileSystemWatcher).FullName, InstructionHandleResult.DetectedFilesystemAccess), + yield return new TypeFinder(typeof(System.IO.File).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileStream).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.Directory).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.DirectoryInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.DriveInfo).FullName, InstructionHandleResult.DetectedFilesystemAccess); + yield return new TypeFinder(typeof(System.IO.FileSystemWatcher).FullName, InstructionHandleResult.DetectedFilesystemAccess); // shell access - new TypeFinder(typeof(System.Diagnostics.Process).FullName, InstructionHandleResult.DetectedShellAccess) - }; + yield return new TypeFinder(typeof(System.Diagnostics.Process).FullName, InstructionHandleResult.DetectedShellAccess); + } } } } -- cgit