diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-03-16 22:17:58 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-03-16 22:17:58 -0400 |
commit | 0d762faf603aac417a382ec680aaabdf7248493b (patch) | |
tree | da05052ddeb77244746941b87b4f80afaefc4fb8 /src | |
parent | ebc6911301018f4c09a5325c06b96b08610570dd (diff) | |
download | SMAPI-0d762faf603aac417a382ec680aaabdf7248493b.tar.gz SMAPI-0d762faf603aac417a382ec680aaabdf7248493b.tar.bz2 SMAPI-0d762faf603aac417a382ec680aaabdf7248493b.zip |
add support for suppressing warnings in mod DB
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI/Framework/IModMetadata.cs | 4 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/AssemblyLoader.cs | 1 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/ModMetadata.cs | 9 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 4 | ||||
-rw-r--r-- | src/SMAPI/StardewModdingAPI.csproj | 1 | ||||
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataModel.cs | 3 | ||||
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs | 4 | ||||
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Framework/ModData/ModWarning.cs (renamed from src/SMAPI/Framework/ModLoading/ModWarning.cs) | 7 |
8 files changed, 27 insertions, 6 deletions
diff --git a/src/SMAPI/Framework/IModMetadata.cs b/src/SMAPI/Framework/IModMetadata.cs index 7ada7dea..38514959 100644 --- a/src/SMAPI/Framework/IModMetadata.cs +++ b/src/SMAPI/Framework/IModMetadata.cs @@ -98,5 +98,9 @@ namespace StardewModdingAPI.Framework /// <summary>Whether the mod has at least one valid update key set.</summary> bool HasValidUpdateKeys(); + + /// <summary>Get whether the mod has a given warning and it hasn't been suppressed in the <see cref="DataRecord"/>.</summary> + /// <param name="warning">The warning to check.</param> + bool HasUnsuppressWarning(ModWarning warning); } } diff --git a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs index 5e0571a0..878b3148 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyLoader.cs @@ -8,6 +8,7 @@ using Mono.Cecil.Cil; using StardewModdingAPI.Framework.Exceptions; using StardewModdingAPI.Internal; using StardewModdingAPI.Metadata; +using StardewModdingAPI.Toolkit.Framework.ModData; namespace StardewModdingAPI.Framework.ModLoading { diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs index 0cb62a75..4ff021b7 100644 --- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs @@ -179,5 +179,14 @@ namespace StardewModdingAPI.Framework.ModLoading { return this.GetUpdateKeys(validOnly: true).Any(); } + + /// <summary>Get whether the mod has a given warning and it hasn't been suppressed in the <see cref="DataRecord"/>.</summary> + /// <param name="warning">The warning to check.</param> + public bool HasUnsuppressWarning(ModWarning warning) + { + return + this.Warnings.HasFlag(warning) + && (this.DataRecord?.DataRecord == null || !this.DataRecord.DataRecord.SuppressWarnings.HasFlag(warning)); + } } } diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index e0347eb2..9ffa46a5 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1107,7 +1107,9 @@ namespace StardewModdingAPI.Framework // issue block format logic void LogWarningGroup(ModWarning warning, LogLevel logLevel, string heading, params string[] blurb) { - IModMetadata[] matches = modsWithWarnings.Where(p => p.Warnings.HasFlag(warning)).ToArray(); + IModMetadata[] matches = modsWithWarnings + .Where(mod => mod.HasUnsuppressWarning(warning)) + .ToArray(); if (!matches.Any()) return; diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 6692bc02..b6562eca 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -228,7 +228,6 @@ <Compile Include="Framework\ModLoading\IInstructionHandler.cs" /> <Compile Include="Framework\ModLoading\IncompatibleInstructionException.cs" /> <Compile Include="Framework\ModLoading\InstructionHandleResult.cs" /> - <Compile Include="Framework\ModLoading\ModWarning.cs" /> <Compile Include="Framework\ModLoading\PlatformAssemblyMap.cs" /> <Compile Include="Framework\ModLoading\RewriteHelper.cs" /> <Compile Include="Framework\ModLoading\Rewriters\FieldReplaceRewriter.cs" /> diff --git a/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataModel.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataModel.cs index d6f32132..18039762 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataModel.cs @@ -31,6 +31,9 @@ namespace StardewModdingAPI.Toolkit.Framework.ModData /// <summary>Maps remote versions to a semantic version for update checks.</summary> public IDictionary<string, string> MapRemoteVersions { get; set; } = new Dictionary<string, string>(); + /// <summary>The mod warnings to suppress, even if they'd normally be shown.</summary> + public ModWarning SuppressWarnings { get; set; } + /// <summary>This field stores properties that aren't mapped to another field before they're parsed into <see cref="Fields"/>.</summary> [JsonExtensionData] public IDictionary<string, JToken> ExtensionData { get; set; } diff --git a/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs index 3949f7dc..794ad2e4 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModDataRecord.cs @@ -19,6 +19,9 @@ namespace StardewModdingAPI.Toolkit.Framework.ModData /// <summary>The former mod IDs (if any).</summary> public string[] FormerIDs { get; } + /// <summary>The mod warnings to suppress, even if they'd normally be shown.</summary> + public ModWarning SuppressWarnings { get; set; } + /// <summary>Maps local versions to a semantic version for update checks.</summary> public IDictionary<string, string> MapLocalVersions { get; } @@ -40,6 +43,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModData this.DisplayName = displayName; this.ID = model.ID; this.FormerIDs = model.GetFormerIDs().ToArray(); + this.SuppressWarnings = model.SuppressWarnings; this.MapLocalVersions = new Dictionary<string, string>(model.MapLocalVersions, StringComparer.InvariantCultureIgnoreCase); this.MapRemoteVersions = new Dictionary<string, string>(model.MapRemoteVersions, StringComparer.InvariantCultureIgnoreCase); this.Fields = model.GetFields().ToArray(); diff --git a/src/SMAPI/Framework/ModLoading/ModWarning.cs b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModWarning.cs index e643cb05..d61c427f 100644 --- a/src/SMAPI/Framework/ModLoading/ModWarning.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/ModData/ModWarning.cs @@ -1,11 +1,10 @@ using System; -using StardewModdingAPI.Events; -namespace StardewModdingAPI.Framework.ModLoading +namespace StardewModdingAPI.Toolkit.Framework.ModData { /// <summary>Indicates a detected non-error mod issue.</summary> [Flags] - internal enum ModWarning + public enum ModWarning { /// <summary>No issues detected.</summary> None = 0, @@ -22,7 +21,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// <summary>The mod uses the <c>dynamic</c> keyword which won't work on Linux/Mac.</summary> UsesDynamic = 8, - /// <summary>The mod references <see cref="ISpecialisedEvents.UnvalidatedUpdateTicking"/> or <see cref="ISpecialisedEvents.UnvalidatedUpdateTicked"/> which may impact stability.</summary> + /// <summary>The mod references specialised 'unvalided update tick' events which may impact stability.</summary> UsesUnvalidatedUpdateTick = 16, /// <summary>The mod has no update keys set.</summary> |