From b5c88d87d2cb1739585651e02513fef73dfc0e27 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 2 Oct 2021 16:40:23 -0400 Subject: add support for unified mod data overrides on the wiki --- src/SMAPI.Web/Framework/ModSiteManager.cs | 39 +++++++++++-------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'src/SMAPI.Web/Framework/ModSiteManager.cs') diff --git a/src/SMAPI.Web/Framework/ModSiteManager.cs b/src/SMAPI.Web/Framework/ModSiteManager.cs index 8f21d2f5..a2b92aa4 100644 --- a/src/SMAPI.Web/Framework/ModSiteManager.cs +++ b/src/SMAPI.Web/Framework/ModSiteManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using StardewModdingAPI.Toolkit; +using StardewModdingAPI.Toolkit.Framework.Clients.Wiki; using StardewModdingAPI.Toolkit.Framework.UpdateData; using StardewModdingAPI.Web.Framework.Clients; @@ -55,9 +56,9 @@ namespace StardewModdingAPI.Web.Framework /// Parse version info for the given mod page info. /// The mod page info. /// The optional update subkey to match in available files. (If no file names or descriptions contain the subkey, it'll be ignored.) - /// Maps remote versions to a semantic version for update checks. + /// The changes to apply to remote versions for update checks. /// Whether to allow non-standard versions. - public ModInfoModel GetPageVersions(IModPage page, string subkey, bool allowNonStandardVersions, IDictionary mapRemoteVersions) + public ModInfoModel GetPageVersions(IModPage page, string subkey, bool allowNonStandardVersions, ChangeDescriptor mapRemoteVersions) { // get base model ModInfoModel model = new ModInfoModel() @@ -79,9 +80,9 @@ namespace StardewModdingAPI.Web.Framework /// Get a semantic local version for update checks. /// The version to parse. - /// A map of version replacements. + /// Changes to apply to the raw version, if any. /// Whether to allow non-standard versions. - public ISemanticVersion GetMappedVersion(string version, IDictionary map, bool allowNonStandard) + public ISemanticVersion GetMappedVersion(string version, ChangeDescriptor map, bool allowNonStandard) { // try mapped version string rawNewVersion = this.GetRawMappedVersion(version, map, allowNonStandard); @@ -102,10 +103,10 @@ namespace StardewModdingAPI.Web.Framework /// The mod to check. /// The optional update subkey to match in available files. (If no file names or descriptions contain the subkey, it'll be ignored.) /// Whether to allow non-standard versions. - /// Maps remote versions to a semantic version for update checks. + /// The changes to apply to remote versions for update checks. /// The main mod version. /// The latest prerelease version, if newer than . - private bool TryGetLatestVersions(IModPage mod, string subkey, bool allowNonStandardVersions, IDictionary mapRemoteVersions, out ISemanticVersion main, out ISemanticVersion preview) + private bool TryGetLatestVersions(IModPage mod, string subkey, bool allowNonStandardVersions, ChangeDescriptor mapRemoteVersions, out ISemanticVersion main, out ISemanticVersion preview) { main = null; preview = null; @@ -179,31 +180,17 @@ namespace StardewModdingAPI.Web.Framework /// Get a semantic local version for update checks. /// The version to map. - /// A map of version replacements. + /// Changes to apply to the raw version, if any. /// Whether to allow non-standard versions. - private string GetRawMappedVersion(string version, IDictionary map, bool allowNonStandard) + private string GetRawMappedVersion(string version, ChangeDescriptor map, bool allowNonStandard) { - if (version == null || map == null || !map.Any()) + if (version == null || map?.HasChanges != true) return version; - // match exact raw version - if (map.ContainsKey(version)) - return map[version]; + var mapped = new List { version }; + map.Apply(mapped); - // match parsed version - if (SemanticVersion.TryParse(version, allowNonStandard, out ISemanticVersion parsed)) - { - if (map.ContainsKey(parsed.ToString())) - return map[parsed.ToString()]; - - foreach ((string fromRaw, string toRaw) in map) - { - if (SemanticVersion.TryParse(fromRaw, allowNonStandard, out ISemanticVersion target) && parsed.Equals(target) && SemanticVersion.TryParse(toRaw, allowNonStandard, out ISemanticVersion newVersion)) - return newVersion.ToString(); - } - } - - return version; + return mapped.FirstOrDefault(); } /// Normalize a version string. -- cgit