ignore root content managers when handling managed asset keys (#644)
This commit is contained in:
parent
c37fe62ca2
commit
202ba23dcc
|
@ -179,7 +179,7 @@ namespace StardewModdingAPI.Framework
|
||||||
public T LoadAndCloneManagedAsset<T>(string internalKey, string contentManagerID, string relativePath, LocalizedContentManager.LanguageCode language)
|
public T LoadAndCloneManagedAsset<T>(string internalKey, string contentManagerID, string relativePath, LocalizedContentManager.LanguageCode language)
|
||||||
{
|
{
|
||||||
// get content manager
|
// get content manager
|
||||||
IContentManager contentManager = this.ContentManagers.FirstOrDefault(p => p.Name == contentManagerID);
|
IContentManager contentManager = this.ContentManagers.FirstOrDefault(p => p.IsNamespaced && p.Name == contentManagerID);
|
||||||
if (contentManager == null)
|
if (contentManager == null)
|
||||||
throw new InvalidOperationException($"The '{contentManagerID}' prefix isn't handled by any mod.");
|
throw new InvalidOperationException($"The '{contentManagerID}' prefix isn't handled by any mod.");
|
||||||
|
|
||||||
|
|
|
@ -51,8 +51,8 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
/// <summary>The absolute path to the <see cref="ContentManager.RootDirectory"/>.</summary>
|
/// <summary>The absolute path to the <see cref="ContentManager.RootDirectory"/>.</summary>
|
||||||
public string FullRootDirectory => Path.Combine(Constants.ExecutionPath, this.RootDirectory);
|
public string FullRootDirectory => Path.Combine(Constants.ExecutionPath, this.RootDirectory);
|
||||||
|
|
||||||
/// <summary>Whether this content manager is for a mod folder.</summary>
|
/// <summary>Whether this content manager can be targeted by managed asset keys (e.g. to load assets from a mod folder).</summary>
|
||||||
public bool IsModContentManager { get; }
|
public bool IsNamespaced { get; }
|
||||||
|
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
|
@ -67,8 +67,8 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
/// <param name="monitor">Encapsulates monitoring and logging.</param>
|
/// <param name="monitor">Encapsulates monitoring and logging.</param>
|
||||||
/// <param name="reflection">Simplifies access to private code.</param>
|
/// <param name="reflection">Simplifies access to private code.</param>
|
||||||
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
||||||
/// <param name="isModFolder">Whether this content manager is for a mod folder.</param>
|
/// <param name="isNamespaced">Whether this content manager handles managed asset keys (e.g. to load assets from a mod folder).</param>
|
||||||
protected BaseContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action<BaseContentManager> onDisposing, bool isModFolder)
|
protected BaseContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action<BaseContentManager> onDisposing, bool isNamespaced)
|
||||||
: base(serviceProvider, rootDirectory, currentCulture)
|
: base(serviceProvider, rootDirectory, currentCulture)
|
||||||
{
|
{
|
||||||
// init
|
// init
|
||||||
|
@ -77,7 +77,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
this.Cache = new ContentCache(this, reflection);
|
this.Cache = new ContentCache(this, reflection);
|
||||||
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
|
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
|
||||||
this.OnDisposing = onDisposing;
|
this.OnDisposing = onDisposing;
|
||||||
this.IsModContentManager = isModFolder;
|
this.IsNamespaced = isNamespaced;
|
||||||
|
|
||||||
// get asset data
|
// get asset data
|
||||||
this.LanguageCodes = this.GetKeyLocales().ToDictionary(p => p.Value, p => p.Key, StringComparer.InvariantCultureIgnoreCase);
|
this.LanguageCodes = this.GetKeyLocales().ToDictionary(p => p.Value, p => p.Key, StringComparer.InvariantCultureIgnoreCase);
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
||||||
/// <param name="onLoadingFirstAsset">A callback to invoke the first time *any* game content manager loads an asset.</param>
|
/// <param name="onLoadingFirstAsset">A callback to invoke the first time *any* game content manager loads an asset.</param>
|
||||||
public GameContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action<BaseContentManager> onDisposing, Action onLoadingFirstAsset)
|
public GameContentManager(string name, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, Action<BaseContentManager> onDisposing, Action onLoadingFirstAsset)
|
||||||
: base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isModFolder: false)
|
: base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: false)
|
||||||
{
|
{
|
||||||
this.IsLocalisableLookup = reflection.GetField<IDictionary<string, bool>>(this, "_localizedAsset").GetValue();
|
this.IsLocalisableLookup = reflection.GetField<IDictionary<string, bool>>(this, "_localizedAsset").GetValue();
|
||||||
this.OnLoadingFirstAsset = onLoadingFirstAsset;
|
this.OnLoadingFirstAsset = onLoadingFirstAsset;
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
/// <summary>The absolute path to the <see cref="ContentManager.RootDirectory"/>.</summary>
|
/// <summary>The absolute path to the <see cref="ContentManager.RootDirectory"/>.</summary>
|
||||||
string FullRootDirectory { get; }
|
string FullRootDirectory { get; }
|
||||||
|
|
||||||
/// <summary>Whether this content manager is for a mod folder.</summary>
|
/// <summary>Whether this content manager can be targeted by managed asset keys (e.g. to load assets from a mod folder).</summary>
|
||||||
bool IsModContentManager { get; }
|
bool IsNamespaced { get; }
|
||||||
|
|
||||||
|
|
||||||
/*********
|
/*********
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
||||||
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
/// <param name="jsonHelper">Encapsulates SMAPI's JSON file parsing.</param>
|
||||||
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
/// <param name="onDisposing">A callback to invoke when the content manager is being disposed.</param>
|
||||||
public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action<BaseContentManager> onDisposing)
|
public ModContentManager(string name, IContentManager gameContentManager, IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, ContentCoordinator coordinator, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action<BaseContentManager> onDisposing)
|
||||||
: base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isModFolder: true)
|
: base(name, serviceProvider, rootDirectory, currentCulture, coordinator, monitor, reflection, onDisposing, isNamespaced: true)
|
||||||
{
|
{
|
||||||
this.GameContentManager = gameContentManager;
|
this.GameContentManager = gameContentManager;
|
||||||
this.JsonHelper = jsonHelper;
|
this.JsonHelper = jsonHelper;
|
||||||
|
|
Loading…
Reference in New Issue