From 5cc069476e1cb63c8fef2dd245a540b6b5130e68 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 26 Dec 2020 11:20:47 -0500 Subject: deprecate ConsoleCommands.Trigger method --- docs/release-notes.md | 1 + src/SMAPI/Framework/DeprecationManager.cs | 31 ++++++++++--------------- src/SMAPI/Framework/ModHelpers/CommandHelper.cs | 8 +++++++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index fe614303..0cc45116 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -14,6 +14,7 @@ * For modders: * World events are now raised for the volcano levels. * Added `apply_save_fix` command to reapply a save migration in exceptional cases. This should be used with extreme care. Type `help apply_save_fix` for details. + * **Deprecation notice:** the `Helper.ConsoleCommands.Trigger` method is now deprecated and should no longer be used. See [integration APIs](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Integrations) for better mod integration options. It will eventually be removed in SMAPI 4.0. For the web UI: * Fixed edge cases in SMAPI log parsing. diff --git a/src/SMAPI/Framework/DeprecationManager.cs b/src/SMAPI/Framework/DeprecationManager.cs index 94a2da85..c22b5718 100644 --- a/src/SMAPI/Framework/DeprecationManager.cs +++ b/src/SMAPI/Framework/DeprecationManager.cs @@ -35,19 +35,17 @@ namespace StardewModdingAPI.Framework this.ModRegistry = modRegistry; } - /// Log a deprecation warning for the old-style events. - public void WarnForOldEvents() + /// Get the source name for a mod from its unique ID. + public string GetSourceNameFromStack() { - this.Warn("legacy events", "2.9", DeprecationLevel.PendingRemoval); + return this.ModRegistry.GetFromStack()?.DisplayName; } - /// Log a deprecation warning. - /// A noun phrase describing what is deprecated. - /// The SMAPI version which deprecated it. - /// How deprecated the code is. - public void Warn(string nounPhrase, string version, DeprecationLevel severity) + /// Get the source name for a mod from its unique ID. + /// The mod's unique ID. + public string GetSourceName(string modId) { - this.Warn(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version, severity); + return this.ModRegistry.Get(modId)?.DisplayName; } /// Log a deprecation warning. @@ -58,7 +56,7 @@ namespace StardewModdingAPI.Framework public void Warn(string source, string nounPhrase, string version, DeprecationLevel severity) { // ignore if already warned - if (!this.MarkWarned(source ?? "", nounPhrase, version)) + if (!this.MarkWarned(source ?? this.GetSourceNameFromStack() ?? "", nounPhrase, version)) return; // queue warning @@ -111,21 +109,16 @@ namespace StardewModdingAPI.Framework this.QueuedWarnings.Clear(); } - /// Mark a deprecation warning as already logged. - /// A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method"). - /// The SMAPI version which deprecated it. - /// Returns whether the deprecation was successfully marked as warned. Returns false if it was already marked. - public bool MarkWarned(string nounPhrase, string version) - { - return this.MarkWarned(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version); - } + /********* + ** Private methods + *********/ /// Mark a deprecation warning as already logged. /// The friendly name of the assembly which used the deprecated code. /// A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method"). /// The SMAPI version which deprecated it. /// Returns whether the deprecation was successfully marked as warned. Returns false if it was already marked. - public bool MarkWarned(string source, string nounPhrase, string version) + private bool MarkWarned(string source, string nounPhrase, string version) { if (string.IsNullOrWhiteSpace(source)) throw new InvalidOperationException("The deprecation source cannot be empty."); diff --git a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs index 600f867f..69382009 100644 --- a/src/SMAPI/Framework/ModHelpers/CommandHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/CommandHelper.cs @@ -36,8 +36,16 @@ namespace StardewModdingAPI.Framework.ModHelpers } /// + [Obsolete] public bool Trigger(string name, string[] arguments) { + SCore.DeprecationManager.Warn( + source: SCore.DeprecationManager.GetSourceName(this.ModID), + nounPhrase: $"{nameof(IModHelper)}.{nameof(IModHelper.ConsoleCommands)}.{nameof(ICommandHelper.Trigger)}", + version: "3.8.1", + severity: DeprecationLevel.Notice + ); + return this.CommandManager.Trigger(name, arguments); } } -- cgit