summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ContentManagerShim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework/ContentManagerShim.cs')
-rw-r--r--src/StardewModdingAPI/Framework/ContentManagerShim.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/ContentManagerShim.cs b/src/StardewModdingAPI/Framework/ContentManagerShim.cs
new file mode 100644
index 00000000..d46f23a3
--- /dev/null
+++ b/src/StardewModdingAPI/Framework/ContentManagerShim.cs
@@ -0,0 +1,50 @@
+using StardewValley;
+
+namespace StardewModdingAPI.Framework
+{
+ /// <summary>A minimal content manager which defers to SMAPI's main content manager.</summary>
+ internal class ContentManagerShim : LocalizedContentManager
+ {
+ /*********
+ ** Properties
+ *********/
+ /// <summary>SMAPI's underlying content manager.</summary>
+ private readonly SContentManager ContentManager;
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The content manager's name for logs (if any).</summary>
+ public string Name { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="contentManager">SMAPI's underlying content manager.</param>
+ /// <param name="name">The content manager's name for logs (if any).</param>
+ public ContentManagerShim(SContentManager contentManager, string name)
+ : base(contentManager.ServiceProvider, contentManager.RootDirectory, contentManager.CurrentCulture, contentManager.LanguageCodeOverride)
+ {
+ this.ContentManager = contentManager;
+ this.Name = name;
+ }
+
+ /// <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 this.ContentManager.LoadFor<T>(assetName, this);
+ }
+
+ /// <summary>Dispose held resources.</summary>
+ /// <param name="disposing">Whether the content manager is disposing (rather than finalising).</param>
+ protected override void Dispose(bool disposing)
+ {
+ this.ContentManager.DisposeFor(this);
+ }
+ }
+}