using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using StardewModdingAPI.Framework.Serialisation; namespace StardewModdingAPI.Framework.Models { /// Metadata about a mod from SMAPI's internal data. internal class ModDataRecord { /********* ** Accessors *********/ /// The unique mod identifier. [JsonConverter(typeof(SFieldConverter))] public ModDataID ID { get; set; } /// A value to inject into field if it's not already set. public string[] UpdateKeys { get; set; } /// The URL where the player can get an unofficial or alternative version of the mod if the official version isn't compatible. public string AlternativeUrl { get; set; } /// The compatibility of given mod versions (if any). [JsonConverter(typeof(SFieldConverter))] public ModCompatibility[] Compatibility { get; set; } = new ModCompatibility[0]; /// Map local versions to a semantic version for update checks. public IDictionary MapLocalVersions { get; set; } = new Dictionary(); /// Map remote versions to a semantic version for update checks. public IDictionary MapRemoteVersions { get; set; } = new Dictionary(); /********* ** Public methods *********/ /// Get the compatibility record for a given version, if any. /// The mod version to check. public ModCompatibility GetCompatibility(ISemanticVersion version) { return this.Compatibility.FirstOrDefault(p => p.MatchesVersion(version)); } /// Get a semantic local version for update checks. /// The local version to normalise. public string GetLocalVersionForUpdateChecks(string version) { return this.MapLocalVersions != null && this.MapLocalVersions.TryGetValue(version, out string newVersion) ? newVersion : version; } /// Get a semantic remote version for update checks. /// The remote version to normalise. public string GetRemoteVersionForUpdateChecks(string version) { return this.MapRemoteVersions != null && this.MapRemoteVersions.TryGetValue(version, out string newVersion) ? newVersion : version; } } }