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 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'src/SMAPI/Framework/ModHelpers') 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 - } } } -- 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/Framework/ModHelpers') 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