diff options
Diffstat (limited to 'src/StardewModdingAPI/Framework/Models')
-rw-r--r-- | src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs | 57 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Models/ModCompatibility.cs | 65 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Models/ModCompatibilityType.cs | 12 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Models/SConfig.cs (renamed from src/StardewModdingAPI/Framework/Models/UserSettings.cs) | 11 |
4 files changed, 84 insertions, 61 deletions
diff --git a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs deleted file mode 100644 index bcf5639c..00000000 --- a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System.Text.RegularExpressions; - -namespace StardewModdingAPI.Framework.Models -{ - /// <summary>Contains abstract metadata about an incompatible mod.</summary> - internal class IncompatibleMod - { - /********* - ** Accessors - *********/ - /// <summary>The unique mod ID.</summary> - public string 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; } - - /// <summary>The most recent incompatible mod version.</summary> - public string UpperVersion { 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>A regular expression matching version strings to consider compatible, even if they technically precede <see cref="UpperVersion"/>.</summary> - public string ForceCompatibleVersion { 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; } - - - /********* - ** Public methods - *********/ - /// <summary>Get whether the specified version is compatible according to this metadata.</summary> - /// <param name="version">The current version of the matching mod.</param> - public bool IsCompatible(ISemanticVersion version) - { - ISemanticVersion lowerVersion = this.LowerVersion != null ? new SemanticVersion(this.LowerVersion) : null; - ISemanticVersion upperVersion = new SemanticVersion(this.UpperVersion); - - // ignore versions not in range - if (lowerVersion != null && version.IsOlderThan(lowerVersion)) - return true; - if (version.IsNewerThan(upperVersion)) - return true; - - // allow versions matching override - return !string.IsNullOrWhiteSpace(this.ForceCompatibleVersion) && Regex.IsMatch(version.ToString(), this.ForceCompatibleVersion, RegexOptions.IgnoreCase); - } - } -} diff --git a/src/StardewModdingAPI/Framework/Models/ModCompatibility.cs b/src/StardewModdingAPI/Framework/Models/ModCompatibility.cs new file mode 100644 index 00000000..1e71dae0 --- /dev/null +++ b/src/StardewModdingAPI/Framework/Models/ModCompatibility.cs @@ -0,0 +1,65 @@ +using System.Runtime.Serialization; +using Newtonsoft.Json; + +namespace StardewModdingAPI.Framework.Models +{ + /// <summary>Metadata about a mod version that SMAPI should assume is compatible or broken, regardless of whether it detects incompatible code.</summary> + internal class ModCompatibility + { + /********* + ** Accessors + *********/ + /**** + ** From config + ****/ + /// <summary>The unique mod ID.</summary> + public string 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; } + + /// <summary>The most recent incompatible mod version.</summary> + public string UpperVersion { 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 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; + } + } +} diff --git a/src/StardewModdingAPI/Framework/Models/ModCompatibilityType.cs b/src/StardewModdingAPI/Framework/Models/ModCompatibilityType.cs new file mode 100644 index 00000000..35edec5e --- /dev/null +++ b/src/StardewModdingAPI/Framework/Models/ModCompatibilityType.cs @@ -0,0 +1,12 @@ +namespace StardewModdingAPI.Framework.Models +{ + /// <summary>Indicates how SMAPI should consider a mod.</summary> + internal enum ModCompatibilityType + { + /// <summary>Assume the mod is not compatible, even if SMAPI doesn't detect any incompatible code.</summary> + AssumeBroken = 0, + + /// <summary>Assume the mod is compatible, even if SMAPI detects incompatible code.</summary> + AssumeCompatible = 1 + } +} diff --git a/src/StardewModdingAPI/Framework/Models/UserSettings.cs b/src/StardewModdingAPI/Framework/Models/SConfig.cs index a0074f77..0de96297 100644 --- a/src/StardewModdingAPI/Framework/Models/UserSettings.cs +++ b/src/StardewModdingAPI/Framework/Models/SConfig.cs @@ -1,15 +1,18 @@ namespace StardewModdingAPI.Framework.Models { - /// <summary>Contains user settings from SMAPI's JSON configuration file.</summary> - internal class UserSettings + /// <summary>The SMAPI configuration settings.</summary> + internal class SConfig { - /********* + /******** ** Accessors - *********/ + ********/ /// <summary>Whether to enable development features.</summary> public bool DeveloperMode { get; set; } /// <summary>Whether to check if a newer version of SMAPI is available on startup.</summary> public bool CheckForUpdates { get; set; } = true; + + /// <summary>A list of mod versions which should be considered compatible or incompatible regardless of whether SMAPI detects incompatible code.</summary> + public ModCompatibility[] ModCompatibility { get; set; } } } |