summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentManagers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-05-03 18:11:31 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-05-03 18:11:31 -0400
commit5d3d919d490fd414fe9647e566e92c71d7f64509 (patch)
treee1eab3352287ef04b5de4cdc28b550e255d58c3f /src/SMAPI/Framework/ContentManagers
parentc48f6d78cc412c5f2e40a8b460b7b3c1c993c51a (diff)
parent3447e2f575c2c83af729777e4d37e93f4c2a6467 (diff)
downloadSMAPI-5d3d919d490fd414fe9647e566e92c71d7f64509.tar.gz
SMAPI-5d3d919d490fd414fe9647e566e92c71d7f64509.tar.bz2
SMAPI-5d3d919d490fd414fe9647e566e92c71d7f64509.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ContentManagers')
-rw-r--r--src/SMAPI/Framework/ContentManagers/ModContentManager.cs30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
index 9af14cb5..4f6aa775 100644
--- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
@@ -34,6 +34,9 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>The language code for language-agnostic mod assets.</summary>
private readonly LanguageCode DefaultLanguage = Constants.DefaultLanguage;
+ /// <summary>If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder.</summary>
+ 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;
@@ -259,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
@@ -280,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))
@@ -308,6 +321,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);