From 5ff3184c301d382f6be528486bdd3139ef2ee2ff Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Apr 2017 21:59:54 -0400 Subject: add version.IsBetween method (#263) --- src/StardewModdingAPI/ISemanticVersion.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/StardewModdingAPI/ISemanticVersion.cs') diff --git a/src/StardewModdingAPI/ISemanticVersion.cs b/src/StardewModdingAPI/ISemanticVersion.cs index 3b9bdb44..24e6442a 100644 --- a/src/StardewModdingAPI/ISemanticVersion.cs +++ b/src/StardewModdingAPI/ISemanticVersion.cs @@ -32,6 +32,11 @@ namespace StardewModdingAPI /// The version to compare with this instance. bool IsNewerThan(ISemanticVersion other); + /// Get whether this version is between two specified versions (inclusively). + /// The minimum version. + /// The maximum version. + bool IsBetween(ISemanticVersion min, ISemanticVersion max); + /// Get a string representation of the version. string ToString(); } -- cgit From 085ae07251c9972bed941e33103f41724d8cd320 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Apr 2017 22:04:56 -0400 Subject: add string overloads for version methods (#263) --- release-notes.md | 5 +++-- src/StardewModdingAPI/ISemanticVersion.cs | 16 ++++++++++++++++ src/StardewModdingAPI/SemanticVersion.cs | 27 ++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) (limited to 'src/StardewModdingAPI/ISemanticVersion.cs') diff --git a/release-notes.md b/release-notes.md index fe55ed10..628757ae 100644 --- a/release-notes.md +++ b/release-notes.md @@ -20,10 +20,11 @@ For players: * Fixed rare issue where the installer would crash trying to delete a bundled mod from `%appdata%`. For mod developers: +* Mods are now initialised after the `Initialize`/`LoadContent` phase, which means the `GameEvents.Initialize` and `GameEvents.LoadContent` events are deprecated. You can move any logic in those methods to your mod's `Entry` method. +* Mods can now specify a minimum game version in their `manifest.json`. +* Added `IsBetween` and string overloads to the `ISemanticVersion` methods. * Fixed mouse-changed event never updating prior mouse position. * Fixed `monitor.ExitGameImmediately` not working correctly. -* Mods can now specify a minimum game version in their `manifest.json`. -* Mods are now initialised after the `Initialize`/`LoadContent` phase, which means the `GameEvents.Initialize` and `GameEvents.LoadContent` events are deprecated. You can move any logic in those methods to your mod's `Entry` method. ## 1.9 See [log](https://github.com/Pathoschild/SMAPI/compare/1.8...1.9). diff --git a/src/StardewModdingAPI/ISemanticVersion.cs b/src/StardewModdingAPI/ISemanticVersion.cs index 24e6442a..27a2f67d 100644 --- a/src/StardewModdingAPI/ISemanticVersion.cs +++ b/src/StardewModdingAPI/ISemanticVersion.cs @@ -28,15 +28,31 @@ namespace StardewModdingAPI /// The version to compare with this instance. bool IsOlderThan(ISemanticVersion other); + /// Get whether this version is older than the specified version. + /// The version to compare with this instance. + /// The specified version is not a valid semantic version. + bool IsOlderThan(string other); + /// Get whether this version is newer than the specified version. /// The version to compare with this instance. bool IsNewerThan(ISemanticVersion other); + /// Get whether this version is newer than the specified version. + /// The version to compare with this instance. + /// The specified version is not a valid semantic version. + bool IsNewerThan(string other); + /// Get whether this version is between two specified versions (inclusively). /// The minimum version. /// The maximum version. bool IsBetween(ISemanticVersion min, ISemanticVersion max); + /// Get whether this version is between two specified versions (inclusively). + /// The minimum version. + /// The maximum version. + /// One of the specified versions is not a valid semantic version. + bool IsBetween(string min, string max); + /// Get a string representation of the version. string ToString(); } diff --git a/src/StardewModdingAPI/SemanticVersion.cs b/src/StardewModdingAPI/SemanticVersion.cs index f6bfb04d..db25dc11 100644 --- a/src/StardewModdingAPI/SemanticVersion.cs +++ b/src/StardewModdingAPI/SemanticVersion.cs @@ -67,7 +67,7 @@ namespace StardewModdingAPI /// The implementation is defined by Semantic Version 2.0 (http://semver.org/). public int CompareTo(ISemanticVersion other) { - if(other == null) + if (other == null) throw new ArgumentNullException(nameof(other)); const int same = 0; @@ -127,6 +127,14 @@ namespace StardewModdingAPI return this.CompareTo(other) < 0; } + /// Get whether this version is older than the specified version. + /// The version to compare with this instance. + /// The specified version is not a valid semantic version. + public bool IsOlderThan(string other) + { + return this.IsOlderThan(new SemanticVersion(other)); + } + /// Get whether this version is newer than the specified version. /// The version to compare with this instance. public bool IsNewerThan(ISemanticVersion other) @@ -134,6 +142,14 @@ namespace StardewModdingAPI return this.CompareTo(other) > 0; } + /// Get whether this version is newer than the specified version. + /// The version to compare with this instance. + /// The specified version is not a valid semantic version. + public bool IsNewerThan(string other) + { + return this.IsNewerThan(new SemanticVersion(other)); + } + /// Get whether this version is between two specified versions (inclusively). /// The minimum version. /// The maximum version. @@ -142,6 +158,15 @@ namespace StardewModdingAPI return this.CompareTo(min) >= 0 && this.CompareTo(max) <= 0; } + /// Get whether this version is between two specified versions (inclusively). + /// The minimum version. + /// The maximum version. + /// One of the specified versions is not a valid semantic version. + public bool IsBetween(string min, string max) + { + return this.IsBetween(new SemanticVersion(min), new SemanticVersion(max)); + } + /// Get a string representation of the version. public override string ToString() { -- cgit