summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ContentManagerShim.cs
blob: d46f23a3fb138376250aec5883cd1a511fef55c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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);
        }
    }
}