diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-12-15 00:18:51 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-12-15 00:18:51 -0500 |
commit | 5f620e14fa331b0721bd4044011363477dc79ef5 (patch) | |
tree | 374d13dee743a8406253175cc171ef4f81356538 | |
parent | 567c216161f00767b5dcdb0adf40a3bee91d18d0 (diff) | |
download | SMAPI-5f620e14fa331b0721bd4044011363477dc79ef5.tar.gz SMAPI-5f620e14fa331b0721bd4044011363477dc79ef5.tar.bz2 SMAPI-5f620e14fa331b0721bd4044011363477dc79ef5.zip |
add SMAPI 3.0 readiness to API data (#606)
8 files changed, 106 insertions, 9 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 0e426bfd..fa7f4109 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -13,6 +13,9 @@ * **Deprecations:** * The `assetData.AsDictionary<TKey, TValue>().Set` methods are deprecated and will be removed in SMAPI 3.0. Mods should access the `Data` property directly instead. +* FOR SMAPI developers: + * Added SMAPI 3.0 readiness to mod API data. + ## 2.9.1 * For players: * Fixed crash in SMAPI 2.9 when constructing certain buildings. diff --git a/src/SMAPI.Web/ViewModels/ModModel.cs b/src/SMAPI.Web/ViewModels/ModModel.cs index 5c1840fc..f1a52f98 100644 --- a/src/SMAPI.Web/ViewModels/ModModel.cs +++ b/src/SMAPI.Web/ViewModels/ModModel.cs @@ -31,6 +31,12 @@ namespace StardewModdingAPI.Web.ViewModels /// <summary>The compatibility status for the beta version of the game.</summary> public ModCompatibilityModel BetaCompatibility { get; set; } + /// <summary>Whether the mod is ready for the upcoming SMAPI 3.0.</summary> + public string Smapi3Status { get; set; } + + /// <summary>A URL related to the <see cref="Smapi3Status"/>.</summary> + public string Smapi3Url { get; set; } + /// <summary>Links to the available mod pages.</summary> public ModLinkModel[] ModPages { get; set; } @@ -59,6 +65,8 @@ namespace StardewModdingAPI.Web.ViewModels this.SourceUrl = this.GetSourceUrl(entry); this.Compatibility = new ModCompatibilityModel(entry.Compatibility); this.BetaCompatibility = entry.BetaCompatibility != null ? new ModCompatibilityModel(entry.BetaCompatibility) : null; + this.Smapi3Status = entry.Smapi3Status.ToString().ToLower(); + this.Smapi3Url = entry.Smapi3Url; this.ModPages = this.GetModPageUrls(entry).ToArray(); this.Warnings = entry.Warnings; this.Slug = entry.Anchor; diff --git a/src/SMAPI.Web/Views/Mods/Index.cshtml b/src/SMAPI.Web/Views/Mods/Index.cshtml index a49a24d9..67034322 100644 --- a/src/SMAPI.Web/Views/Mods/Index.cshtml +++ b/src/SMAPI.Web/Views/Mods/Index.cshtml @@ -45,7 +45,10 @@ </div> </div> <div id="mod-count" v-show="showAdvanced"> - <span v-if="visibleStats.total > 0">{{visibleStats.total}} mods shown ({{Math.round((visibleStats.compatible + visibleStats.workaround) / visibleStats.total * 100)}}% compatible or have a workaround, {{Math.round((visibleStats.soon + visibleStats.broken) / visibleStats.total * 100)}}% broken, {{Math.round(visibleStats.abandoned / visibleStats.total * 100)}}% obsolete).</span> + <div v-if="visibleStats.total > 0"> + {{visibleStats.total}} mods shown ({{Math.round((visibleStats.compatible + visibleStats.workaround) / visibleStats.total * 100)}}% compatible or have a workaround, {{Math.round((visibleStats.soon + visibleStats.broken) / visibleStats.total * 100)}}% broken, {{Math.round(visibleStats.abandoned / visibleStats.total * 100)}}% obsolete).<br /> + SMAPI 3.0 (upcoming): {{Math.round(visibleStats.smapi3_ok / visibleStats.total * 100)}}% ready, {{Math.round(visibleStats.smapi3_soon / visibleStats.total * 100)}}% soon, {{Math.round(visibleStats.smapi3_broken / visibleStats.total * 100)}}% broken, {{Math.round(visibleStats.smapi3_unknown / visibleStats.total * 100)}}% unknown. + </div> <span v-else>No matching mods found.</span> </div> <table class="wikitable" id="mod-list"> @@ -57,6 +60,7 @@ <th>compatibility</th> <th v-show="showAdvanced">broke in</th> <th v-show="showAdvanced">code</th> + <th v-show="showAdvanced"><a href="http://smapi.io/3.0">3.0</a></th> <th> </th> </tr> </thead> @@ -88,6 +92,14 @@ <span v-if="mod.SourceUrl"><a v-bind:href="mod.SourceUrl">source</a></span> <span v-else class="mod-closed-source">no source</span> </td> + <td v-show="showAdvanced"> + <template v-if="(mod.BetaCompatibility || mod.Compatibility).Status == 'ok' || mod.Smapi3Status == 'ok' || mod.Smapi3Status == 'soon'"> + <small v-if="mod.Smapi3Status == 'ok'">✓</small> + <small v-else-if="mod.Smapi3Status == 'broken'">✖</small> + <small v-else-if="mod.Smapi3Status == 'soon' && mod.Smapi3Url"><a v-bind:href="mod.Smapi3Url">↻ soon</a></small> + <small v-else>↻ {{mod.Smapi3Status}}</small> + </template> + </td> <td> <small><a v-bind:href="'#' + mod.Slug">#</a></small> </td> diff --git a/src/SMAPI.Web/wwwroot/Content/js/mods.js b/src/SMAPI.Web/wwwroot/Content/js/mods.js index f7a8501e..23c7aa7e 100644 --- a/src/SMAPI.Web/wwwroot/Content/js/mods.js +++ b/src/SMAPI.Web/wwwroot/Content/js/mods.js @@ -11,7 +11,11 @@ smapi.modList = function (mods) { soon: 0, broken: 0, abandoned: 0, - invalid: 0 + invalid: 0, + smapi3_unknown: 0, + smapi3_ok: 0, + smapi3_broken: 0, + smapi3_soon: 0 }; var data = { mods: mods, @@ -88,6 +92,28 @@ smapi.modList = function (mods) { id: "show-custom", value: true } + }, + "SMAPI 3.0": { + ok: { + label: "ready", + id: "show-smapi-3-ready", + value: true + }, + soon: { + label: "soon", + id: "show-smapi-3-soon", + value: true + }, + broken: { + label: "broken", + id: "show-smapi-3-broken", + value: true + }, + unknown: { + label: "unknown", + id: "show-smapi-3-unknown", + value: true + } } }, search: "" @@ -154,6 +180,7 @@ smapi.modList = function (mods) { if (mod.Visible) { stats.total++; stats[this.getCompatibilityGroup(mod)]++; + stats["smapi3_" + mod.Smapi3Status]++; } } }, @@ -179,6 +206,10 @@ smapi.modList = function (mods) { if (filters.status[status] && !filters.status[status].value) return false; + // check SMAPI 3.0 compatibility + if (filters["SMAPI 3.0"][mod.Smapi3Status] && !filters["SMAPI 3.0"][mod.Smapi3Status].value) + return false; + // check download sites var ignoreSites = []; 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 + } +} |