From 40bc8f57c71d12d49bad24074cfe3279efe12850 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 14 Jan 2017 00:59:19 -0500 Subject: add support for incompatible mod version ranges --- .../Framework/Models/IncompatibleMod.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/StardewModdingAPI/Framework/Models') diff --git a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs index 9bf06552..bcc62bb4 100644 --- a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs +++ b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs @@ -14,8 +14,11 @@ namespace StardewModdingAPI.Framework.Models /// The mod name. public string Name { get; set; } + /// The oldest incompatible mod version, or null for all past versions. + public string LowerVersion { get; set; } + /// The most recent incompatible mod version. - public string Version { get; set; } + public string UpperVersion { get; set; } /// The URL the user can check for an official updated version. public string UpdateUrl { get; set; } @@ -23,7 +26,7 @@ namespace StardewModdingAPI.Framework.Models /// The URL the user can check for an unofficial updated version. public string UnofficialUpdateUrl { get; set; } - /// A regular expression matching version strings to consider compatible, even if they technically precede . + /// A regular expression matching version strings to consider compatible, even if they technically precede . public string ForceCompatibleVersion { get; set; } @@ -34,14 +37,17 @@ namespace StardewModdingAPI.Framework.Models /// The current version of the matching mod. public bool IsCompatible(ISemanticVersion version) { - ISemanticVersion incompatibleVersion = new SemanticVersion(this.Version); + ISemanticVersion lowerVersion = this.LowerVersion != null ? new SemanticVersion(this.LowerVersion) : null; + ISemanticVersion upperVersion = new SemanticVersion(this.UpperVersion); - // allow newer versions - if (version.IsNewerThan(incompatibleVersion)) + // 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); } } -} \ No newline at end of file +} -- cgit From 0ac9e47ea2af8d09baa2df9568aa30dce790c950 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 14 Jan 2017 01:11:42 -0500 Subject: add support for custom incompatible-mod-version error text --- release-notes.md | 1 + src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs | 4 ++++ src/StardewModdingAPI/Program.cs | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Framework/Models') diff --git a/release-notes.md b/release-notes.md index 6c667c31..bede8849 100644 --- a/release-notes.md +++ b/release-notes.md @@ -10,6 +10,7 @@ For players: For SMAPI developers: * Added support for specifying a lower bound in mod incompatibility data. + * Added support for custom incompatible-mod-version error text. ## 1.5 See [log](https://github.com/Pathoschild/SMAPI/compare/1.4...1.5). diff --git a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs index bcc62bb4..bcf5639c 100644 --- a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs +++ b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs @@ -29,6 +29,10 @@ namespace StardewModdingAPI.Framework.Models /// A regular expression matching version strings to consider compatible, even if they technically precede . public string ForceCompatibleVersion { get; set; } + /// The reason phrase to show in the warning, or null to use the default value. + /// "this version is incompatible with the latest version of the game" + public string ReasonPhrase { get; set; } + /********* ** Public methods diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 9d08c823..e5c27e71 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -402,7 +402,8 @@ namespace StardewModdingAPI { if (!compatibility.IsCompatible(manifest.Version)) { - string warning = $"Skipped {compatibility.Name} {manifest.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:"; + string reasonPhrase = compatibility.ReasonPhrase ?? "this version is not compatible with the latest version of the game"; + string warning = $"Skipped {compatibility.Name} {manifest.Version} because {reasonPhrase}. Please check for a newer version of the mod here:"; if (!string.IsNullOrWhiteSpace(compatibility.UpdateUrl)) warning += $"{Environment.NewLine}- official mod: {compatibility.UpdateUrl}"; if (!string.IsNullOrWhiteSpace(compatibility.UnofficialUpdateUrl)) -- cgit