summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/Models
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework/Models')
-rw-r--r--src/StardewModdingAPI/Framework/Models/Manifest.cs6
-rw-r--r--src/StardewModdingAPI/Framework/Models/ModCompatibility.cs50
-rw-r--r--src/StardewModdingAPI/Framework/Models/ModCompatibilityID.cs57
3 files changed, 71 insertions, 42 deletions
diff --git a/src/StardewModdingAPI/Framework/Models/Manifest.cs b/src/StardewModdingAPI/Framework/Models/Manifest.cs
index 1b5c2646..29c3517e 100644
--- a/src/StardewModdingAPI/Framework/Models/Manifest.cs
+++ b/src/StardewModdingAPI/Framework/Models/Manifest.cs
@@ -21,18 +21,18 @@ namespace StardewModdingAPI.Framework.Models
public string Author { get; set; }
/// <summary>The mod version.</summary>
- [JsonConverter(typeof(ManifestFieldConverter))]
+ [JsonConverter(typeof(SFieldConverter))]
public ISemanticVersion Version { get; set; }
/// <summary>The minimum SMAPI version required by this mod, if any.</summary>
- [JsonConverter(typeof(ManifestFieldConverter))]
+ [JsonConverter(typeof(SFieldConverter))]
public ISemanticVersion MinimumApiVersion { get; set; }
/// <summary>The name of the DLL in the directory that has the <see cref="Mod.Entry"/> method.</summary>
public string EntryDll { get; set; }
/// <summary>The other mods that must be loaded before this mod.</summary>
- [JsonConverter(typeof(ManifestFieldConverter))]
+ [JsonConverter(typeof(SFieldConverter))]
public IManifestDependency[] Dependencies { get; set; }
/// <summary>The unique mod ID.</summary>
diff --git a/src/StardewModdingAPI/Framework/Models/ModCompatibility.cs b/src/StardewModdingAPI/Framework/Models/ModCompatibility.cs
index 90cbd237..d3a9c533 100644
--- a/src/StardewModdingAPI/Framework/Models/ModCompatibility.cs
+++ b/src/StardewModdingAPI/Framework/Models/ModCompatibility.cs
@@ -1,5 +1,5 @@
-using System.Runtime.Serialization;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
+using StardewModdingAPI.Framework.Serialisation;
namespace StardewModdingAPI.Framework.Models
{
@@ -9,60 +9,32 @@ namespace StardewModdingAPI.Framework.Models
/*********
** Accessors
*********/
- /****
- ** From config
- ****/
/// <summary>The unique mod IDs.</summary>
- public string[] ID { get; set; }
+ [JsonConverter(typeof(SFieldConverter))]
+ public ModCompatibilityID[] ID { get; set; }
/// <summary>The mod name.</summary>
public string Name { get; set; }
/// <summary>The oldest incompatible mod version, or <c>null</c> for all past versions.</summary>
- public string LowerVersion { get; set; }
+ [JsonConverter(typeof(SFieldConverter))]
+ public ISemanticVersion LowerVersion { get; set; }
/// <summary>The most recent incompatible mod version.</summary>
- public string UpperVersion { get; set; }
+ [JsonConverter(typeof(SFieldConverter))]
+ public ISemanticVersion UpperVersion { get; set; }
/// <summary>A label to show to the user instead of <see cref="UpperVersion"/>, when the manifest version differs from the user-facing version.</summary>
public string UpperVersionLabel { get; set; }
- /// <summary>The URL the user can check for an official updated version.</summary>
- public string UpdateUrl { get; set; }
-
- /// <summary>The URL the user can check for an unofficial updated version.</summary>
- public string UnofficialUpdateUrl { get; set; }
+ /// <summary>The URLs the user can check for a newer version.</summary>
+ public string[] UpdateUrls { get; set; }
/// <summary>The reason phrase to show in the warning, or <c>null</c> to use the default value.</summary>
/// <example>"this version is incompatible with the latest version of the game"</example>
public string ReasonPhrase { get; set; }
/// <summary>Indicates how SMAPI should consider the mod.</summary>
- public ModCompatibilityType Compatibility { get; set; }
-
-
- /****
- ** Injected
- ****/
- /// <summary>The semantic version corresponding to <see cref="LowerVersion"/>.</summary>
- [JsonIgnore]
- public ISemanticVersion LowerSemanticVersion { get; set; }
-
- /// <summary>The semantic version corresponding to <see cref="UpperVersion"/>.</summary>
- [JsonIgnore]
- public ISemanticVersion UpperSemanticVersion { get; set; }
-
-
- /*********
- ** Private methods
- *********/
- /// <summary>The method called when the model finishes deserialising.</summary>
- /// <param name="context">The deserialisation context.</param>
- [OnDeserialized]
- private void OnDeserialized(StreamingContext context)
- {
- this.LowerSemanticVersion = this.LowerVersion != null ? new SemanticVersion(this.LowerVersion) : null;
- this.UpperSemanticVersion = this.UpperVersion != null ? new SemanticVersion(this.UpperVersion) : null;
- }
+ public ModCompatibilityType Compatibility { get; set; } = ModCompatibilityType.AssumeBroken;
}
}
diff --git a/src/StardewModdingAPI/Framework/Models/ModCompatibilityID.cs b/src/StardewModdingAPI/Framework/Models/ModCompatibilityID.cs
new file mode 100644
index 00000000..98e70116
--- /dev/null
+++ b/src/StardewModdingAPI/Framework/Models/ModCompatibilityID.cs
@@ -0,0 +1,57 @@
+using System;
+using Newtonsoft.Json;
+
+namespace StardewModdingAPI.Framework.Models
+{
+ /// <summary>Uniquely identifies a mod for compatibility checks.</summary>
+ internal class ModCompatibilityID
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The unique mod ID.</summary>
+ public string ID { get; set; }
+
+ /// <summary>The mod name to disambiguate non-unique IDs, or <c>null</c> to ignore the mod name.</summary>
+ public string Name { get; set; }
+
+ /// <summary>The author name to disambiguate non-unique IDs, or <c>null</c> to ignore the author.</summary>
+ public string Author { get; set; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public ModCompatibilityID() { }
+
+ /// <summary>Construct an instance.</summary>
+ /// <param name="data">The mod ID or a JSON string matching the <see cref="ModCompatibilityID"/> fields.</param>
+ public ModCompatibilityID(string data)
+ {
+ // JSON can be stuffed into the ID string as a convenience hack to keep JSON mod lists
+ // formatted readably. The tradeoff is that the format is a bit more magical, but that's
+ // probably acceptable since players aren't meant to edit it. It's also fairly clear what
+ // the JSON strings do, if not necessarily how.
+ if (data.StartsWith("{"))
+ JsonConvert.PopulateObject(data, this);
+ else
+ this.ID = data;
+ }
+
+ /// <summary>Get whether this ID matches a given mod manifest.</summary>
+ /// <param name="id">The mod's unique ID, or a substitute ID if it isn't set in the manifest.</param>
+ /// <param name="manifest">The manifest to check.</param>
+ public bool Matches(string id, IManifest manifest)
+ {
+ return
+ this.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase)
+ && (
+ this.Author == null
+ || this.Author.Equals(manifest.Author, StringComparison.InvariantCultureIgnoreCase)
+ || (manifest.ExtraFields.ContainsKey("Authour") && this.Author.Equals(manifest.ExtraFields["Authour"].ToString(), StringComparison.InvariantCultureIgnoreCase))
+ )
+ && (this.Name == null || this.Name.Equals(manifest.Name, StringComparison.InvariantCultureIgnoreCase));
+ }
+ }
+}