summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ContentHelper.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-05-25 20:55:08 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-05-25 20:55:08 -0400
commit24e214b6012de06246deadfd3d63f4a5e25a71ba (patch)
tree5597c8d6c620a624fb69fa9b212c82f6af6a7a61 /src/StardewModdingAPI/Framework/ContentHelper.cs
parenta91e111247cbe5d9b92953a7f449a12c6fa7b4cf (diff)
downloadSMAPI-24e214b6012de06246deadfd3d63f4a5e25a71ba.tar.gz
SMAPI-24e214b6012de06246deadfd3d63f4a5e25a71ba.tar.bz2
SMAPI-24e214b6012de06246deadfd3d63f4a5e25a71ba.zip
minor cleanup
Diffstat (limited to 'src/StardewModdingAPI/Framework/ContentHelper.cs')
-rw-r--r--src/StardewModdingAPI/Framework/ContentHelper.cs25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs
index 5a2a8b9b..10240cd1 100644
--- a/src/StardewModdingAPI/Framework/ContentHelper.cs
+++ b/src/StardewModdingAPI/Framework/ContentHelper.cs
@@ -71,38 +71,37 @@ namespace StardewModdingAPI.Framework
// get asset path
string assetPath = this.GetModAssetPath(key, file.FullName);
+ // try cache
+ if (this.ContentManager.IsLoaded(assetPath))
+ return this.ContentManager.Load<T>(assetPath);
+
// load content
switch (file.Extension.ToLower())
{
+ // XNB file
case ".xnb":
return this.ContentManager.Load<T>(assetPath);
+ // unpacked map
case ".tbin":
// validate
if (typeof(T) != typeof(Map))
throw new ContentLoadException($"Can't read file with extension '{file.Extension}' as type '{typeof(T)}'; must be type '{typeof(Map)}'.");
-
- // try cache
- if (this.ContentManager.IsLoaded(assetPath))
- return this.ContentManager.Load<T>(assetPath);
// fetch & cache
FormatManager formatManager = FormatManager.Instance;
Map map = formatManager.LoadMap(file.FullName);
- foreach (TileSheet t in map.TileSheets)
- t.ImageSource = t.ImageSource.Replace(".png", "");
+ foreach (TileSheet tilesheet in map.TileSheets)
+ tilesheet.ImageSource = tilesheet.ImageSource.Replace(".png", "");
this.ContentManager.Inject(assetPath, map);
return (T)(object)map;
-
+
+ // unpacked image
case ".png":
// validate
if (typeof(T) != typeof(Texture2D))
throw new ContentLoadException($"Can't read file with extension '{file.Extension}' as type '{typeof(T)}'; must be type '{typeof(Texture2D)}'.");
- // try cache
- if (this.ContentManager.IsLoaded(assetPath))
- return this.ContentManager.Load<T>(assetPath);
-
// fetch & cache
using (FileStream stream = File.OpenRead(file.FullName))
{
@@ -111,10 +110,6 @@ namespace StardewModdingAPI.Framework
this.ContentManager.Inject(assetPath, texture);
return (T)(object)texture;
}
-
-
-
-
default:
throw new ContentLoadException($"Unknown file extension '{file.Extension}'; must be '.xnb' or '.png'.");