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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
using System;
using System.Globalization;
using StardewValley;
namespace StardewModdingAPI.Framework
{
/// <summary>A minimal content manager which defers to SMAPI's core content logic.</summary>
internal class ContentManagerShim : LocalizedContentManager
{
/*********
** Properties
*********/
/// <summary>SMAPI's core content logic.</summary>
private readonly ContentCore ContentCore;
/*********
** 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="contentCore">SMAPI's core content logic.</param>
/// <param name="name">The content manager's name for logs (if any).</param>
/// <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.ContentCore = contentCore;
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)
{
#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.ContentCore.DisposeFor(this);
}
}
}
|