summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ContentManagers/BaseContentManager.cs56
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManager.cs27
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManagerForAssetPropagation.cs2
-rw-r--r--src/SMAPI/Framework/ContentManagers/ModContentManager.cs21
-rw-r--r--src/SMAPI/Metadata/CoreAssetPropagator.cs2
5 files changed, 32 insertions, 76 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index b6b3a7a0..1a64dab8 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -5,7 +5,6 @@ using System.Diagnostics.Contracts;
using System.Globalization;
using System.IO;
using System.Linq;
-using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Framework.Content;
using StardewModdingAPI.Framework.Exceptions;
@@ -53,16 +52,16 @@ namespace StardewModdingAPI.Framework.ContentManagers
/*********
** Accessors
*********/
- /// <summary>A name for the mod manager. Not guaranteed to be unique.</summary>
+ /// <inheritdoc />
public string Name { get; }
- /// <summary>The current language as a constant.</summary>
+ /// <inheritdoc />
public LanguageCode Language => this.GetCurrentLanguage();
- /// <summary>The absolute path to the <see cref="ContentManager.RootDirectory"/>.</summary>
+ /// <inheritdoc />
public string FullRootDirectory => Path.Combine(Constants.ExecutionPath, this.RootDirectory);
- /// <summary>Whether this content manager can be targeted by managed asset keys (e.g. to load assets from a mod folder).</summary>
+ /// <inheritdoc />
public bool IsNamespaced { get; }
@@ -97,56 +96,42 @@ namespace StardewModdingAPI.Framework.ContentManagers
this.BaseDisposableReferences = reflection.GetField<List<IDisposable>>(this, "disposableAssets").GetValue();
}
- /// <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>
+ /// <inheritdoc />
public override T Load<T>(string assetName)
{
return this.Load<T>(assetName, this.Language, useCache: true);
}
- /// <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>
+ /// <inheritdoc />
public override T Load<T>(string assetName, LanguageCode language)
{
return this.Load<T>(assetName, language, useCache: true);
}
- /// <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>
- /// <param name="useCache">Whether to read/write the loaded asset to the asset cache.</param>
+ /// <inheritdoc />
public abstract T Load<T>(string assetName, LocalizedContentManager.LanguageCode language, bool useCache);
- /// <summary>Load the base asset without localization.</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>
+ /// <inheritdoc />
[Obsolete("This method is implemented for the base game and should not be used directly. To load an asset from the underlying content manager directly, use " + nameof(BaseContentManager.RawLoad) + " instead.")]
public override T LoadBase<T>(string assetName)
{
return this.Load<T>(assetName, LanguageCode.en, useCache: true);
}
- /// <summary>Perform any cleanup needed when the locale changes.</summary>
+ /// <inheritdoc />
public virtual void OnLocaleChanged() { }
/// <inheritdoc />
public virtual void OnReturningToTitleScreen() { }
- /// <summary>Normalize path separators in a file path. For asset keys, see <see cref="AssertAndNormalizeAssetName"/> instead.</summary>
- /// <param name="path">The file path to normalize.</param>
+ /// <inheritdoc />
[Pure]
public string NormalizePathSeparators(string path)
{
return this.Cache.NormalizePathSeparators(path);
}
- /// <summary>Assert that the given key has a valid format and return a normalized form consistent with the underlying cache.</summary>
- /// <param name="assetName">The asset key to check.</param>
- /// <exception cref="SContentLoadException">The asset key is empty or contains invalid characters.</exception>
+ /// <inheritdoc />
[SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local", Justification = "Parameter is only used for assertion checks by design.")]
public string AssertAndNormalizeAssetName(string assetName)
{
@@ -163,29 +148,26 @@ namespace StardewModdingAPI.Framework.ContentManagers
/****
** Content loading
****/
- /// <summary>Get the current content locale.</summary>
+ /// <inheritdoc />
public string GetLocale()
{
return this.GetLocale(this.GetCurrentLanguage());
}
- /// <summary>The locale for a language.</summary>
- /// <param name="language">The language.</param>
+ /// <inheritdoc />
public string GetLocale(LanguageCode language)
{
return this.LanguageCodeString(language);
}
- /// <summary>Get whether the content manager has already loaded and cached the given asset.</summary>
- /// <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.</param>
+ /// <inheritdoc />
public bool IsLoaded(string assetName, LanguageCode language)
{
assetName = this.Cache.NormalizeKey(assetName);
return this.IsNormalizedKeyLoaded(assetName, language);
}
- /// <summary>Get the cached asset keys.</summary>
+ /// <inheritdoc />
public IEnumerable<string> GetAssetKeys()
{
return this.Cache.Keys
@@ -196,10 +178,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
/****
** Cache invalidation
****/
- /// <summary>Purge matched assets from the cache.</summary>
- /// <param name="predicate">Matches the asset keys to invalidate.</param>
- /// <param name="dispose">Whether to dispose invalidated assets. This should only be <c>true</c> when they're being invalidated as part of a dispose, to avoid crashing the game.</param>
- /// <returns>Returns the invalidated asset names and instances.</returns>
+ /// <inheritdoc />
public IDictionary<string, object> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false)
{
IDictionary<string, object> removeAssets = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
@@ -228,8 +207,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
return removeAssets;
}
- /// <summary>Dispose held resources.</summary>
- /// <param name="isDisposing">Whether the content manager is being disposed (rather than finalized).</param>
+ /// <inheritdoc />
protected override void Dispose(bool isDisposing)
{
// ignore if disposed
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
index e3d1e569..8e78faba 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
@@ -59,11 +59,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
this.OnLoadingFirstAsset = onLoadingFirstAsset;
}
- /// <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>
- /// <param name="useCache">Whether to read/write the loaded asset to the asset cache.</param>
+ /// <inheritdoc />
public override T Load<T>(string assetName, LocalizedContentManager.LanguageCode language, bool useCache)
{
// raise first-load callback
@@ -95,7 +91,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
if (this.AssetsBeingLoaded.Contains(assetName))
{
this.Monitor.Log($"Broke loop while loading asset '{assetName}'.", LogLevel.Warn);
- this.Monitor.Log($"Bypassing mod loaders for this asset. Stack trace:\n{Environment.StackTrace}", LogLevel.Trace);
+ this.Monitor.Log($"Bypassing mod loaders for this asset. Stack trace:\n{Environment.StackTrace}");
data = this.RawLoad<T>(assetName, language, useCache);
}
else
@@ -117,7 +113,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
return data;
}
- /// <summary>Perform any cleanup needed when the locale changes.</summary>
+ /// <inheritdoc />
public override void OnLocaleChanged()
{
base.OnLocaleChanged();
@@ -137,7 +133,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
.OrderBy(p => p, StringComparer.OrdinalIgnoreCase)
.ToArray();
if (invalidated.Any())
- this.Monitor.Log($"Invalidated {invalidated.Length} asset names: {string.Join(", ", invalidated)} for locale change.", LogLevel.Trace);
+ this.Monitor.Log($"Invalidated {invalidated.Length} asset names: {string.Join(", ", invalidated)} for locale change.");
}
/// <inheritdoc />
@@ -165,7 +161,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
this.InvalidateCache((_, _) => true);
}
- /// <summary>Create a new content manager for temporary use.</summary>
+ /// <inheritdoc />
public override LocalizedContentManager CreateTemporary()
{
return this.Coordinator.CreateGameContentManager("(temporary)");
@@ -175,9 +171,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
/*********
** Private methods
*********/
- /// <summary>Get whether an asset has already been loaded.</summary>
- /// <param name="normalizedAssetName">The normalized asset name.</param>
- /// <param name="language">The language to check.</param>
+ /// <inheritdoc />
protected override bool IsNormalizedKeyLoaded(string normalizedAssetName, LanguageCode language)
{
string cachedKey = null;
@@ -191,12 +185,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
: this.Cache.ContainsKey(normalizedAssetName);
}
- /// <summary>Add tracking data to an asset and add it to 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>
- /// <param name="language">The language code for which to inject the asset.</param>
- /// <param name="useCache">Whether to save the asset to the asset cache.</param>
+ /// <inheritdoc />
protected override void TrackAsset<T>(string assetName, T value, LanguageCode language, bool useCache)
{
// handle explicit language in asset name
@@ -384,7 +373,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
try
{
editor.Edit<T>(asset);
- this.Monitor.Log($"{mod.DisplayName} edited {info.AssetName}.", LogLevel.Trace);
+ this.Monitor.Log($"{mod.DisplayName} edited {info.AssetName}.");
}
catch (Exception ex)
{
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManagerForAssetPropagation.cs b/src/SMAPI/Framework/ContentManagers/GameContentManagerForAssetPropagation.cs
index cbbebf02..61683ce6 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManagerForAssetPropagation.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManagerForAssetPropagation.cs
@@ -37,7 +37,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>Get whether a texture was loaded by this content manager.</summary>
/// <param name="texture">The texture to check.</param>
- public bool IsReponsibleFor(Texture2D texture)
+ public bool IsResponsibleFor(Texture2D texture)
{
return
texture?.Tag is string tag
diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
index 284c1f37..9af14cb5 100644
--- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
@@ -59,28 +59,19 @@ namespace StardewModdingAPI.Framework.ContentManagers
this.ModName = modName;
}
- /// <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>
+ /// <inheritdoc />
public override T Load<T>(string assetName)
{
return this.Load<T>(assetName, this.DefaultLanguage, useCache: false);
}
- /// <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>
+ /// <inheritdoc />
public override T Load<T>(string assetName, LanguageCode language)
{
return this.Load<T>(assetName, language, useCache: false);
}
- /// <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>
- /// <param name="useCache">Whether to read/write the loaded asset to the asset cache.</param>
+ /// <inheritdoc />
public override T Load<T>(string assetName, LanguageCode language, bool useCache)
{
assetName = this.AssertAndNormalizeAssetName(assetName);
@@ -190,7 +181,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
return asset;
}
- /// <summary>Create a new content manager for temporary use.</summary>
+ /// <inheritdoc />
public override LocalizedContentManager CreateTemporary()
{
throw new NotSupportedException("Can't create a temporary mod content manager.");
@@ -210,9 +201,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
/*********
** Private methods
*********/
- /// <summary>Get whether an asset has already been loaded.</summary>
- /// <param name="normalizedAssetName">The normalized asset name.</param>
- /// <param name="language">The language to check.</param>
+ /// <inheritdoc />
protected override bool IsNormalizedKeyLoaded(string normalizedAssetName, LanguageCode language)
{
return this.Cache.ContainsKey(normalizedAssetName);
diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs
index 5fb1b10d..8b591bc1 100644
--- a/src/SMAPI/Metadata/CoreAssetPropagator.cs
+++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs
@@ -1201,7 +1201,7 @@ namespace StardewModdingAPI.Metadata
GameContentManagerForAssetPropagation content = this.DisposableContentManager;
Texture2D newTexture = content.Load<Texture2D>(key);
- if (oldTexture?.IsDisposed == false && !object.ReferenceEquals(oldTexture, newTexture) && content.IsReponsibleFor(oldTexture))
+ if (oldTexture?.IsDisposed == false && !object.ReferenceEquals(oldTexture, newTexture) && content.IsResponsibleFor(oldTexture))
oldTexture.Dispose();
return newTexture;