summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release-notes.md4
-rw-r--r--src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs92
2 files changed, 76 insertions, 20 deletions
diff --git a/release-notes.md b/release-notes.md
index d5bb81fe..430bd9c8 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -26,6 +26,10 @@ For mod developers:
For power users:
* Added command-line arguments to the SMAPI installer so it can be scripted.
+## 1.15.4
+For players:
+* Internal fixes to support Entoarox Framework and the upcoming SMAPI 2.0 release.
+
## 1.15.3
For players:
* Fixed mods being marked as duplicate incorrectly in some cases.
diff --git a/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs b/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs
index ffa78ff6..21201970 100644
--- a/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs
+++ b/src/StardewModdingAPI/Framework/ModHelpers/ContentHelper.cs
@@ -216,47 +216,99 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <exception cref="ContentLoadException">The map tilesheets could not be loaded.</exception>
private void FixLocalMapTilesheets(Map map, string mapKey)
{
+ // check map info
if (!map.TileSheets.Any())
return;
-
string relativeMapFolder = Path.GetDirectoryName(mapKey) ?? ""; // folder path containing the map, relative to the mod folder
+
+ // fix tilesheets
foreach (TileSheet tilesheet in map.TileSheets)
{
- // check for tilesheet relative to map
+ string imageSource = tilesheet.ImageSource;
+
+ // get seasonal name (if applicable)
+ string seasonalImageSource = null;
+ if(Game1.currentSeason != null && Game1.currentSeason != "spring")
+ {
+ string filename = Path.GetFileName(imageSource);
+ string dirPath = imageSource.Substring(0, imageSource.LastIndexOf(filename));
+ if (filename.StartsWith("spring_"))
+ seasonalImageSource = dirPath + Game1.currentSeason + "_" + filename.Substring("spring_".Length);
+ }
+
+ // load best match
+ try
{
- string localKey = Path.Combine(relativeMapFolder, tilesheet.ImageSource);
- FileInfo localFile = this.GetModFile(localKey);
- if (localFile.Exists)
+ string key =
+ this.TryLoadTilesheetImageSource(relativeMapFolder, seasonalImageSource)
+ ?? this.TryLoadTilesheetImageSource(relativeMapFolder, imageSource);
+ if (key != null)
{
- try
- {
- this.Load<Texture2D>(localKey);
- }
- catch (Exception ex)
- {
- throw new ContentLoadException($"The local '{tilesheet.ImageSource}' tilesheet couldn't be loaded.", ex);
- }
- tilesheet.ImageSource = this.GetActualAssetKey(localKey);
+ tilesheet.ImageSource = key;
continue;
}
}
+ catch (Exception ex)
+ {
+ throw new ContentLoadException($"The '{imageSource}' tilesheet couldn't be loaded relative to either map file or the game's content folder.", ex);
+ }
+
+ // none found
+ throw new ContentLoadException($"The '{imageSource}' tilesheet couldn't be loaded relative to either map file or the game's content folder.");
+ }
+ }
+
+ /// <summary>Load a tilesheet image source if the file exists.</summary>
+ /// <param name="relativeMapFolder">The folder path containing the map, relative to the mod folder.</param>
+ /// <param name="imageSource">The tilesheet image source to load.</param>
+ /// <returns>Returns the loaded asset key (if it was loaded successfully).</returns>
+ private string TryLoadTilesheetImageSource(string relativeMapFolder, string imageSource)
+ {
+ if (imageSource == null)
+ return null;
+
+ // check for tilesheet relative to map
+ {
+ string localKey = Path.Combine(relativeMapFolder, imageSource);
+ FileInfo localFile = this.GetModFile(localKey);
+ if (localFile.Exists)
+ {
+ try
+ {
+ this.Load<Texture2D>(localKey);
+ }
+ catch (Exception ex)
+ {
+ throw new ContentLoadException($"The local '{imageSource}' tilesheet couldn't be loaded.", ex);
+ }
+
+ return this.GetActualAssetKey(localKey);
+ }
+ }
+
+ // fallback to game content
+ {
+ string contentKey = imageSource.EndsWith(".png")
+ ? imageSource.Substring(0, imageSource.Length - 4)
+ : imageSource;
- // fallback to game content
+ FileInfo file = new FileInfo(Path.Combine(this.ContentManager.FullRootDirectory, contentKey + ".xnb"));
+ if (file.Exists)
{
- string contentKey = tilesheet.ImageSource;
- if (contentKey.EndsWith(".png"))
- contentKey = contentKey.Substring(0, contentKey.Length - 4);
try
{
this.ContentManager.Load<Texture2D>(contentKey);
}
catch (Exception ex)
{
- throw new ContentLoadException($"The '{tilesheet.ImageSource}' tilesheet couldn't be loaded relative to either map file or the game's content folder.", ex);
+ throw new ContentLoadException($"The '{imageSource}' tilesheet couldn't be loaded relative to either map file or the game's content folder.", ex);
}
- tilesheet.ImageSource = contentKey;
+ return contentKey;
}
}
+
+ // not found
+ return null;
}
/// <summary>Assert that the given key has a valid format.</summary>