From 99f70f963459912ce66f5a586eb4fc36e561b69d Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 1 May 2021 12:33:09 -0400 Subject: match tilesheets without extension to .png files automatically if possible --- .../Framework/ContentManagers/ModContentManager.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/SMAPI/Framework/ContentManagers') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 9af14cb5..0cd431e8 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -34,6 +34,9 @@ namespace StardewModdingAPI.Framework.ContentManagers /// The language code for language-agnostic mod assets. private readonly LanguageCode DefaultLanguage = Constants.DefaultLanguage; + /// If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder. + private readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" }; + /********* ** Public methods @@ -215,11 +218,17 @@ namespace StardewModdingAPI.Framework.ContentManagers FileInfo file = new FileInfo(Path.Combine(this.FullRootDirectory, path)); // try with default extension - if (!file.Exists && file.Extension.ToLower() != ".xnb") + if (!file.Exists && file.Extension == string.Empty) { - FileInfo result = new FileInfo(file.FullName + ".xnb"); - if (result.Exists) - file = result; + foreach (string extension in this.LocalTilesheetExtensions) + { + FileInfo result = new FileInfo(file.FullName + extension); + if (result.Exists) + { + file = result; + break; + } + } } return file; -- cgit From eef6a9c2e8d124ad0856a8b351f9cae68e54f6eb Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 May 2021 18:34:26 -0400 Subject: add support for dot-ignoring local map tilesheet files (#732) --- docs/release-notes.md | 1 + src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 9 +++++++++ 2 files changed, 10 insertions(+) (limited to 'src/SMAPI/Framework/ContentManagers') diff --git a/docs/release-notes.md b/docs/release-notes.md index 73b9376d..27786e18 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -24,6 +24,7 @@ * For modders: * Added asset propagation for `Data\Concessions`. * Added SMAPI version and bitness to the console title before startup to simplify troubleshooting. + * Added support for [ignoring local map tilesheet files when loading a map](https://stardewvalleywiki.com/Modding:Maps#Local_copy_of_a_vanilla_tilesheet). * If a map loads a tilesheet path with no file extension, SMAPI now automatically links it to a `.png` version in the map folder if possible. * Improved error-handling during asset propagation. * Fixed `Context.IsMainPlayer` returning true for a farmhand in split-screen mode before the screen is initialized. diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 0cd431e8..f32e3be6 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -317,6 +317,15 @@ namespace StardewModdingAPI.Framework.ContentManagers return true; } + // special case: local filenames starting with a dot should be ignored + // For example, this lets mod authors have a '.spring_town.png' file in their map folder so it can be + // opened in Tiled, while still mapping it to the vanilla 'Maps/spring_town' asset at runtime. + { + string filename = Path.GetFileName(relativePath); + if (filename.StartsWith(".")) + relativePath = Path.Combine(Path.GetDirectoryName(relativePath) ?? "", filename.TrimStart('.')); + } + // get relative to map file { string localKey = Path.Combine(modRelativeMapFolder, relativePath); -- cgit From 2cc5509e9828fd5194ca6ef7ae9ea23bd3628971 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 May 2021 18:35:34 -0400 Subject: add verbose logs for map tilesheet changes --- src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/SMAPI/Framework/ContentManagers') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index f32e3be6..4f6aa775 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -268,6 +268,7 @@ namespace StardewModdingAPI.Framework.ContentManagers string relativeMapFolder = Path.GetDirectoryName(relativeMapPath) ?? ""; // folder path containing the map, relative to the mod folder // fix tilesheets + this.Monitor.VerboseLog($"Fixing tilesheet paths for map '{relativeMapPath}' from mod '{this.ModName}'..."); foreach (TileSheet tilesheet in map.TileSheets) { // get image source @@ -289,6 +290,9 @@ namespace StardewModdingAPI.Framework.ContentManagers if (!this.TryGetTilesheetAssetName(relativeMapFolder, imageSource, out string assetName, out string error)) throw new SContentLoadException($"{errorPrefix} {error}"); + if (assetName != tilesheet.ImageSource) + this.Monitor.VerboseLog($" Mapped tilesheet '{tilesheet.ImageSource}' to '{assetName}'."); + tilesheet.ImageSource = assetName; } catch (Exception ex) when (!(ex is SContentLoadException)) -- cgit