summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentManagerShim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/ContentManagerShim.cs')
-rw-r--r--src/SMAPI/Framework/ContentManagerShim.cs68
1 files changed, 59 insertions, 9 deletions
diff --git a/src/SMAPI/Framework/ContentManagerShim.cs b/src/SMAPI/Framework/ContentManagerShim.cs
index d46f23a3..8f88fc2d 100644
--- a/src/SMAPI/Framework/ContentManagerShim.cs
+++ b/src/SMAPI/Framework/ContentManagerShim.cs
@@ -1,15 +1,17 @@
+using System;
+using System.Globalization;
using StardewValley;
namespace StardewModdingAPI.Framework
{
- /// <summary>A minimal content manager which defers to SMAPI's main content manager.</summary>
+ /// <summary>A minimal content manager which defers to SMAPI's core content logic.</summary>
internal class ContentManagerShim : LocalizedContentManager
{
/*********
** Properties
*********/
- /// <summary>SMAPI's underlying content manager.</summary>
- private readonly SContentManager ContentManager;
+ /// <summary>SMAPI's core content logic.</summary>
+ private readonly ContentCore ContentCore;
/*********
@@ -23,12 +25,16 @@ namespace StardewModdingAPI.Framework
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- /// <param name="contentManager">SMAPI's underlying content manager.</param>
+ /// <param name="contentCore">SMAPI's core content logic.</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)
+ /// <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>
+ public ContentManagerShim(ContentCore contentCore, string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, string languageCodeOverride)
+ : base(serviceProvider, rootDirectory, currentCulture, languageCodeOverride)
{
- this.ContentManager = contentManager;
+ this.ContentCore = contentCore;
this.Name = name;
}
@@ -37,14 +43,58 @@ namespace StardewModdingAPI.Framework
/// <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);
+#if STARDEW_VALLEY_1_3
+ return this.Load<T>(assetName, LocalizedContentManager.CurrentLanguageCode);
+#else
+ return this.ContentCore.Load<T>(assetName, this);
+#endif
}
+#if STARDEW_VALLEY_1_3
+ /// <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>
+ /// <param name="language">The language code for which to load content.</param>
+ public override T Load<T>(string assetName, LanguageCode language)
+ {
+ return this.ContentCore.Load<T>(assetName, this, language);
+ }
+
+ /// <summary>Load the base asset without localisation.</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 LoadBase<T>(string assetName)
+ {
+ return this.Load<T>(assetName, LanguageCode.en);
+ }
+#endif
+
+ /// <summary>Inject an asset into the cache.</summary>
+ /// <typeparam name="T">The type of asset to inject.</typeparam>
+ /// <param name="assetName">The asset path relative to the loader root directory, not including the <c>.xnb</c> extension.</param>
+ /// <param name="value">The asset value.</param>
+ public void Inject<T>(string assetName, T value)
+ {
+ this.ContentCore.Inject<T>(assetName, value, this);
+ }
+
+#if STARDEW_VALLEY_1_3
+ /// <summary>Create a new content manager for temporary use.</summary>
+ public override LocalizedContentManager CreateTemporary()
+ {
+ return this.ContentCore.CreateContentManager("(temporary)");
+ }
+#endif
+
+
+ /*********
+ ** Protected methods
+ *********/
/// <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);
+ this.ContentCore.DisposeFor(this);
}
}
}