deprecate ConsoleCommands.Trigger method

This commit is contained in:
Jesse Plamondon-Willard 2020-12-26 11:20:47 -05:00
parent 8895021696
commit 5cc069476e
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 21 additions and 19 deletions

View File

@ -14,6 +14,7 @@
* For modders: * For modders:
* World events are now raised for the volcano levels. * 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. * 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: For the web UI:
* Fixed edge cases in SMAPI log parsing. * Fixed edge cases in SMAPI log parsing.

View File

@ -35,19 +35,17 @@ namespace StardewModdingAPI.Framework
this.ModRegistry = modRegistry; this.ModRegistry = modRegistry;
} }
/// <summary>Log a deprecation warning for the old-style events.</summary> /// <summary>Get the source name for a mod from its unique ID.</summary>
public void WarnForOldEvents() public string GetSourceNameFromStack()
{ {
this.Warn("legacy events", "2.9", DeprecationLevel.PendingRemoval); return this.ModRegistry.GetFromStack()?.DisplayName;
} }
/// <summary>Log a deprecation warning.</summary> /// <summary>Get the source name for a mod from its unique ID.</summary>
/// <param name="nounPhrase">A noun phrase describing what is deprecated.</param> /// <param name="modId">The mod's unique ID.</param>
/// <param name="version">The SMAPI version which deprecated it.</param> public string GetSourceName(string modId)
/// <param name="severity">How deprecated the code is.</param>
public void Warn(string nounPhrase, string version, DeprecationLevel severity)
{ {
this.Warn(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version, severity); return this.ModRegistry.Get(modId)?.DisplayName;
} }
/// <summary>Log a deprecation warning.</summary> /// <summary>Log a deprecation warning.</summary>
@ -58,7 +56,7 @@ namespace StardewModdingAPI.Framework
public void Warn(string source, string nounPhrase, string version, DeprecationLevel severity) public void Warn(string source, string nounPhrase, string version, DeprecationLevel severity)
{ {
// ignore if already warned // ignore if already warned
if (!this.MarkWarned(source ?? "<unknown>", nounPhrase, version)) if (!this.MarkWarned(source ?? this.GetSourceNameFromStack() ?? "<unknown>", nounPhrase, version))
return; return;
// queue warning // queue warning
@ -111,21 +109,16 @@ namespace StardewModdingAPI.Framework
this.QueuedWarnings.Clear(); this.QueuedWarnings.Clear();
} }
/// <summary>Mark a deprecation warning as already logged.</summary>
/// <param name="nounPhrase">A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method").</param>
/// <param name="version">The SMAPI version which deprecated it.</param>
/// <returns>Returns whether the deprecation was successfully marked as warned. Returns <c>false</c> if it was already marked.</returns>
public bool MarkWarned(string nounPhrase, string version)
{
return this.MarkWarned(this.ModRegistry.GetFromStack()?.DisplayName, nounPhrase, version);
}
/*********
** Private methods
*********/
/// <summary>Mark a deprecation warning as already logged.</summary> /// <summary>Mark a deprecation warning as already logged.</summary>
/// <param name="source">The friendly name of the assembly which used the deprecated code.</param> /// <param name="source">The friendly name of the assembly which used the deprecated code.</param>
/// <param name="nounPhrase">A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method").</param> /// <param name="nounPhrase">A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method").</param>
/// <param name="version">The SMAPI version which deprecated it.</param> /// <param name="version">The SMAPI version which deprecated it.</param>
/// <returns>Returns whether the deprecation was successfully marked as warned. Returns <c>false</c> if it was already marked.</returns> /// <returns>Returns whether the deprecation was successfully marked as warned. Returns <c>false</c> if it was already marked.</returns>
public bool MarkWarned(string source, string nounPhrase, string version) private bool MarkWarned(string source, string nounPhrase, string version)
{ {
if (string.IsNullOrWhiteSpace(source)) if (string.IsNullOrWhiteSpace(source))
throw new InvalidOperationException("The deprecation source cannot be empty."); throw new InvalidOperationException("The deprecation source cannot be empty.");

View File

@ -36,8 +36,16 @@ namespace StardewModdingAPI.Framework.ModHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
[Obsolete]
public bool Trigger(string name, string[] arguments) 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); return this.CommandManager.Trigger(name, arguments);
} }
} }