diff options
-rw-r--r-- | release-notes.md | 1 | ||||
-rw-r--r-- | src/StardewModdingAPI/Version.cs | 27 |
2 files changed, 26 insertions, 2 deletions
diff --git a/release-notes.md b/release-notes.md index 64e65ebd..e04c284a 100644 --- a/release-notes.md +++ b/release-notes.md @@ -5,6 +5,7 @@ * Added support for Linux and Mac. * Added zoom-adjusted mouse position to mouse-changed event arguments. * Added OS version to log. + * Switched to [semantic versioning](http://semver.org). * Fixed mod versions not being displayed correctly on log. * Fixed misspelled field in `manifest.json` schema. * Fixed several events not correctly propagating state. diff --git a/src/StardewModdingAPI/Version.cs b/src/StardewModdingAPI/Version.cs index cce68ad8..db5a21d4 100644 --- a/src/StardewModdingAPI/Version.cs +++ b/src/StardewModdingAPI/Version.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json; namespace StardewModdingAPI { - /// <summary>A semantic mod version with an optional build tag.</summary> + /// <summary>A semantic version with an optional release tag.</summary> public struct Version { /********* @@ -46,7 +46,30 @@ namespace StardewModdingAPI /// <summary>Get a string representation of the version.</summary> public override string ToString() { - return $"{this.MajorVersion}.{this.MinorVersion}.{this.PatchVersion} {this.Build}".Trim(); + // version + string result = this.PatchVersion != 0 + ? $"{this.MajorVersion}.{this.MinorVersion}.{this.PatchVersion}" + : $"{this.MajorVersion}.{this.MinorVersion}"; + + // tag + string tag = this.GetNormalisedTag(this.Build); + if (tag != null) + result += $"-{tag}"; + return result; + } + + + /********* + ** Private methods + *********/ + /// <summary>Get a normalised build tag.</summary> + /// <param name="tag">The tag to normalise.</param> + private string GetNormalisedTag(string tag) + { + tag = tag?.Trim().Trim('-'); + if (string.IsNullOrWhiteSpace(tag) || tag == "0") + return null; + return tag; } } } |