summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-07-23 19:39:17 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-07-23 19:39:17 -0400
commiteeee6b185d5438e5d44ed0da7c23cf19813b29ea (patch)
tree1690b76bea5612368528ea38448beb1ddcaaff44 /src/StardewModdingAPI/Framework
parent467ad2ffd45f7c034b89b668883bb5271524821d (diff)
downloadSMAPI-eeee6b185d5438e5d44ed0da7c23cf19813b29ea.tar.gz
SMAPI-eeee6b185d5438e5d44ed0da7c23cf19813b29ea.tar.bz2
SMAPI-eeee6b185d5438e5d44ed0da7c23cf19813b29ea.zip
use more flexible approach to core asset reloading (#335)
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/SContentManager.cs26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/StardewModdingAPI/Framework/SContentManager.cs b/src/StardewModdingAPI/Framework/SContentManager.cs
index 0741d04d..0854c379 100644
--- a/src/StardewModdingAPI/Framework/SContentManager.cs
+++ b/src/StardewModdingAPI/Framework/SContentManager.cs
@@ -8,6 +8,7 @@ using Microsoft.Xna.Framework.Content;
using StardewModdingAPI.AssemblyRewriters;
using StardewModdingAPI.Framework.Content;
using StardewModdingAPI.Framework.Reflection;
+using StardewModdingAPI.Metadata;
using StardewValley;
namespace StardewModdingAPI.Framework
@@ -37,10 +38,10 @@ namespace StardewModdingAPI.Framework
private readonly IPrivateMethod GetKeyLocale;
/// <summary>The language codes used in asset keys.</summary>
- private IDictionary<string, LanguageCode> KeyLocales;
+ private readonly IDictionary<string, LanguageCode> KeyLocales;
- /// <summary>The game's static asset setters by normalised asset name.</summary>
- private readonly IDictionary<string, Action> CoreAssetSetters;
+ /// <summary>Provides metadata for core game assets.</summary>
+ private readonly CoreAssets CoreAssets;
/*********
@@ -89,22 +90,12 @@ namespace StardewModdingAPI.Framework
else
this.NormaliseAssetNameForPlatform = key => key.Replace('\\', '/'); // based on MonoGame's ContentManager.Load<T> logic
- // get asset key locales
+ // get asset data
+ this.CoreAssets = new CoreAssets(this.NormaliseAssetName);
this.KeyLocales = this.GetKeyLocales(reflection);
- this.CoreAssetSetters = this.GetCoreAssetSetters();
}
- /// <summary>Get methods to reload core game assets by normalised key.</summary>
- private IDictionary<string, Action> GetCoreAssetSetters()
- {
- return Constants.GetCoreAssetSetters()
- .ToDictionary<KeyValuePair<string, Action<SContentManager, string>>, string, Action>(
- p => this.NormaliseAssetName(p.Key),
- p => () => p.Value(this, p.Key)
- );
- }
-
/// <summary>Get the locale codes (like <c>ja-JP</c>) used in asset keys.</summary>
/// <param name="reflection">Simplifies access to private game code.</param>
private IDictionary<string, LanguageCode> GetKeyLocales(Reflector reflection)
@@ -246,11 +237,8 @@ namespace StardewModdingAPI.Framework
int reloaded = 0;
foreach (string key in purgeAssetKeys)
{
- if (this.CoreAssetSetters.TryGetValue(key, out Action reloadAsset))
- {
- reloadAsset();
+ if(this.CoreAssets.ReloadForKey(this, key))
reloaded++;
- }
}
// report result