From 8d704153762fa73416a3ccb44ee71032952802eb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 26 Mar 2022 15:02:11 -0400 Subject: [PATCH] add deprecation notices for SMAPI 4.0.0 (#766) --- docs/release-notes.md | 37 ++++++++----------- src/SMAPI/Constants.cs | 17 ++++++++- src/SMAPI/Framework/Content/AssetInfo.cs | 23 +++++++++++- .../Framework/ModHelpers/ContentHelper.cs | 34 +++++++++++++++-- src/SMAPI/Framework/SCore.cs | 19 ++++++++++ src/SMAPI/IAssetInfo.cs | 1 + 6 files changed, 103 insertions(+), 28 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 98392c17..464049b9 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,37 +3,32 @@ # Release notes ## Upcoming release * For players: - * Improved translations. Thanks to ChulkyBow (updated Ukrainian)! - * Fixed `player_add` console command's handling of Journal Scraps and Secret Notes. - * Fixed `set_farm_type` console command not updating warps if they moved. - * Improved [command-line arguments](technical/smapi.md#command-line-arguments) on Linux/macOS: + * Fixed support for `_international` content assets (used in the movie theater). + * Fixed the warning text when a mod causes an asset load conflict with itself. + * Improved Linux/macOS [command-line arguments](technical/smapi.md#command-line-arguments): * Added `--use-current-shell` to avoid opening a separate terminal window. * Fixed `--no-terminal` still opening a terminal window, even if nothing is logged to it (thanks to Ryhon0!). - * Fixed warning text when a mod causes an asset load conflict with itself. - * Fixed support for `_international` content assets (used in the movie theater). + * Improved translations. Thanks to ChulkyBow (updated Ukrainian)! + +* For the Console Commands mod: + * Fixed `player_add` not handling journal scraps and secret notes correctly. + * Fixed `set_farm_type` not updating warps. * For mod authors: - * Added [content events](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Events#Content), which will replace `IAssetEditor` and `IAssetLoader` in SMAPI 4.0.0. - _These include new features not supported by the old API like load conflict resolution, edit priority, and content pack labels. They also support new cases like easily detecting when an asset has been changed._ - * Overhauled [mod-provided APIs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Integrations#Mod-provided_APIs) (thanks to Shockah!). - _This adds support for many previously-unsupported cases: proxied interfaces in return values or input arguments, proxied enums if their values match, generic methods, and more._ + * **Added [content events](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Events#Content), which will replace `IAssetEditor` and `IAssetLoader` in SMAPI 4.0.0.** + _These include new features not supported by the old API like load conflict resolution, edit priority, and content pack labels. They also support new cases like easily detecting when an asset has changed, and avoid data corruption issues in some edge cases._ + * **Overhauled [mod-provided API](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Integrations#Mod-provided_APIs) proxying** (thanks to Shockah!). + _This adds support for many previously unsupported cases: proxied interfaces in return values or input arguments, proxied enums if their values match, generic methods, and more. Existing mod APIs should work fine as-is._ + * **Deprecation warning:** The upcoming SMAPI 4.0 will remove deprecated APIs and break mods which haven't updated yet. + _See [_Migrate to SMAPI 4.0_](https://stardewvalleywiki.com/Modding:Migrate_to_SMAPI_4.0) for help updating your mod code. You can update your mod code now, there's no need to wait for the 4.0.0 release (which will happen in at least three months, and possibly later if needed to update open-source mods)._ * Added `Constants.ContentPath`. - * Added `IAssetName Name` field to the info received by `IAssetEditor` and `IAssetLoader` methods. + * Added `IAssetName` fields to the info received by `IAssetEditor` and `IAssetLoader` methods. _This adds methods for working with asset names, parsed locales, etc._ - * If an asset is loaded multiple times in the same tick, `IAssetLoader.CanLoad` and `IAssetEditor.CanEdit` are now cached unless invalidated via `helper.Content.InvalidateCache`. + * If an asset is loaded multiple times in the same tick, `IAssetLoader.CanLoad` and `IAssetEditor.CanEdit` are now cached unless invalidated by `helper.Content.InvalidateCache`. * Fixed the `SDate` constructor being case-sensitive. * Fixed support for using locale codes from custom languages in asset names (e.g. `Data/Achievements.eo-EU`). * Fixed issue where suppressing `[Left|Right]Thumbstick[Down|Left]` keys would suppress the opposite direction instead. -* **Deprecation warning for mod authors:** - These APIs are now deprecated and will be removed in the upcoming SMAPI 4.0.0. - - API | how to update code - :-- | :----------------- - `Constants.ExecutionPath` | Use `Constants.GamePath` instead. - `IAssetInfo.AssetName`
`IAssetData.AssetName` | Use `Name` instead, which changes the type from `string` to the new `AssetName`. - `IAssetInfo.AssetNameEquals`
`IAssetData.AssetNameEquals` | Use `Name.IsEquivalentTo` instead. - * For the web UI: * Updated the JSON validator/schema for Content Patcher 1.25.0. * Added `data-*` attributes to log parser page for external tools. diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index b736ca59..3351e5c4 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -77,8 +77,21 @@ namespace StardewModdingAPI public static GameFramework GameFramework { get; } = EarlyConstants.GameFramework; /// The path to the game folder. - [Obsolete($"Use {nameof(GamePath)} instead.")] - public static string ExecutionPath => Constants.GamePath; + [Obsolete($"Use {nameof(Constants)}.{nameof(GamePath)} instead.")] + public static string ExecutionPath + { + get + { + SCore.DeprecationManager.Warn( + source: SCore.DeprecationManager.GetSourceNameFromStack(), + nounPhrase: $"{nameof(Constants)}.{nameof(Constants.ExecutionPath)}", + version: "3.14.0", + severity: DeprecationLevel.Notice + ); + + return Constants.GamePath; + } + } /// The path to the game folder. public static string GamePath { get; } = EarlyConstants.GamePath; diff --git a/src/SMAPI/Framework/Content/AssetInfo.cs b/src/SMAPI/Framework/Content/AssetInfo.cs index 556f1c2a..6e93c33c 100644 --- a/src/SMAPI/Framework/Content/AssetInfo.cs +++ b/src/SMAPI/Framework/Content/AssetInfo.cs @@ -27,7 +27,20 @@ namespace StardewModdingAPI.Framework.Content /// [Obsolete($"Use {nameof(Name)} or {nameof(NameWithoutLocale)} instead.")] - public string AssetName => this.NameWithoutLocale.Name; + public string AssetName + { + get + { + SCore.DeprecationManager.Warn( + source: SCore.DeprecationManager.GetSourceNameFromStack(), + nounPhrase: $"{nameof(IAssetInfo)}.{nameof(IAssetInfo.AssetName)}", + version: "3.14.0", + severity: DeprecationLevel.Notice + ); + + return this.NameWithoutLocale.Name; + } + } /// public Type DataType { get; } @@ -54,6 +67,14 @@ namespace StardewModdingAPI.Framework.Content [Obsolete($"Use {nameof(Name)}.{nameof(IAssetName.IsEquivalentTo)} or {nameof(NameWithoutLocale)}.{nameof(IAssetName.IsEquivalentTo)} instead.")] public bool AssetNameEquals(string path) { + SCore.DeprecationManager.Warn( + source: SCore.DeprecationManager.GetSourceNameFromStack(), + nounPhrase: $"{nameof(IAssetInfo)}.{nameof(IAssetInfo.AssetNameEquals)}", + version: "3.14.0", + severity: DeprecationLevel.Notice + ); + + return this.NameWithoutLocale.IsEquivalentTo(path); } diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 3416c286..3727b909 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -44,16 +44,42 @@ namespace StardewModdingAPI.Framework.ModHelpers public LocalizedContentManager.LanguageCode CurrentLocaleConstant => this.GameContentManager.Language; /// The observable implementation of . - internal ObservableCollection ObservableAssetEditors { get; } = new ObservableCollection(); + internal ObservableCollection ObservableAssetEditors { get; } = new(); /// The observable implementation of . - internal ObservableCollection ObservableAssetLoaders { get; } = new ObservableCollection(); + internal ObservableCollection ObservableAssetLoaders { get; } = new(); /// - public IList AssetLoaders => this.ObservableAssetLoaders; + public IList AssetLoaders + { + get + { + SCore.DeprecationManager.Warn( + source: this.ModName, + nounPhrase: $"{nameof(IContentHelper)}.{nameof(IContentHelper.AssetLoaders)}", + version: "3.14.0", + severity: DeprecationLevel.Notice + ); + + return this.ObservableAssetLoaders; + } + } /// - public IList AssetEditors => this.ObservableAssetEditors; + public IList AssetEditors + { + get + { + SCore.DeprecationManager.Warn( + source: this.ModName, + nounPhrase: $"{nameof(IContentHelper)}.{nameof(IContentHelper.AssetEditors)}", + version: "3.14.0", + severity: DeprecationLevel.Notice + ); + + return this.ObservableAssetEditors; + } + } /********* diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index dd952dee..eab977ac 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1609,9 +1609,28 @@ namespace StardewModdingAPI.Framework { // ReSharper disable SuspiciousTypeConversion.Global if (metadata.Mod is IAssetEditor editor) + { + SCore.DeprecationManager.Warn( + source: metadata.DisplayName, + nounPhrase: $"{nameof(IAssetEditor)}", + version: "3.14.0", + severity: DeprecationLevel.Notice + ); + this.ContentCore.Editors.Add(new ModLinked(metadata, editor)); + } + if (metadata.Mod is IAssetLoader loader) + { + SCore.DeprecationManager.Warn( + source: metadata.DisplayName, + nounPhrase: $"{nameof(IAssetLoader)}", + version: "3.14.0", + severity: DeprecationLevel.Notice + ); + this.ContentCore.Loaders.Add(new ModLinked(metadata, loader)); + } // ReSharper restore SuspiciousTypeConversion.Global helper.ObservableAssetEditors.CollectionChanged += (sender, e) => this.OnAssetInterceptorsChanged(metadata, e.NewItems?.Cast(), e.OldItems?.Cast(), this.ContentCore.Editors); diff --git a/src/SMAPI/IAssetInfo.cs b/src/SMAPI/IAssetInfo.cs index c7b2ab62..c3753b97 100644 --- a/src/SMAPI/IAssetInfo.cs +++ b/src/SMAPI/IAssetInfo.cs @@ -12,6 +12,7 @@ namespace StardewModdingAPI string Locale { get; } /// The asset name being read. + /// NOTE: when reading this field from an or implementation, it's always equivalent to for backwards compatibility. public IAssetName Name { get; } /// The with any locale codes stripped.