diff options
Diffstat (limited to 'src/StardewModdingAPI.Toolkit')
4 files changed, 50 insertions, 7 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs index c9d9f916..45b46ea6 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/ModExtendedMetadataModel.cs @@ -41,6 +41,15 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi public string CustomUrl { get; set; } /**** + ** SMAPI 3.0 readiness + ****/ + /// <summary>Whether the mod is ready for the upcoming SMAPI 3.0.</summary> + public WikiSmapi3Status Smapi3Status { get; set; } + + /// <summary>A URL related to the <see cref="Smapi3Status"/>.</summary> + public string Smapi3Url { get; set; } + + /**** ** Stable compatibility ****/ /// <summary>The compatibility status.</summary> @@ -85,6 +94,9 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi this.CustomSourceUrl = wiki.CustomSourceUrl; this.CustomUrl = wiki.CustomUrl; + this.Smapi3Status = wiki.Smapi3Status; + this.Smapi3Url = wiki.Smapi3Url; + this.CompatibilityStatus = wiki.Compatibility.Status; this.CompatibilitySummary = wiki.Compatibility.Summary; diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs index 91078b08..19a4292f 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiClient.cs @@ -102,7 +102,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki // parse stable compatibility WikiCompatibilityInfo compatibility = new WikiCompatibilityInfo { - Status = this.GetAttributeAsStatus(node, "data-status") ?? WikiCompatibilityStatus.Ok, + Status = this.GetAttributeAsEnum<WikiCompatibilityStatus>(node, "data-status") ?? WikiCompatibilityStatus.Ok, BrokeIn = this.GetAttribute(node, "data-broke-in"), UnofficialVersion = this.GetAttributeAsSemanticVersion(node, "data-unofficial-version"), UnofficialUrl = this.GetAttribute(node, "data-unofficial-url"), @@ -112,7 +112,7 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki // parse beta compatibility WikiCompatibilityInfo betaCompatibility = null; { - WikiCompatibilityStatus? betaStatus = this.GetAttributeAsStatus(node, "data-beta-status"); + WikiCompatibilityStatus? betaStatus = this.GetAttributeAsEnum<WikiCompatibilityStatus>(node, "data-beta-status"); if (betaStatus.HasValue) { betaCompatibility = new WikiCompatibilityInfo @@ -126,6 +126,10 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki } } + // parse SMAPI 3.0 readiness status + WikiSmapi3Status smapi3Status = this.GetAttributeAsEnum<WikiSmapi3Status>(node, "data-smapi-3-status") ?? WikiSmapi3Status.Unknown; + string smapi3Url = this.GetAttribute(node, "data-smapi-3-url"); + // yield model yield return new WikiModEntry { @@ -140,6 +144,8 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki CustomUrl = customUrl, Compatibility = compatibility, BetaCompatibility = betaCompatibility, + Smapi3Status = smapi3Status, + Smapi3Url = smapi3Url, Warnings = warnings, Anchor = anchor }; @@ -169,17 +175,18 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki : new string[0]; } - /// <summary>Get an attribute value and parse it as a compatibility status.</summary> + /// <summary>Get an attribute value and parse it as an enum value.</summary> + /// <typeparam name="TEnum">The enum type.</typeparam> /// <param name="element">The element whose attributes to read.</param> /// <param name="name">The attribute name.</param> - private WikiCompatibilityStatus? GetAttributeAsStatus(HtmlNode element, string name) + private TEnum? GetAttributeAsEnum<TEnum>(HtmlNode element, string name) where TEnum : struct { string raw = this.GetAttribute(element, name); if (raw == null) return null; - if (!Enum.TryParse(raw, true, out WikiCompatibilityStatus status)) - throw new InvalidOperationException($"Unknown status '{raw}' when parsing compatibility list."); - return status; + if (!Enum.TryParse(raw, true, out TEnum value) && Enum.IsDefined(typeof(TEnum), value)) + throw new InvalidOperationException($"Unknown {typeof(TEnum).Name} value '{raw}' when parsing compatibility list."); + return value; } /// <summary>Get an attribute value and parse it as a semantic version.</summary> diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs index f7b7839b..b71269fe 100644 --- a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiModEntry.cs @@ -39,6 +39,12 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki /// <summary>The mod's compatibility with the latest beta version of the game (if any).</summary> public WikiCompatibilityInfo BetaCompatibility { get; set; } + /// <summary>Whether the mod is ready for the upcoming SMAPI 3.0.</summary> + public WikiSmapi3Status Smapi3Status { get; set; } + + /// <summary>A URL related to the <see cref="Smapi3Status"/>.</summary> + public string Smapi3Url { get; set; } + /// <summary>Whether a Stardew Valley or SMAPI beta which affects mod compatibility is in progress. If this is true, <see cref="BetaCompatibility"/> should be used for beta versions of SMAPI instead of <see cref="Compatibility"/>.</summary> public bool HasBetaInfo => this.BetaCompatibility != null; diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiSmapi3Status.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiSmapi3Status.cs new file mode 100644 index 00000000..879cfd8a --- /dev/null +++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/Wiki/WikiSmapi3Status.cs @@ -0,0 +1,18 @@ +namespace StardewModdingAPI.Toolkit.Framework.Clients.Wiki +{ + /// <summary>Whether a mod is ready for the upcoming SMAPI 3.0.</summary> + public enum WikiSmapi3Status + { + /// <summary>The mod's compatibility status is unknown.</summary> + Unknown = 0, + + /// <summary>The mod is compatible with the upcoming SMAPI 3.0.</summary> + Ok = 1, + + /// <summary>The mod will break in SMAPI 3.0.</summary> + Broken = 2, + + /// <summary>The mod has a pull request submitted for SMAPI 3.0 compatibility.</summary> + Soon = 3 + } +} |