summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Models/ModDataRecord.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-10-07 23:20:36 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-10-07 23:20:36 -0400
commitd0dd2f7ba729de6be749d326a2fed78988ba9d7b (patch)
treea22127da6a8900e9f29bbb847bfd5d3347f6b952 /src/SMAPI/Framework/Models/ModDataRecord.cs
parent7889676ea24cafc945899bf25608784e3f5bc9e0 (diff)
parent5928f5f86c4493ddb6b89bce0b7d0fb73a884c09 (diff)
downloadSMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.gz
SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.tar.bz2
SMAPI-d0dd2f7ba729de6be749d326a2fed78988ba9d7b.zip
Merge branch 'add-mod-build-config' into develop
Diffstat (limited to 'src/SMAPI/Framework/Models/ModDataRecord.cs')
-rw-r--r--src/SMAPI/Framework/Models/ModDataRecord.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/Models/ModDataRecord.cs b/src/SMAPI/Framework/Models/ModDataRecord.cs
new file mode 100644
index 00000000..c6a12188
--- /dev/null
+++ b/src/SMAPI/Framework/Models/ModDataRecord.cs
@@ -0,0 +1,63 @@
+using System.Collections.Generic;
+using System.Linq;
+using Newtonsoft.Json;
+using StardewModdingAPI.Framework.Serialisation;
+
+namespace StardewModdingAPI.Framework.Models
+{
+ /// <summary>Metadata about a mod from SMAPI's internal data.</summary>
+ internal class ModDataRecord
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The unique mod identifier.</summary>
+ [JsonConverter(typeof(SFieldConverter))]
+ public ModDataID ID { get; set; }
+
+ /// <summary>A value to inject into <see cref="IManifest.UpdateKeys"/> field if it's not already set.</summary>
+ public string[] UpdateKeys { get; set; }
+
+ /// <summary>The URL where the player can get an unofficial or alternative version of the mod if the official version isn't compatible.</summary>
+ public string AlternativeUrl { get; set; }
+
+ /// <summary>The compatibility of given mod versions (if any).</summary>
+ [JsonConverter(typeof(SFieldConverter))]
+ public ModCompatibility[] Compatibility { get; set; } = new ModCompatibility[0];
+
+ /// <summary>Map local versions to a semantic version for update checks.</summary>
+ public IDictionary<string, string> MapLocalVersions { get; set; } = new Dictionary<string, string>();
+
+ /// <summary>Map remote versions to a semantic version for update checks.</summary>
+ public IDictionary<string, string> MapRemoteVersions { get; set; } = new Dictionary<string, string>();
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Get the compatibility record for a given version, if any.</summary>
+ /// <param name="version">The mod version to check.</param>
+ public ModCompatibility GetCompatibility(ISemanticVersion version)
+ {
+ return this.Compatibility.FirstOrDefault(p => p.MatchesVersion(version));
+ }
+
+ /// <summary>Get a semantic local version for update checks.</summary>
+ /// <param name="version">The local version to normalise.</param>
+ public string GetLocalVersionForUpdateChecks(string version)
+ {
+ return this.MapLocalVersions != null && this.MapLocalVersions.TryGetValue(version, out string newVersion)
+ ? newVersion
+ : version;
+ }
+
+ /// <summary>Get a semantic remote version for update checks.</summary>
+ /// <param name="version">The remote version to normalise.</param>
+ public string GetRemoteVersionForUpdateChecks(string version)
+ {
+ return this.MapRemoteVersions != null && this.MapRemoteVersions.TryGetValue(version, out string newVersion)
+ ? newVersion
+ : version;
+ }
+ }
+}