minor cleanup
This commit is contained in:
parent
a91e111247
commit
24e214b601
|
@ -71,38 +71,37 @@ namespace StardewModdingAPI.Framework
|
||||||
// get asset path
|
// get asset path
|
||||||
string assetPath = this.GetModAssetPath(key, file.FullName);
|
string assetPath = this.GetModAssetPath(key, file.FullName);
|
||||||
|
|
||||||
|
// try cache
|
||||||
|
if (this.ContentManager.IsLoaded(assetPath))
|
||||||
|
return this.ContentManager.Load<T>(assetPath);
|
||||||
|
|
||||||
// load content
|
// load content
|
||||||
switch (file.Extension.ToLower())
|
switch (file.Extension.ToLower())
|
||||||
{
|
{
|
||||||
|
// XNB file
|
||||||
case ".xnb":
|
case ".xnb":
|
||||||
return this.ContentManager.Load<T>(assetPath);
|
return this.ContentManager.Load<T>(assetPath);
|
||||||
|
|
||||||
|
// unpacked map
|
||||||
case ".tbin":
|
case ".tbin":
|
||||||
// validate
|
// validate
|
||||||
if (typeof(T) != typeof(Map))
|
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)}'.");
|
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
|
// fetch & cache
|
||||||
FormatManager formatManager = FormatManager.Instance;
|
FormatManager formatManager = FormatManager.Instance;
|
||||||
Map map = formatManager.LoadMap(file.FullName);
|
Map map = formatManager.LoadMap(file.FullName);
|
||||||
foreach (TileSheet t in map.TileSheets)
|
foreach (TileSheet tilesheet in map.TileSheets)
|
||||||
t.ImageSource = t.ImageSource.Replace(".png", "");
|
tilesheet.ImageSource = tilesheet.ImageSource.Replace(".png", "");
|
||||||
this.ContentManager.Inject(assetPath, map);
|
this.ContentManager.Inject(assetPath, map);
|
||||||
return (T)(object)map;
|
return (T)(object)map;
|
||||||
|
|
||||||
|
// unpacked image
|
||||||
case ".png":
|
case ".png":
|
||||||
// validate
|
// validate
|
||||||
if (typeof(T) != typeof(Texture2D))
|
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)}'.");
|
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
|
// fetch & cache
|
||||||
using (FileStream stream = File.OpenRead(file.FullName))
|
using (FileStream stream = File.OpenRead(file.FullName))
|
||||||
{
|
{
|
||||||
|
@ -112,10 +111,6 @@ namespace StardewModdingAPI.Framework
|
||||||
return (T)(object)texture;
|
return (T)(object)texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ContentLoadException($"Unknown file extension '{file.Extension}'; must be '.xnb' or '.png'.");
|
throw new ContentLoadException($"Unknown file extension '{file.Extension}'; must be '.xnb' or '.png'.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,7 +268,6 @@ namespace StardewModdingAPI
|
||||||
** Private methods
|
** Private methods
|
||||||
*********/
|
*********/
|
||||||
/// <summary>Assert that the minimum conditions are present to initialise SMAPI without type load exceptions.</summary>
|
/// <summary>Assert that the minimum conditions are present to initialise SMAPI without type load exceptions.</summary>
|
||||||
/// <returns>Returns whether the minimum conditions are met.</returns>
|
|
||||||
private static void AssertMinimumCompatibility()
|
private static void AssertMinimumCompatibility()
|
||||||
{
|
{
|
||||||
void PrintErrorAndExit(string message)
|
void PrintErrorAndExit(string message)
|
||||||
|
|
Loading…
Reference in New Issue