diff options
-rw-r--r-- | src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj | 4 | ||||
-rw-r--r-- | src/SMAPI.Web/Controllers/IndexController.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/Constants.cs | 16 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/Rewriters/TypeReferenceRewriter.cs | 11 | ||||
-rw-r--r-- | src/SMAPI/Metadata/InstructionMetadata.cs | 3 | ||||
-rw-r--r-- | src/SMAPI/Program.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/SemanticVersion.cs | 31 | ||||
-rw-r--r-- | src/SMAPI/StardewModdingAPI.csproj | 1 | ||||
-rw-r--r-- | src/StardewModdingAPI.Toolkit.CoreInterfaces/ISemanticVersion.cs (renamed from src/SMAPI/ISemanticVersion.cs) | 0 | ||||
-rw-r--r-- | src/StardewModdingAPI.Toolkit/ISemanticVersion.cs | 46 | ||||
-rw-r--r-- | src/StardewModdingAPI.Toolkit/SemanticVersion.cs | 95 |
11 files changed, 96 insertions, 115 deletions
diff --git a/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj b/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj index 44fff536..afba15a1 100644 --- a/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj +++ b/src/SMAPI.Mods.SaveBackup/StardewModdingAPI.Mods.SaveBackup.csproj @@ -51,6 +51,10 @@ <Name>StardewModdingAPI</Name> <Private>False</Private> </ProjectReference> + <ProjectReference Include="..\StardewModdingAPI.Toolkit.CoreInterfaces\StardewModdingAPI.Toolkit.CoreInterfaces.csproj"> + <Project>{d5cfd923-37f1-4bc3-9be8-e506e202ac28}</Project> + <Name>StardewModdingAPI.Toolkit.CoreInterfaces</Name> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\build\common.targets" /> diff --git a/src/SMAPI.Web/Controllers/IndexController.cs b/src/SMAPI.Web/Controllers/IndexController.cs index f4ade7de..09bad112 100644 --- a/src/SMAPI.Web/Controllers/IndexController.cs +++ b/src/SMAPI.Web/Controllers/IndexController.cs @@ -130,7 +130,7 @@ namespace StardewModdingAPI.Web.Controllers Match match = Regex.Match(asset.FileName, @"SMAPI-(?<version>[\d\.]+(?:-.+)?)-installer(?<forDevs>-for-developers)?.zip"); if (!match.Success || !SemanticVersion.TryParse(match.Groups["version"].Value, out ISemanticVersion version)) continue; - bool isBeta = version.Tag != null; + bool isBeta = version.IsPrerelease(); bool isForDevs = match.Groups["forDevs"].Success; yield return new ReleaseVersion(release, asset, version, isBeta, isForDevs); diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 65ca7866..df70d603 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -38,10 +38,10 @@ namespace StardewModdingAPI ** Public ****/ /// <summary>SMAPI's current semantic version.</summary> - public static ISemanticVersion ApiVersion { get; } + public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion("2.6-beta.17"); /// <summary>The minimum supported version of Stardew Valley.</summary> - public static ISemanticVersion MinimumGameVersion { get; } + public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.3.21"); /// <summary>The maximum supported version of Stardew Valley.</summary> public static ISemanticVersion MaximumGameVersion { get; } = null; @@ -70,9 +70,6 @@ namespace StardewModdingAPI /**** ** Internal ****/ - /// <summary>SMAPI's current semantic version as a mod toolkit version.</summary> - internal static Toolkit.ISemanticVersion ApiVersionForToolkit { get; } - /// <summary>The URL of the SMAPI home page.</summary> internal const string HomePageUrl = "https://smapi.io"; @@ -113,15 +110,6 @@ namespace StardewModdingAPI /********* ** Internal methods *********/ - /// <summary>Initialise the static values.</summary> - static Constants() - { - Constants.ApiVersionForToolkit = new Toolkit.SemanticVersion("2.6-beta.17"); - Constants.MinimumGameVersion = new GameVersion("1.3.20"); - - Constants.ApiVersion = new SemanticVersion(Constants.ApiVersionForToolkit); - } - /// <summary>Get metadata for mapping assemblies to the current platform.</summary> /// <param name="targetPlatform">The target game platform.</param> internal static PlatformAssemblyMap GetAssemblyMap(Platform targetPlatform) diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/TypeReferenceRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/TypeReferenceRewriter.cs index 5c7db902..de9c439a 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/TypeReferenceRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/TypeReferenceRewriter.cs @@ -17,6 +17,9 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters /// <summary>The new type to reference.</summary> private readonly Type ToType; + /// <summary>A lambda which indicates whether a matching type reference should be rewritten.</summary> + private readonly Func<TypeReference, bool> ShouldRewrite; + /********* ** Public methods @@ -24,11 +27,13 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters /// <summary>Construct an instance.</summary> /// <param name="fromTypeFullName">The full type name to which to find references.</param> /// <param name="toType">The new type to reference.</param> - public TypeReferenceRewriter(string fromTypeFullName, Type toType) + /// <param name="shouldRewrite">A lambda which indicates whether a matching type reference should be rewritten.</param> + public TypeReferenceRewriter(string fromTypeFullName, Type toType, Func<TypeReference, bool> shouldRewrite = null) : base(fromTypeFullName, InstructionHandleResult.None) { this.FromTypeName = fromTypeFullName; this.ToType = toType; + this.ShouldRewrite = shouldRewrite ?? (type => true); } /// <summary>Perform the predefined logic for a method if applicable.</summary> @@ -135,7 +140,11 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters { // root type if (type.FullName == this.FromTypeName) + { + if (!this.ShouldRewrite(type)) + return type; return module.ImportReference(this.ToType); + } // generic arguments if (type is GenericInstanceType genericType) diff --git a/src/SMAPI/Metadata/InstructionMetadata.cs b/src/SMAPI/Metadata/InstructionMetadata.cs index 1063ae71..543d44a7 100644 --- a/src/SMAPI/Metadata/InstructionMetadata.cs +++ b/src/SMAPI/Metadata/InstructionMetadata.cs @@ -37,6 +37,9 @@ namespace StardewModdingAPI.Metadata // rewrite for SMAPI 2.0 new VirtualEntryCallRemover(), + // rewrite for SMAPI 2.6 + new TypeReferenceRewriter("StardewModdingAPI.ISemanticVersion", typeof(ISemanticVersion), type => type.Scope.Name == "StardewModdingAPI"), // moved to SMAPI.Toolkit.CoreInterfaces + // rewrite for Stardew Valley 1.3 new StaticFieldToConstantRewriter<int>(typeof(Game1), "tileSize", Game1.tileSize), diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 7b5176a0..a51d6380 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -585,7 +585,7 @@ namespace StardewModdingAPI #if !SMAPI_FOR_WINDOWS url = url.Replace("https://", "http://"); // workaround for OpenSSL issues with the game's bundled Mono on Linux/Mac #endif - WebApiClient client = new WebApiClient(url, Constants.ApiVersionForToolkit); + WebApiClient client = new WebApiClient(url, Constants.ApiVersion); this.Monitor.Log("Checking for updates...", LogLevel.Trace); // check SMAPI version diff --git a/src/SMAPI/SemanticVersion.cs b/src/SMAPI/SemanticVersion.cs index c4dd1912..587ff286 100644 --- a/src/SMAPI/SemanticVersion.cs +++ b/src/SMAPI/SemanticVersion.cs @@ -10,23 +10,23 @@ namespace StardewModdingAPI ** Properties *********/ /// <summary>The underlying semantic version implementation.</summary> - private readonly Toolkit.ISemanticVersion Version; + private readonly ISemanticVersion Version; /********* ** Accessors *********/ /// <summary>The major version incremented for major API changes.</summary> - public int MajorVersion => this.Version.Major; + public int MajorVersion => this.Version.MajorVersion; /// <summary>The minor version incremented for backwards-compatible changes.</summary> - public int MinorVersion => this.Version.Minor; + public int MinorVersion => this.Version.MinorVersion; /// <summary>The patch version for backwards-compatible bug fixes.</summary> - public int PatchVersion => this.Version.Patch; + public int PatchVersion => this.Version.PatchVersion; /// <summary>An optional build tag.</summary> - public string Build => this.Version.Tag; + public string Build => this.Version.Build; /********* @@ -56,7 +56,7 @@ namespace StardewModdingAPI /// <summary>Construct an instance.</summary> /// <param name="version">The underlying semantic version implementation.</param> - internal SemanticVersion(Toolkit.ISemanticVersion version) + internal SemanticVersion(ISemanticVersion version) { this.Version = version; } @@ -64,7 +64,7 @@ namespace StardewModdingAPI /// <summary>Whether this is a pre-release version.</summary> public bool IsPrerelease() { - return !string.IsNullOrWhiteSpace(this.Build); + return this.Version.IsPrerelease(); } /// <summary>Get an integer indicating whether this version precedes (less than 0), supercedes (more than 0), or is equivalent to (0) the specified version.</summary> @@ -73,15 +73,14 @@ namespace StardewModdingAPI /// <remarks>The implementation is defined by Semantic Version 2.0 (http://semver.org/).</remarks> public int CompareTo(ISemanticVersion other) { - Toolkit.ISemanticVersion toolkitOther = new Toolkit.SemanticVersion(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.Build); - return this.Version.CompareTo(toolkitOther); + return this.Version.CompareTo(other); } /// <summary>Get whether this version is older than the specified version.</summary> /// <param name="other">The version to compare with this instance.</param> public bool IsOlderThan(ISemanticVersion other) { - return this.CompareTo(other) < 0; + return this.Version.IsOlderThan(other); } /// <summary>Get whether this version is older than the specified version.</summary> @@ -89,14 +88,14 @@ namespace StardewModdingAPI /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception> public bool IsOlderThan(string other) { - return this.IsOlderThan(new SemanticVersion(other)); + return this.Version.IsOlderThan(other); } /// <summary>Get whether this version is newer than the specified version.</summary> /// <param name="other">The version to compare with this instance.</param> public bool IsNewerThan(ISemanticVersion other) { - return this.CompareTo(other) > 0; + return this.Version.IsNewerThan(other); } /// <summary>Get whether this version is newer than the specified version.</summary> @@ -104,7 +103,7 @@ namespace StardewModdingAPI /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception> public bool IsNewerThan(string other) { - return this.IsNewerThan(new SemanticVersion(other)); + return this.Version.IsNewerThan(other); } /// <summary>Get whether this version is between two specified versions (inclusively).</summary> @@ -112,7 +111,7 @@ namespace StardewModdingAPI /// <param name="max">The maximum version.</param> public bool IsBetween(ISemanticVersion min, ISemanticVersion max) { - return this.CompareTo(min) >= 0 && this.CompareTo(max) <= 0; + return this.Version.IsBetween(min, max); } /// <summary>Get whether this version is between two specified versions (inclusively).</summary> @@ -121,7 +120,7 @@ namespace StardewModdingAPI /// <exception cref="FormatException">One of the specified versions is not a valid semantic version.</exception> public bool IsBetween(string min, string max) { - return this.IsBetween(new SemanticVersion(min), new SemanticVersion(max)); + return this.Version.IsBetween(min, max); } /// <summary>Indicates whether the current object is equal to another object of the same type.</summary> @@ -144,7 +143,7 @@ namespace StardewModdingAPI /// <returns>Returns whether parsing the version succeeded.</returns> internal static bool TryParse(string version, out ISemanticVersion parsed) { - if (Toolkit.SemanticVersion.TryParse(version, out Toolkit.ISemanticVersion versionImpl)) + if (Toolkit.SemanticVersion.TryParse(version, out ISemanticVersion versionImpl)) { parsed = new SemanticVersion(versionImpl); return true; diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index a429d204..c872391c 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -280,7 +280,6 @@ <Compile Include="IModHelper.cs" /> <Compile Include="IModLinked.cs" /> <Compile Include="Framework\Logging\LogFileManager.cs" /> - <Compile Include="ISemanticVersion.cs" /> <Compile Include="ITranslationHelper.cs" /> <Compile Include="LogLevel.cs" /> <Compile Include="Framework\ModRegistry.cs" /> diff --git a/src/SMAPI/ISemanticVersion.cs b/src/StardewModdingAPI.Toolkit.CoreInterfaces/ISemanticVersion.cs index 961ef777..961ef777 100644 --- a/src/SMAPI/ISemanticVersion.cs +++ b/src/StardewModdingAPI.Toolkit.CoreInterfaces/ISemanticVersion.cs diff --git a/src/StardewModdingAPI.Toolkit/ISemanticVersion.cs b/src/StardewModdingAPI.Toolkit/ISemanticVersion.cs deleted file mode 100644 index ca62d393..00000000 --- a/src/StardewModdingAPI.Toolkit/ISemanticVersion.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; - -namespace StardewModdingAPI.Toolkit -{ - /// <summary>A semantic version with an optional release tag.</summary> - public interface ISemanticVersion : IComparable<ISemanticVersion>, IEquatable<ISemanticVersion> - { - /********* - ** Accessors - *********/ - /// <summary>The major version incremented for major API changes.</summary> - int Major { get; } - - /// <summary>The minor version incremented for backwards-compatible changes.</summary> - int Minor { get; } - - /// <summary>The patch version for backwards-compatible bug fixes.</summary> - int Patch { get; } - - /// <summary>An optional prerelease tag.</summary> - string Tag { get; } - - - /********* - ** Accessors - *********/ - /// <summary>Whether this is a pre-release version.</summary> - bool IsPrerelease(); - - /// <summary>Get whether this version is older than the specified version.</summary> - /// <param name="other">The version to compare with this instance.</param> - bool IsOlderThan(ISemanticVersion other); - - /// <summary>Get whether this version is newer than the specified version.</summary> - /// <param name="other">The version to compare with this instance.</param> - bool IsNewerThan(ISemanticVersion other); - - /// <summary>Get whether this version is between two specified versions (inclusively).</summary> - /// <param name="min">The minimum version.</param> - /// <param name="max">The maximum version.</param> - bool IsBetween(ISemanticVersion min, ISemanticVersion max); - - /// <summary>Get a string representation of the version.</summary> - string ToString(); - } -} diff --git a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs index de480416..156d58ce 100644 --- a/src/StardewModdingAPI.Toolkit/SemanticVersion.cs +++ b/src/StardewModdingAPI.Toolkit/SemanticVersion.cs @@ -31,16 +31,16 @@ namespace StardewModdingAPI.Toolkit ** Accessors *********/ /// <summary>The major version incremented for major API changes.</summary> - public int Major { get; } + public int MajorVersion { get; } /// <summary>The minor version incremented for backwards-compatible changes.</summary> - public int Minor { get; } + public int MinorVersion { get; } /// <summary>The patch version for backwards-compatible bug fixes.</summary> - public int Patch { get; } + public int PatchVersion { get; } /// <summary>An optional prerelease tag.</summary> - public string Tag { get; } + public string Build { get; } /********* @@ -53,10 +53,10 @@ namespace StardewModdingAPI.Toolkit /// <param name="tag">An optional prerelease tag.</param> public SemanticVersion(int major, int minor, int patch, string tag = null) { - this.Major = major; - this.Minor = minor; - this.Patch = patch; - this.Tag = this.GetNormalisedTag(tag); + this.MajorVersion = major; + this.MinorVersion = minor; + this.PatchVersion = patch; + this.Build = this.GetNormalisedTag(tag); this.AssertValid(); } @@ -69,9 +69,9 @@ namespace StardewModdingAPI.Toolkit if (version == null) throw new ArgumentNullException(nameof(version), "The input version can't be null."); - this.Major = version.Major; - this.Minor = version.Minor; - this.Patch = version.Build; + this.MajorVersion = version.Major; + this.MinorVersion = version.Minor; + this.PatchVersion = version.Build; this.AssertValid(); } @@ -90,10 +90,10 @@ namespace StardewModdingAPI.Toolkit throw new FormatException($"The input '{version}' isn't a valid semantic version."); // initialise - this.Major = int.Parse(match.Groups["major"].Value); - this.Minor = match.Groups["minor"].Success ? int.Parse(match.Groups["minor"].Value) : 0; - this.Patch = match.Groups["patch"].Success ? int.Parse(match.Groups["patch"].Value) : 0; - this.Tag = match.Groups["prerelease"].Success ? this.GetNormalisedTag(match.Groups["prerelease"].Value) : null; + this.MajorVersion = int.Parse(match.Groups["major"].Value); + this.MinorVersion = match.Groups["minor"].Success ? int.Parse(match.Groups["minor"].Value) : 0; + this.PatchVersion = match.Groups["patch"].Success ? int.Parse(match.Groups["patch"].Value) : 0; + this.Build = match.Groups["prerelease"].Success ? this.GetNormalisedTag(match.Groups["prerelease"].Value) : null; this.AssertValid(); } @@ -105,7 +105,7 @@ namespace StardewModdingAPI.Toolkit { if (other == null) throw new ArgumentNullException(nameof(other)); - return this.CompareTo(other.Major, other.Minor, other.Patch, other.Tag); + return this.CompareTo(other.MajorVersion, other.MinorVersion, other.PatchVersion, other.Build); } /// <summary>Indicates whether the current object is equal to another object of the same type.</summary> @@ -119,7 +119,7 @@ namespace StardewModdingAPI.Toolkit /// <summary>Whether this is a pre-release version.</summary> public bool IsPrerelease() { - return !string.IsNullOrWhiteSpace(this.Tag); + return !string.IsNullOrWhiteSpace(this.Build); } /// <summary>Get whether this version is older than the specified version.</summary> @@ -129,6 +129,14 @@ namespace StardewModdingAPI.Toolkit return this.CompareTo(other) < 0; } + /// <summary>Get whether this version is older than the specified version.</summary> + /// <param name="other">The version to compare with this instance.</param> + /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception> + public bool IsOlderThan(string other) + { + return this.IsOlderThan(new SemanticVersion(other)); + } + /// <summary>Get whether this version is newer than the specified version.</summary> /// <param name="other">The version to compare with this instance.</param> public bool IsNewerThan(ISemanticVersion other) @@ -136,6 +144,14 @@ namespace StardewModdingAPI.Toolkit return this.CompareTo(other) > 0; } + /// <summary>Get whether this version is newer than the specified version.</summary> + /// <param name="other">The version to compare with this instance.</param> + /// <exception cref="FormatException">The specified version is not a valid semantic version.</exception> + public bool IsNewerThan(string other) + { + return this.IsNewerThan(new SemanticVersion(other)); + } + /// <summary>Get whether this version is between two specified versions (inclusively).</summary> /// <param name="min">The minimum version.</param> /// <param name="max">The maximum version.</param> @@ -144,16 +160,25 @@ namespace StardewModdingAPI.Toolkit return this.CompareTo(min) >= 0 && this.CompareTo(max) <= 0; } + /// <summary>Get whether this version is between two specified versions (inclusively).</summary> + /// <param name="min">The minimum version.</param> + /// <param name="max">The maximum version.</param> + /// <exception cref="FormatException">One of the specified versions is not a valid semantic version.</exception> + public bool IsBetween(string min, string max) + { + return this.IsBetween(new SemanticVersion(min), new SemanticVersion(max)); + } + /// <summary>Get a string representation of the version.</summary> public override string ToString() { // version - string result = this.Patch != 0 - ? $"{this.Major}.{this.Minor}.{this.Patch}" - : $"{this.Major}.{this.Minor}"; + string result = this.PatchVersion != 0 + ? $"{this.MajorVersion}.{this.MinorVersion}.{this.PatchVersion}" + : $"{this.MajorVersion}.{this.MinorVersion}"; // tag - string tag = this.Tag; + string tag = this.Build; if (tag != null) result += $"-{tag}"; return result; @@ -201,17 +226,17 @@ namespace StardewModdingAPI.Toolkit const int curOlder = -1; // compare stable versions - if (this.Major != otherMajor) - return this.Major.CompareTo(otherMajor); - if (this.Minor != otherMinor) - return this.Minor.CompareTo(otherMinor); - if (this.Patch != otherPatch) - return this.Patch.CompareTo(otherPatch); - if (this.Tag == otherTag) + if (this.MajorVersion != otherMajor) + return this.MajorVersion.CompareTo(otherMajor); + if (this.MinorVersion != otherMinor) + return this.MinorVersion.CompareTo(otherMinor); + if (this.PatchVersion != otherPatch) + return this.PatchVersion.CompareTo(otherPatch); + if (this.Build == otherTag) return same; // stable supercedes pre-release - bool curIsStable = string.IsNullOrWhiteSpace(this.Tag); + bool curIsStable = string.IsNullOrWhiteSpace(this.Build); bool otherIsStable = string.IsNullOrWhiteSpace(otherTag); if (curIsStable) return curNewer; @@ -219,7 +244,7 @@ namespace StardewModdingAPI.Toolkit return curOlder; // compare two pre-release tag values - string[] curParts = this.Tag.Split('.', '-'); + string[] curParts = this.Build.Split('.', '-'); string[] otherParts = otherTag.Split('.', '-'); for (int i = 0; i < curParts.Length; i++) { @@ -248,15 +273,15 @@ namespace StardewModdingAPI.Toolkit /// <summary>Assert that the current version is valid.</summary> private void AssertValid() { - if (this.Major < 0 || this.Minor < 0 || this.Patch < 0) + if (this.MajorVersion < 0 || this.MinorVersion < 0 || this.PatchVersion < 0) throw new FormatException($"{this} isn't a valid semantic version. The major, minor, and patch numbers can't be negative."); - if (this.Major == 0 && this.Minor == 0 && this.Patch == 0) + if (this.MajorVersion == 0 && this.MinorVersion == 0 && this.PatchVersion == 0) throw new FormatException($"{this} isn't a valid semantic version. At least one of the major, minor, and patch numbers must be more than zero."); - if (this.Tag != null) + if (this.Build != null) { - if (this.Tag.Trim() == "") + if (this.Build.Trim() == "") throw new FormatException($"{this} isn't a valid semantic version. The tag cannot be a blank string (but may be omitted)."); - if (!Regex.IsMatch(this.Tag, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase)) + if (!Regex.IsMatch(this.Build, $"^{SemanticVersion.TagPattern}$", RegexOptions.IgnoreCase)) throw new FormatException($"{this} isn't a valid semantic version. The tag is invalid."); } } |