diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-25 21:02:05 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-25 21:02:05 -0400 |
commit | a47ca7e3910d532a3468f2ff222c9c1ed28514c4 (patch) | |
tree | a9144c932d9e993cf399de02eaae773b966ba6c3 /src | |
parent | 24e214b6012de06246deadfd3d63f4a5e25a71ba (diff) | |
download | SMAPI-a47ca7e3910d532a3468f2ff222c9c1ed28514c4.tar.gz SMAPI-a47ca7e3910d532a3468f2ff222c9c1ed28514c4.tar.bz2 SMAPI-a47ca7e3910d532a3468f2ff222c9c1ed28514c4.zip |
expand .tbin loading to support custom tilesheets from the mod folder
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Framework/ContentHelper.cs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs index 10240cd1..e15f0dcf 100644 --- a/src/StardewModdingAPI/Framework/ContentHelper.cs +++ b/src/StardewModdingAPI/Framework/ContentHelper.cs @@ -91,8 +91,47 @@ namespace StardewModdingAPI.Framework // fetch & cache FormatManager formatManager = FormatManager.Instance; Map map = formatManager.LoadMap(file.FullName); - foreach (TileSheet tilesheet in map.TileSheets) - tilesheet.ImageSource = tilesheet.ImageSource.Replace(".png", ""); + if (map.TileSheets.Any()) + { + string relativeMapFolder = Path.GetDirectoryName(key) ?? ""; // folder path containing the map, relative to the mod folder + foreach (TileSheet tilesheet in map.TileSheets) + { + // check for tilesheet relative to map + { + string localKey = Path.Combine(relativeMapFolder, tilesheet.ImageSource); + FileInfo localFile = this.GetModFile(localKey); + if (localFile.Exists) + { + try + { + this.Load<Texture2D>(localKey); + } + catch (Exception ex) + { + throw new ContentLoadException($"{this.ModName} failed loading map '{key}' from {source} because the local '{tilesheet.ImageSource}' tilesheet couldn't be loaded.", ex); + } + tilesheet.ImageSource = this.GetActualAssetKey(localKey); + continue; + } + } + + // fallback to game content + 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($"{this.ModName} failed loading map '{key}' from {source} because the '{tilesheet.ImageSource}' tilesheet couldn't be found relative to either map file or the game's content folder.", ex); + } + tilesheet.ImageSource = contentKey; + } + } + + // inject map this.ContentManager.Inject(assetPath, map); return (T)(object)map; |