using System; using System.Globalization; using StardewValley; namespace StardewModdingAPI.Framework { /// A minimal content manager which defers to SMAPI's core content logic. internal class ContentManagerShim : LocalizedContentManager { /********* ** Properties *********/ /// SMAPI's core content logic. private readonly ContentCore ContentCore; /********* ** Accessors *********/ /// The content manager's name for logs (if any). public string Name { get; } /********* ** Public methods *********/ /// Construct an instance. /// SMAPI's core content logic. /// The content manager's name for logs (if any). /// The service provider to use to locate services. /// The root directory to search for content. /// The current culture for which to localise content. /// The current language code for which to localise content. public ContentManagerShim(ContentCore contentCore, string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, string languageCodeOverride) : base(serviceProvider, rootDirectory, currentCulture, languageCodeOverride) { this.ContentCore = contentCore; this.Name = name; } /// Load an asset that has been processed by the content pipeline. /// The type of asset to load. /// The asset path relative to the loader root directory, not including the .xnb extension. public override T Load(string assetName) { #if STARDEW_VALLEY_1_3 return this.Load(assetName, LocalizedContentManager.CurrentLanguageCode); #else return this.ContentCore.Load(assetName, this); #endif } #if STARDEW_VALLEY_1_3 /// Load an asset that has been processed by the content pipeline. /// The type of asset to load. /// The asset path relative to the loader root directory, not including the .xnb extension. /// The language code for which to load content. public override T Load(string assetName, LanguageCode language) { return this.ContentCore.Load(assetName, this, language); } /// Load the base asset without localisation. /// The type of asset to load. /// The asset path relative to the loader root directory, not including the .xnb extension. public override T LoadBase(string assetName) { return this.Load(assetName, LanguageCode.en); } #endif /// Inject an asset into the cache. /// The type of asset to inject. /// The asset path relative to the loader root directory, not including the .xnb extension. /// The asset value. public void Inject(string assetName, T value) { this.ContentCore.Inject(assetName, value, this); } #if STARDEW_VALLEY_1_3 /// Create a new content manager for temporary use. public override LocalizedContentManager CreateTemporary() { return this.ContentCore.CreateContentManager("(temporary)"); } #endif /********* ** Protected methods *********/ /// Dispose held resources. /// Whether the content manager is disposing (rather than finalising). protected override void Dispose(bool disposing) { this.ContentCore.DisposeFor(this); } } }