From a6071feaf84518c436fba0d148e3ea7d547663da Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 2 Nov 2017 01:34:21 -0400 Subject: fix custom asset loads failing on Linux/Mac (#383) --- src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 22 +---------- src/SMAPI/Framework/SContentManager.cs | 52 ++++++++++++------------- 2 files changed, 28 insertions(+), 46 deletions(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index be9594ee..7665eb78 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -26,9 +26,6 @@ namespace StardewModdingAPI.Framework.ModHelpers /// The absolute path to the mod folder. private readonly string ModFolderPath; - /// The path to the mod's folder, relative to the game's content folder (e.g. "../Mods/ModName"). - private readonly string ModFolderPathFromContent; - /// The friendly mod name for use in errors. private readonly string ModName; @@ -73,7 +70,6 @@ namespace StardewModdingAPI.Framework.ModHelpers this.ContentManager = contentManager; this.ModFolderPath = modFolderPath; this.ModName = modName; - this.ModFolderPathFromContent = this.ContentManager.GetRelativePath(modFolderPath); this.Monitor = monitor; } @@ -102,7 +98,7 @@ namespace StardewModdingAPI.Framework.ModHelpers throw GetContentError($"there's no matching file at path '{file.FullName}'."); // get asset path - string assetName = this.GetModAssetPath(key, file.FullName); + string assetName = this.ContentManager.GetAssetNameFromFilePath(file.FullName); // try cache if (this.ContentManager.IsLoaded(assetName)) @@ -151,7 +147,7 @@ namespace StardewModdingAPI.Framework.ModHelpers case ContentSource.ModFolder: FileInfo file = this.GetModFile(key); - return this.ContentManager.NormaliseAssetName(this.GetModAssetPath(key, file.FullName)); + return this.ContentManager.NormaliseAssetName(this.ContentManager.GetAssetNameFromFilePath(file.FullName)); default: throw new NotSupportedException($"Unknown content source '{source}'."); @@ -356,19 +352,5 @@ namespace StardewModdingAPI.Framework.ModHelpers // get file return new FileInfo(path); } - - /// Get the asset path which loads a mod folder through a content manager. - /// The file path relative to the mod's folder. - /// The absolute file path. - private string GetModAssetPath(string localPath, string absolutePath) - { -#if SMAPI_FOR_WINDOWS - // XNA doesn't allow absolute asset paths, so get a path relative to the content folder - return Path.Combine(this.ModFolderPathFromContent, localPath); -#else - // MonoGame is weird about relative paths on Mac, but allows absolute paths - return absolutePath; -#endif - } } } diff --git a/src/SMAPI/Framework/SContentManager.cs b/src/SMAPI/Framework/SContentManager.cs index a755a6df..524b2d17 100644 --- a/src/SMAPI/Framework/SContentManager.cs +++ b/src/SMAPI/Framework/SContentManager.cs @@ -102,7 +102,7 @@ namespace StardewModdingAPI.Framework this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor)); this.Cache = new ContentCache(this, reflection, SContentManager.PossiblePathSeparators, SContentManager.PreferredPathSeparator); this.GetKeyLocale = reflection.GetPrivateMethod(this, "languageCode"); - this.ModContentPrefix = this.GetRelativePath(Constants.ModPath); + this.ModContentPrefix = this.GetAssetNameFromFilePath(Constants.ModPath); // get asset data this.CoreAssets = new CoreAssets(this.NormaliseAssetName); @@ -140,19 +140,17 @@ namespace StardewModdingAPI.Framework throw new ArgumentException("The asset key or local path contains invalid characters."); } - /// Get a directory path relative to the content root. - /// The target file path. - public string GetRelativePath(string targetPath) + /// Convert an absolute file path into a appropriate asset name. + /// The absolute path to the file. + public string GetAssetNameFromFilePath(string absolutePath) { - // convert to URIs - Uri from = new Uri(this.FullRootDirectory + "/"); - Uri to = new Uri(targetPath + "/"); - if (from.Scheme != to.Scheme) - throw new InvalidOperationException($"Can't get path for '{targetPath}' relative to '{this.FullRootDirectory}'."); - - // get relative path - return Uri.UnescapeDataString(from.MakeRelativeUri(to).ToString()) - .Replace(Path.DirectorySeparatorChar == '/' ? '\\' : '/', Path.DirectorySeparatorChar); // use correct separator for platform +#if SMAPI_FOR_WINDOWS + // XNA doesn't allow absolute asset paths, so get a path relative to the content folder + return this.GetRelativePath(absolutePath); +#else + // MonoGame is weird about relative paths on Mac, but allows absolute paths + return absolutePath; +#endif } /**** @@ -395,6 +393,21 @@ namespace StardewModdingAPI.Framework /**** ** Asset name/key handling ****/ + /// Get a directory or file path relative to the content root. + /// The target file path. + private string GetRelativePath(string targetPath) + { + // convert to URIs + Uri from = new Uri(this.FullRootDirectory + "/"); + Uri to = new Uri(targetPath + "/"); + if (from.Scheme != to.Scheme) + throw new InvalidOperationException($"Can't get path for '{targetPath}' relative to '{this.FullRootDirectory}'."); + + // get relative path + return Uri.UnescapeDataString(from.MakeRelativeUri(to).ToString()) + .Replace(Path.DirectorySeparatorChar == '/' ? '\\' : '/', Path.DirectorySeparatorChar); // use correct separator for platform + } + /// Get the locale codes (like ja-JP) used in asset keys. /// Simplifies access to private game code. private IDictionary GetKeyLocales(Reflector reflection) @@ -551,19 +564,6 @@ namespace StardewModdingAPI.Framework return file; } - /// Get a file from the game's content folder. - /// The asset key. - private FileInfo GetContentFolderFile(string key) - { - // get file path - string path = Path.Combine(this.FullRootDirectory, key); - if (!path.EndsWith(".xnb")) - path += ".xnb"; - - // get file - return new FileInfo(path); - } - /// Load the initial asset from the registered . /// The basic asset metadata. /// Returns the loaded asset metadata, or null if no loader matched. -- cgit From 7dc7f010a64ef0cf057a67bbee85196ce1d695c0 Mon Sep 17 00:00:00 2001 From: YonKuma Date: Wed, 8 Nov 2017 22:51:25 -0500 Subject: Added code to suppress mouse clicks issue Pathoschild/SMAPI#384 --- src/SMAPI/Events/EventArgsInput.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index ff904675..0df5275b 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -127,6 +127,37 @@ namespace StardewModdingAPI.Events Game1.oldPadState = new GamePadState(thumbsticks, triggers, buttons, dpad); } + + // mouse + else if (button.TryGetStardewInput(out InputButton inputButton)) + { + if (inputButton.mouseLeft) + { + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + ButtonState.Pressed, + Game1.oldMouseState.MiddleButton, + Game1.oldMouseState.RightButton, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); + } + else if (inputButton.mouseRight) + { + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + Game1.oldMouseState.LeftButton, + Game1.oldMouseState.MiddleButton, + ButtonState.Pressed, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); + } + } } } } -- cgit From b9ba645ce0cb8fe924e0c8e880ebba3d065558ef Mon Sep 17 00:00:00 2001 From: YonKuma Date: Wed, 8 Nov 2017 22:59:51 -0500 Subject: Fixing code to match SMAPI idiom --- src/SMAPI/Events/EventArgsInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index 0df5275b..bb06430a 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -129,7 +129,7 @@ namespace StardewModdingAPI.Events } // mouse - else if (button.TryGetStardewInput(out InputButton inputButton)) + else if (this.Button.TryGetStardewInput(out InputButton inputButton)) { if (inputButton.mouseLeft) { -- cgit From 4aa3545b58ccda79863d8d2136904f2ff0995cfb Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Wed, 8 Nov 2017 22:52:34 -0800 Subject: Adding a date function --- src/SMAPI/Utilities/SDate.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs index 2630731a..126673eb 100644 --- a/src/SMAPI/Utilities/SDate.cs +++ b/src/SMAPI/Utilities/SDate.cs @@ -95,6 +95,12 @@ namespace StardewModdingAPI.Utilities return $"{this.Day:00} {this.Season} Y{this.Year}"; } + /// This function will return the number of days since Year 1 Spring 0 for an arbitrary date + public static int TotalNumberOfDays(SDate date) + { + return (((date.Year - 1) * 112) + (date.GetSeasonIndex() * 28) + date.Day); + } + /**** ** IEquatable ****/ -- cgit From 0330d84e990883a5bd5f98a70570bde007713414 Mon Sep 17 00:00:00 2001 From: YonKuma Date: Fri, 10 Nov 2017 16:20:25 -0500 Subject: Simplified mouse checks SuppressButton now uses the passed button rather than the object button --- src/SMAPI/Events/EventArgsInput.cs | 55 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index bb06430a..276bfef6 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -56,11 +56,11 @@ namespace StardewModdingAPI.Events public void SuppressButton(SButton button) { // keyboard - if (this.Button.TryGetKeyboard(out Keys key)) + if (button.TryGetKeyboard(out Keys key)) Game1.oldKBState = new KeyboardState(Game1.oldKBState.GetPressedKeys().Union(new[] { key }).ToArray()); // controller - else if (this.Button.TryGetController(out Buttons controllerButton)) + else if (button.TryGetController(out Buttons controllerButton)) { var newState = GamePad.GetState(PlayerIndex.One); var thumbsticks = Game1.oldPadState.ThumbSticks; @@ -129,34 +129,31 @@ namespace StardewModdingAPI.Events } // mouse - else if (this.Button.TryGetStardewInput(out InputButton inputButton)) + else if (button == SButton.MouseLeft) { - if (inputButton.mouseLeft) - { - Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - ButtonState.Pressed, - Game1.oldMouseState.MiddleButton, - Game1.oldMouseState.RightButton, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 - ); - } - else if (inputButton.mouseRight) - { - Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - Game1.oldMouseState.LeftButton, - Game1.oldMouseState.MiddleButton, - ButtonState.Pressed, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 - ); - } + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + ButtonState.Pressed, + Game1.oldMouseState.MiddleButton, + Game1.oldMouseState.RightButton, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); + } + else if (button == SButton.MouseRight) + { + Game1.oldMouseState = new MouseState( + Game1.oldMouseState.X, + Game1.oldMouseState.Y, + Game1.oldMouseState.ScrollWheelValue, + Game1.oldMouseState.LeftButton, + Game1.oldMouseState.MiddleButton, + ButtonState.Pressed, + Game1.oldMouseState.XButton1, + Game1.oldMouseState.XButton2 + ); } } } -- cgit From 3a832b99bf3f82cfe39de776b5e15db6c8ddff1a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 26 Nov 2017 14:54:32 -0500 Subject: add date.DaysSinceStart property, add unit tests, update release notes (#390) --- docs/release-notes.md | 7 +++ src/SMAPI.Tests/Utilities/SDateTests.cs | 53 ++++++++++++++++++++ src/SMAPI/Framework/Models/ManifestDependency.cs | 1 + src/SMAPI/Utilities/SDate.cs | 64 ++++++++++++++---------- 4 files changed, 98 insertions(+), 27 deletions(-) (limited to 'src/SMAPI') diff --git a/docs/release-notes.md b/docs/release-notes.md index 1a9e4681..a74b1927 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,4 +1,11 @@ # Release notes +## 2.2 +* For players: + * Fixed mods crashing when loading a custom asset on Linux/Mac. + +* For modders: + * Added `DaysSinceStart` property to `SDate` dates. + ## 2.1 * For players: * Added a log parser at [log.smapi.io](https://log.smapi.io). diff --git a/src/SMAPI.Tests/Utilities/SDateTests.cs b/src/SMAPI.Tests/Utilities/SDateTests.cs index 86a0d3d0..b89d8857 100644 --- a/src/SMAPI.Tests/Utilities/SDateTests.cs +++ b/src/SMAPI.Tests/Utilities/SDateTests.cs @@ -81,6 +81,59 @@ namespace StardewModdingAPI.Tests.Utilities Assert.Throws(() => _ = new SDate(day, season, year), "Constructing the invalid date didn't throw the expected exception."); } + /**** + ** DayOfWeek + ****/ + [Test(Description = "Assert the day of week.")] + [TestCase("01 spring Y1", ExpectedResult = System.DayOfWeek.Monday)] + [TestCase("02 spring Y2", ExpectedResult = System.DayOfWeek.Tuesday)] + [TestCase("03 spring Y3", ExpectedResult = System.DayOfWeek.Wednesday)] + [TestCase("04 spring Y4", ExpectedResult = System.DayOfWeek.Thursday)] + [TestCase("05 spring Y5", ExpectedResult = System.DayOfWeek.Friday)] + [TestCase("06 spring Y6", ExpectedResult = System.DayOfWeek.Saturday)] + [TestCase("07 spring Y7", ExpectedResult = System.DayOfWeek.Sunday)] + [TestCase("08 summer Y8", ExpectedResult = System.DayOfWeek.Monday)] + [TestCase("09 summer Y9", ExpectedResult = System.DayOfWeek.Tuesday)] + [TestCase("10 summer Y10", ExpectedResult = System.DayOfWeek.Wednesday)] + [TestCase("11 summer Y11", ExpectedResult = System.DayOfWeek.Thursday)] + [TestCase("12 summer Y12", ExpectedResult = System.DayOfWeek.Friday)] + [TestCase("13 summer Y13", ExpectedResult = System.DayOfWeek.Saturday)] + [TestCase("14 summer Y14", ExpectedResult = System.DayOfWeek.Sunday)] + [TestCase("15 fall Y15", ExpectedResult = System.DayOfWeek.Monday)] + [TestCase("16 fall Y16", ExpectedResult = System.DayOfWeek.Tuesday)] + [TestCase("17 fall Y17", ExpectedResult = System.DayOfWeek.Wednesday)] + [TestCase("18 fall Y18", ExpectedResult = System.DayOfWeek.Thursday)] + [TestCase("19 fall Y19", ExpectedResult = System.DayOfWeek.Friday)] + [TestCase("20 fall Y20", ExpectedResult = System.DayOfWeek.Saturday)] + [TestCase("21 fall Y21", ExpectedResult = System.DayOfWeek.Sunday)] + [TestCase("22 winter Y22", ExpectedResult = System.DayOfWeek.Monday)] + [TestCase("23 winter Y23", ExpectedResult = System.DayOfWeek.Tuesday)] + [TestCase("24 winter Y24", ExpectedResult = System.DayOfWeek.Wednesday)] + [TestCase("25 winter Y25", ExpectedResult = System.DayOfWeek.Thursday)] + [TestCase("26 winter Y26", ExpectedResult = System.DayOfWeek.Friday)] + [TestCase("27 winter Y27", ExpectedResult = System.DayOfWeek.Saturday)] + [TestCase("28 winter Y28" + "", ExpectedResult = System.DayOfWeek.Sunday)] + public DayOfWeek DayOfWeek(string dateStr) + { + // act + return this.GetDate(dateStr).DayOfWeek; + } + + /**** + ** DaysSinceStart + ****/ + [Test(Description = "Assert the number of days since 01 spring Y1 (inclusive).")] + [TestCase("01 spring Y1", ExpectedResult = 1)] + [TestCase("02 spring Y1", ExpectedResult = 2)] + [TestCase("28 spring Y1", ExpectedResult = 28)] + [TestCase("01 summer Y1", ExpectedResult = 29)] + [TestCase("01 summer Y2", ExpectedResult = 141)] + public int DaysSinceStart(string dateStr) + { + // act + return this.GetDate(dateStr).DaysSinceStart; + } + /**** ** ToString ****/ diff --git a/src/SMAPI/Framework/Models/ManifestDependency.cs b/src/SMAPI/Framework/Models/ManifestDependency.cs index 5646b335..97f0775a 100644 --- a/src/SMAPI/Framework/Models/ManifestDependency.cs +++ b/src/SMAPI/Framework/Models/ManifestDependency.cs @@ -15,6 +15,7 @@ namespace StardewModdingAPI.Framework.Models /// Whether the dependency must be installed to use the mod. public bool IsRequired { get; set; } + /********* ** Public methods *********/ diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs index 126673eb..e589e9a4 100644 --- a/src/SMAPI/Utilities/SDate.cs +++ b/src/SMAPI/Utilities/SDate.cs @@ -35,6 +35,9 @@ namespace StardewModdingAPI.Utilities /// The day of week. public DayOfWeek DayOfWeek { get; } + /// The number of days since the game began (starting at 1 for the first day of spring in Y1). + public int DaysSinceStart { get; } + /********* ** Public methods @@ -67,7 +70,7 @@ namespace StardewModdingAPI.Utilities public SDate AddDays(int offset) { // get new hash code - int hashCode = this.GetHashCode() + offset; + int hashCode = this.DaysSinceStart + offset; if (hashCode < 1) throw new ArithmeticException($"Adding {offset} days to {this} would result in a date before 01 spring Y1."); @@ -95,12 +98,6 @@ namespace StardewModdingAPI.Utilities return $"{this.Day:00} {this.Season} Y{this.Year}"; } - /// This function will return the number of days since Year 1 Spring 0 for an arbitrary date - public static int TotalNumberOfDays(SDate date) - { - return (((date.Year - 1) * 112) + (date.GetSeasonIndex() * 28) + date.Day); - } - /**** ** IEquatable ****/ @@ -121,12 +118,7 @@ namespace StardewModdingAPI.Utilities /// Get a hash code which uniquely identifies a date. public override int GetHashCode() { - // return the number of days since 01 spring Y1 (inclusively) - int yearIndex = this.Year - 1; - return - yearIndex * this.DaysInSeason * this.SeasonsInYear - + this.GetSeasonIndex() * this.DaysInSeason - + this.Day; + return this.DaysSinceStart; } /**** @@ -138,7 +130,7 @@ namespace StardewModdingAPI.Utilities /// The equality of the dates public static bool operator ==(SDate date, SDate other) { - return date?.GetHashCode() == other?.GetHashCode(); + return date?.DaysSinceStart == other?.DaysSinceStart; } /// Get whether one date is not equal to another. @@ -146,7 +138,7 @@ namespace StardewModdingAPI.Utilities /// The other date to compare. public static bool operator !=(SDate date, SDate other) { - return date?.GetHashCode() != other?.GetHashCode(); + return date?.DaysSinceStart != other?.DaysSinceStart; } /// Get whether one date is more than another. @@ -154,7 +146,7 @@ namespace StardewModdingAPI.Utilities /// The other date to compare. public static bool operator >(SDate date, SDate other) { - return date?.GetHashCode() > other?.GetHashCode(); + return date?.DaysSinceStart > other?.DaysSinceStart; } /// Get whether one date is more than or equal to another. @@ -162,7 +154,7 @@ namespace StardewModdingAPI.Utilities /// The other date to compare. public static bool operator >=(SDate date, SDate other) { - return date?.GetHashCode() >= other?.GetHashCode(); + return date?.DaysSinceStart >= other?.DaysSinceStart; } /// Get whether one date is less than or equal to another. @@ -170,7 +162,7 @@ namespace StardewModdingAPI.Utilities /// The other date to compare. public static bool operator <=(SDate date, SDate other) { - return date?.GetHashCode() <= other?.GetHashCode(); + return date?.DaysSinceStart <= other?.DaysSinceStart; } /// Get whether one date is less than another. @@ -178,7 +170,7 @@ namespace StardewModdingAPI.Utilities /// The other date to compare. public static bool operator <(SDate date, SDate other) { - return date?.GetHashCode() < other?.GetHashCode(); + return date?.DaysSinceStart < other?.DaysSinceStart; } @@ -209,7 +201,9 @@ namespace StardewModdingAPI.Utilities this.Day = day; this.Season = season; this.Year = year; - this.DayOfWeek = this.GetDayOfWeek(); + this.DayOfWeek = this.GetDayOfWeek(day); + this.DaysSinceStart = this.GetDaysSinceStart(day, season, year); + } /// Get whether a date represents 0 spring Y1, which is the date during the in-game intro. @@ -221,10 +215,11 @@ namespace StardewModdingAPI.Utilities return day == 0 && season == "spring" && year == 1; } - /// Get the day of week for the current date. - private DayOfWeek GetDayOfWeek() + /// Get the day of week for a given date. + /// The day of month. + private DayOfWeek GetDayOfWeek(int day) { - switch (this.Day % 7) + switch (day % 7) { case 0: return DayOfWeek.Sunday; @@ -245,13 +240,28 @@ namespace StardewModdingAPI.Utilities } } - /// Get the current season index. + /// Get the number of days since the game began (starting at 1 for the first day of spring in Y1). + /// The day of month. + /// The season name. + /// The year. + private int GetDaysSinceStart(int day, string season, int year) + { + // return the number of days since 01 spring Y1 (inclusively) + int yearIndex = year - 1; + return + yearIndex * this.DaysInSeason * this.SeasonsInYear + + this.GetSeasonIndex(season) * this.DaysInSeason + + day; + } + + /// Get a season index. + /// The season name. /// The current season wasn't recognised. - private int GetSeasonIndex() + private int GetSeasonIndex(string season) { - int index = Array.IndexOf(this.Seasons, this.Season); + int index = Array.IndexOf(this.Seasons, season); if (index == -1) - throw new InvalidOperationException($"The current season '{this.Season}' wasn't recognised."); + throw new InvalidOperationException($"The season '{season}' wasn't recognised."); return index; } } -- cgit From ca13b2834c3d34be94c4d46a59cba945e62cce33 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 26 Nov 2017 15:39:41 -0500 Subject: fix e.SuppressButton() not working with some mouse buttons, update release notes (#389) --- docs/release-notes.md | 2 ++ src/SMAPI/Events/EventArgsInput.cs | 31 +++++++++---------------------- 2 files changed, 11 insertions(+), 22 deletions(-) (limited to 'src/SMAPI') diff --git a/docs/release-notes.md b/docs/release-notes.md index a74b1927..433050fb 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -5,6 +5,8 @@ * For modders: * Added `DaysSinceStart` property to `SDate` dates. + * Fixed input `e.SuppressButton(button)` method ignoring input. + * Fixed input `e.SuppressButton()` method not working with mouse buttons. ## 2.1 * For players: diff --git a/src/SMAPI/Events/EventArgsInput.cs b/src/SMAPI/Events/EventArgsInput.cs index 276bfef6..54ce9b53 100644 --- a/src/SMAPI/Events/EventArgsInput.cs +++ b/src/SMAPI/Events/EventArgsInput.cs @@ -129,30 +129,17 @@ namespace StardewModdingAPI.Events } // mouse - else if (button == SButton.MouseLeft) + else if (button == SButton.MouseLeft || button == SButton.MouseMiddle || button == SButton.MouseRight || button == SButton.MouseX1 || button == SButton.MouseX2) { Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - ButtonState.Pressed, - Game1.oldMouseState.MiddleButton, - Game1.oldMouseState.RightButton, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 - ); - } - else if (button == SButton.MouseRight) - { - Game1.oldMouseState = new MouseState( - Game1.oldMouseState.X, - Game1.oldMouseState.Y, - Game1.oldMouseState.ScrollWheelValue, - Game1.oldMouseState.LeftButton, - Game1.oldMouseState.MiddleButton, - ButtonState.Pressed, - Game1.oldMouseState.XButton1, - Game1.oldMouseState.XButton2 + x: Game1.oldMouseState.X, + y: Game1.oldMouseState.Y, + scrollWheel: Game1.oldMouseState.ScrollWheelValue, + leftButton: button == SButton.MouseLeft ? ButtonState.Pressed : Game1.oldMouseState.LeftButton, + middleButton: button == SButton.MouseMiddle ? ButtonState.Pressed : Game1.oldMouseState.MiddleButton, + rightButton: button == SButton.MouseRight ? ButtonState.Pressed : Game1.oldMouseState.RightButton, + xButton1: button == SButton.MouseX1 ? ButtonState.Pressed : Game1.oldMouseState.XButton1, + xButton2: button == SButton.MouseX2 ? ButtonState.Pressed : Game1.oldMouseState.XButton2 ); } } -- cgit From 1aa4098a510ce0f82e7ea7abc24e31e4f5f27225 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 26 Nov 2017 16:27:36 -0500 Subject: fix CFAutomate compatibility errors showing no URL (#393) --- docs/release-notes.md | 1 + src/SMAPI/StardewModdingAPI.config.json | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/SMAPI') diff --git a/docs/release-notes.md b/docs/release-notes.md index 4c5f49d6..da6c046d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,7 @@ ## 2.2 * For players: * Fixed mods crashing when loading a custom asset on Linux/Mac. + * Updated compatibility list. * For modders: * Added `DaysSinceStart` property to `SDate` dates. diff --git a/src/SMAPI/StardewModdingAPI.config.json b/src/SMAPI/StardewModdingAPI.config.json index fa3bdcc9..6718806e 100644 --- a/src/SMAPI/StardewModdingAPI.config.json +++ b/src/SMAPI/StardewModdingAPI.config.json @@ -509,7 +509,8 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha "ID": "Platonymous.CFAutomate", "Compatibility": { "~1.0.1": { "Status": "AssumeBroken" } // no longer compatible with Automate - } + }, + "AlternativeUrl": "https://www.nexusmods.com/stardewvalley/mods/991" }, { // Custom Farm Types -- cgit From 5ae28b2a8caf764e0df0e3bfeca8941db5f4be87 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 27 Nov 2017 22:19:23 -0500 Subject: fix error when a mod has an invalid filename in the EntryDLL manifest field (#402) --- docs/release-notes.md | 11 +++++------ src/SMAPI/Framework/ModLoading/ModResolver.cs | 12 ++++++++++++ src/SMAPI/Program.cs | 10 +++++----- 3 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src/SMAPI') diff --git a/docs/release-notes.md b/docs/release-notes.md index 1b06f86f..f371e5d4 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,20 +1,19 @@ # Release notes ## 2.2 * For players: - * Fixed mods crashing when loading a custom asset on Linux/Mac. - * Fixed rare installer errors on Mac due to generated `mcs` file. + * Fixed error when a mod loads custom assets on Linux/Mac. + * Fixed error when a mod has an invalid `EntryDLL` manifest value format. + * Fixed rare error when Mac adds an `mcs` file to the installer package. * Fixed `player_add` command not handling tool upgrade levels. * Updated compatibility list. + * (log.smapi.io) Saved logs no longer expire after a week. + * (log.smapi.io) The upload-log modal can now be closed by pressing `ESC` or clicking outside it. * For modders: * Added `DaysSinceStart` property to `SDate` dates. * Fixed input `e.SuppressButton(button)` method ignoring input. * Fixed input `e.SuppressButton()` method not working with mouse buttons. -* For log.smapi.io: - * Saved logs no longer expire after a week. - * The upload-log modal can now be closed by pressing `ESC` or clicking outside it. - ## 2.1 * For players: * Added a log parser at [log.smapi.io](https://log.smapi.io). diff --git a/src/SMAPI/Framework/ModLoading/ModResolver.cs b/src/SMAPI/Framework/ModLoading/ModResolver.cs index d0ef1b08..9802d9e9 100644 --- a/src/SMAPI/Framework/ModLoading/ModResolver.cs +++ b/src/SMAPI/Framework/ModLoading/ModResolver.cs @@ -142,6 +142,18 @@ namespace StardewModdingAPI.Framework.ModLoading continue; } + // validate DLL value + if (string.IsNullOrWhiteSpace(mod.Manifest.EntryDll)) + { + mod.SetStatus(ModMetadataStatus.Failed, "its manifest has no EntryDLL field."); + continue; + } + if (mod.Manifest.EntryDll.Intersect(Path.GetInvalidFileNameChars()).Any()) + { + mod.SetStatus(ModMetadataStatus.Failed, $"its manifest has invalid filename '{mod.Manifest.EntryDll}' for the EntryDLL field."); + continue; + } + // validate DLL path string assemblyPath = Path.Combine(mod.DirectoryPath, mod.Manifest.EntryDll); if (!File.Exists(assemblyPath)) diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index b742467b..3ba35e43 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -653,11 +653,8 @@ namespace StardewModdingAPI { // get basic info IManifest manifest = metadata.Manifest; - string assemblyPath = metadata.Manifest?.EntryDll != null - ? Path.Combine(metadata.DirectoryPath, metadata.Manifest.EntryDll) - : null; - this.Monitor.Log(assemblyPath != null - ? $"Loading {metadata.DisplayName} from {assemblyPath.Replace(Constants.ModPath, "").TrimStart(Path.DirectorySeparatorChar)}..." + this.Monitor.Log(metadata.Manifest?.EntryDll != null + ? $"Loading {metadata.DisplayName} from {metadata.DirectoryPath.Replace(Constants.ModPath, "").TrimStart(Path.DirectorySeparatorChar)}{Path.DirectorySeparatorChar}{metadata.Manifest.EntryDll}..." // don't use Path.Combine here, since EntryDLL might not be valid : $"Loading {metadata.DisplayName}...", LogLevel.Trace); // validate status @@ -669,6 +666,9 @@ namespace StardewModdingAPI } // preprocess & load mod assembly + string assemblyPath = metadata.Manifest?.EntryDll != null + ? Path.Combine(metadata.DirectoryPath, metadata.Manifest.EntryDll) + : null; Assembly modAssembly; try { -- cgit From c81520e0bc3433ca7165fbea9b8eaa31eb53a694 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 28 Nov 2017 18:34:27 -0500 Subject: update for 2.2 release --- build/GlobalAssemblyInfo.cs | 4 ++-- docs/release-notes.md | 10 ++++++---- src/SMAPI/Constants.cs | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/SMAPI') diff --git a/build/GlobalAssemblyInfo.cs b/build/GlobalAssemblyInfo.cs index 9af704e0..65211aad 100644 --- a/build/GlobalAssemblyInfo.cs +++ b/build/GlobalAssemblyInfo.cs @@ -2,5 +2,5 @@ using System.Reflection; using System.Runtime.InteropServices; [assembly: ComVisible(false)] -[assembly: AssemblyVersion("2.1.0.0")] -[assembly: AssemblyFileVersion("2.1.0.0")] +[assembly: AssemblyVersion("2.2.0.0")] +[assembly: AssemblyFileVersion("2.2.0.0")] diff --git a/docs/release-notes.md b/docs/release-notes.md index f371e5d4..338a0f9e 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,12 +2,12 @@ ## 2.2 * For players: * Fixed error when a mod loads custom assets on Linux/Mac. - * Fixed error when a mod has an invalid `EntryDLL` manifest value format. + * Fixed error when a mod has an invalid `EntryDLL` filename. * Fixed rare error when Mac adds an `mcs` file to the installer package. * Fixed `player_add` command not handling tool upgrade levels. * Updated compatibility list. - * (log.smapi.io) Saved logs no longer expire after a week. - * (log.smapi.io) The upload-log modal can now be closed by pressing `ESC` or clicking outside it. + * The [log parser][] no longer expires logs after a week. + * The [log parser][] now lets you close modals with `ESC` or a click outside it. * For modders: * Added `DaysSinceStart` property to `SDate` dates. @@ -16,7 +16,7 @@ ## 2.1 * For players: - * Added a log parser at [log.smapi.io](https://log.smapi.io). + * Added a [log parser][] site. * Added better Steam instructions to the SMAPI installer. * Renamed the bundled _TrainerMod_ to _ConsoleCommands_ to make its purpose clearer. * Removed the game's test messages from the console log. @@ -558,3 +558,5 @@ For SMAPI developers: * 0.3 (2016-03-01, [log](https://github.com/Pathoschild/SMAPI/compare/Alpha0.2...0.3)) * 0.2 (2016-02-29, [log](https://github.com/Pathoschild/SMAPI/compare/Alpha0.1...Alpha0.2) * 0.1 (2016-02-28) + +[log parser]: https://log.smapi.io diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index a2dbdd98..c9f9be41 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -29,7 +29,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(2, 1, 0); + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(2, 2, 0); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.30"); -- cgit From 72a02c56d51f5e5b0e8e2fc7db59e1f0e6d93d5c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 2 Dec 2017 14:27:03 -0500 Subject: add NormaliseAssetName content helper method (#404) --- docs/release-notes.md | 3 ++- src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 9 +++++++++ src/SMAPI/IContentHelper.cs | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) (limited to 'src/SMAPI') diff --git a/docs/release-notes.md b/docs/release-notes.md index 53ec07c6..1e89667a 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -12,7 +12,8 @@ * Slightly improved the [log parser][] UI. * For modders: - * Added `DaysSinceStart` property to `SDate` dates. + * Added `helper.Content.NormaliseAssetName` method. + * Added `SDate.DaysSinceStart` property. * Fixed input events' `e.SuppressButton(button)` method ignoring specified button. * Fixed input events' `e.SuppressButton()` method not working with mouse buttons. diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 7665eb78..4a1d3853 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; using System.IO; using System.Linq; using Microsoft.Xna.Framework.Content; @@ -134,6 +135,14 @@ namespace StardewModdingAPI.Framework.ModHelpers } } + /// Normalise an asset name so it's consistent with those generated by the game. This is mainly useful for string comparisons like on generated asset names, and isn't necessary when passing asset names into other content helper methods. + /// The asset key. + [Pure] + public string NormaliseAssetName(string assetName) + { + return this.ContentManager.NormaliseAssetName(assetName); + } + /// Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists. /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. diff --git a/src/SMAPI/IContentHelper.cs b/src/SMAPI/IContentHelper.cs index e3362502..1b87183d 100644 --- a/src/SMAPI/IContentHelper.cs +++ b/src/SMAPI/IContentHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using StardewValley; @@ -37,6 +38,11 @@ namespace StardewModdingAPI /// The content asset couldn't be loaded (e.g. because it doesn't exist). T Load(string key, ContentSource source = ContentSource.ModFolder); + /// Normalise an asset name so it's consistent with those generated by the game. This is mainly useful for string comparisons like on generated asset names, and isn't necessary when passing asset names into other content helper methods. + /// The asset key. + [Pure] + string NormaliseAssetName(string assetName); + /// Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists. /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder. /// Where to search for a matching content asset. -- cgit From adba8a31977acb4e8e5e1a98d53c12292ac4bff6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 2 Dec 2017 18:27:36 -0500 Subject: simplify version format in constants --- src/SMAPI/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index c9f9be41..41b79272 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -29,7 +29,7 @@ namespace StardewModdingAPI ** Public ****/ /// SMAPI's current semantic version. - public static ISemanticVersion ApiVersion { get; } = new SemanticVersion(2, 2, 0); + public static ISemanticVersion ApiVersion { get; } = new SemanticVersion("2.2"); /// The minimum supported version of Stardew Valley. public static ISemanticVersion MinimumGameVersion { get; } = new SemanticVersion("1.2.30"); -- cgit From dc4f89acb6cd8f838934b60e8f5645c6145706f8 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 2 Dec 2017 18:49:35 -0500 Subject: remove unneeded file --- src/SMAPI/App.config | 9 --------- src/SMAPI/StardewModdingAPI.csproj | 3 --- 2 files changed, 12 deletions(-) delete mode 100644 src/SMAPI/App.config (limited to 'src/SMAPI') diff --git a/src/SMAPI/App.config b/src/SMAPI/App.config deleted file mode 100644 index 27cdf0f7..00000000 --- a/src/SMAPI/App.config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 605292b2..380ed733 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -234,9 +234,6 @@ - - Designer - Designer -- cgit