diff options
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Framework/GameVersion.cs | 20 | ||||
-rw-r--r-- | src/SMAPI/SemanticVersion.cs | 10 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/SMAPI/Framework/GameVersion.cs b/src/SMAPI/Framework/GameVersion.cs index cd88895c..29cfbc39 100644 --- a/src/SMAPI/Framework/GameVersion.cs +++ b/src/SMAPI/Framework/GameVersion.cs @@ -52,20 +52,34 @@ namespace StardewModdingAPI.Framework /// <param name="gameVersion">The game version string.</param> private static string GetSemanticVersionString(string gameVersion) { - return GameVersion.VersionMap.TryGetValue(gameVersion, out string semanticVersion) - ? semanticVersion - : gameVersion; + // mapped version + if (GameVersion.VersionMap.TryGetValue(gameVersion, out string semanticVersion)) + return semanticVersion; + + // special case: four-part versions + string[] parts = gameVersion.Split('.'); + if (parts.Length == 4) + return $"{parts[0]}.{parts[1]}.{parts[2]}+{parts[3]}"; + + return gameVersion; } /// <summary>Convert a semantic version string to the equivalent game version string.</summary> /// <param name="semanticVersion">The semantic version string.</param> private static string GetGameVersionString(string semanticVersion) { + // mapped versions foreach (var mapping in GameVersion.VersionMap) { if (mapping.Value.Equals(semanticVersion, StringComparison.InvariantCultureIgnoreCase)) return mapping.Key; } + + // special case: four-part versions + string[] parts = semanticVersion.Split('.', '+'); + if (parts.Length == 4) + return $"{parts[0]}.{parts[1]}.{parts[2]}.{parts[3]}"; + return semanticVersion; } } diff --git a/src/SMAPI/SemanticVersion.cs b/src/SMAPI/SemanticVersion.cs index 0db41673..2a33ecef 100644 --- a/src/SMAPI/SemanticVersion.cs +++ b/src/SMAPI/SemanticVersion.cs @@ -28,6 +28,9 @@ namespace StardewModdingAPI /// <summary>An optional prerelease tag.</summary> public string PrereleaseTag => this.Version.PrereleaseTag; + /// <summary>Optional build metadata. This is ignored when determining version precedence.</summary> + public string BuildMetadata => this.Version.BuildMetadata; + /********* ** Public methods @@ -36,10 +39,11 @@ namespace StardewModdingAPI /// <param name="majorVersion">The major version incremented for major API changes.</param> /// <param name="minorVersion">The minor version incremented for backwards-compatible changes.</param> /// <param name="patchVersion">The patch version for backwards-compatible bug fixes.</param> - /// <param name="build">An optional build tag.</param> + /// <param name="prerelease">An optional prerelease tag.</param> + /// <param name="build">Optional build metadata. This is ignored when determining version precedence.</param> [JsonConstructor] - public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, string build = null) - : this(new Toolkit.SemanticVersion(majorVersion, minorVersion, patchVersion, build)) { } + public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, string prerelease = null, string build = null) + : this(new Toolkit.SemanticVersion(majorVersion, minorVersion, patchVersion, prerelease, build)) { } /// <summary>Construct an instance.</summary> /// <param name="version">The semantic version string.</param> |