summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI/Framework/SContentManager.cs63
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs7
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.csproj1
3 files changed, 71 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/SContentManager.cs b/src/StardewModdingAPI/Framework/SContentManager.cs
new file mode 100644
index 00000000..27001a06
--- /dev/null
+++ b/src/StardewModdingAPI/Framework/SContentManager.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Threading;
+using Microsoft.Xna.Framework;
+using StardewModdingAPI.Framework.Reflection;
+using StardewValley;
+
+namespace StardewModdingAPI.Framework
+{
+ /// <summary>SMAPI's implementation of the game's content manager which lets it raise content events.</summary>
+ internal class SContentManager : LocalizedContentManager
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Encapsulates monitoring and logging.</summary>
+ private readonly IMonitor Monitor;
+
+ /// <summary>The underlying content manager's asset cache.</summary>
+ private readonly IDictionary<string, object> Cache;
+
+ /// <summary>Normalises an asset key to match the cache key.</summary>
+ private readonly IPrivateMethod NormaliseAssetKey;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="serviceProvider">The service provider to use to locate services.</param>
+ /// <param name="rootDirectory">The root directory to search for content.</param>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ public SContentManager(IServiceProvider serviceProvider, string rootDirectory, IMonitor monitor)
+ : this(serviceProvider, rootDirectory, Thread.CurrentThread.CurrentUICulture, null, monitor) { }
+
+ /// <summary>Construct an instance.</summary>
+ /// <param name="serviceProvider">The service provider to use to locate services.</param>
+ /// <param name="rootDirectory">The root directory to search for content.</param>
+ /// <param name="currentCulture">The current culture for which to localise content.</param>
+ /// <param name="languageCodeOverride">The current language code for which to localise content.</param>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ public SContentManager(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, string languageCodeOverride, IMonitor monitor)
+ : base(serviceProvider, rootDirectory, currentCulture, languageCodeOverride)
+ {
+ this.Monitor = monitor;
+
+ IReflectionHelper reflection = new ReflectionHelper();
+ this.Cache = reflection
+ .GetPrivateField<Dictionary<string, object>>(this, "loadedAssets")
+ .GetValue();
+ this.NormaliseAssetKey = reflection.GetPrivateMethod(typeof(TitleContainer), "GetCleanPath");
+ }
+
+ /// <summary>Load an asset that has been processed by the Content Pipeline.</summary>
+ /// <typeparam name="T">The type of asset to load.</typeparam>
+ /// <param name="assetName">The asset path relative to the loader root directory, not including the <c>.xnb</c> extension.</param>
+ public override T Load<T>(string assetName)
+ {
+ return base.Load<T>(assetName);
+ }
+ }
+}
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index 56631260..aab44b59 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -288,7 +288,14 @@ namespace StardewModdingAPI.Framework
/// <summary>The method called before XNA or MonoGame loads or reloads graphics resources.</summary>
protected override void LoadContent()
{
+ // override content manager
+ LocalizedContentManager contentManager = Game1.content;
+ Game1.content = new SContentManager(this.Content.ServiceProvider, this.Content.RootDirectory, this.Monitor);
+
+ // defer to game logic
base.LoadContent();
+
+ // raise load content event
GameEvents.InvokeLoadContent(this.Monitor);
}
diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj
index 72cc1ed2..ee37379d 100644
--- a/src/StardewModdingAPI/StardewModdingAPI.csproj
+++ b/src/StardewModdingAPI/StardewModdingAPI.csproj
@@ -153,6 +153,7 @@
<Compile Include="Framework\Models\SConfig.cs" />
<Compile Include="Framework\Reflection\PrivateProperty.cs" />
<Compile Include="Framework\RequestExitDelegate.cs" />
+ <Compile Include="Framework\SContentManager.cs" />
<Compile Include="Framework\Serialisation\JsonHelper.cs" />
<Compile Include="Framework\Serialisation\SelectiveStringEnumConverter.cs" />
<Compile Include="Framework\Serialisation\SemanticVersionConverter.cs" />