diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-09-07 13:06:27 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-09-07 13:06:27 -0400 |
commit | 5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83 (patch) | |
tree | 0a42305174eb84561a584549cd685c5e95670f36 /src/SMAPI/Framework/ModHelpers/ContentHelper.cs | |
parent | 8da88b8fe5b41739c5cd0df3280b9770fc7f10a4 (diff) | |
parent | f9fac11028354f15d786d5b854608edb10716f79 (diff) | |
download | SMAPI-5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83.tar.gz SMAPI-5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83.tar.bz2 SMAPI-5e43bdbf5cd6dbab36c25287c85d42ccfeea2c83.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ModHelpers/ContentHelper.cs')
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 44 |
1 files changed, 11 insertions, 33 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 23e45fd1..5fd8f5e9 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -5,13 +5,10 @@ using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.IO; using System.Linq; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Content; using StardewModdingAPI.Framework.ContentManagers; using StardewModdingAPI.Framework.Exceptions; using StardewValley; -using xTile; namespace StardewModdingAPI.Framework.ModHelpers { @@ -40,10 +37,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /********* ** Accessors *********/ - /// <summary>The game's current locale code (like <c>pt-BR</c>).</summary> + /// <inheritdoc /> public string CurrentLocale => this.GameContentManager.GetLocale(); - /// <summary>The game's current locale as an enum value.</summary> + /// <inheritdoc /> public LocalizedContentManager.LanguageCode CurrentLocaleConstant => this.GameContentManager.Language; /// <summary>The observable implementation of <see cref="AssetEditors"/>.</summary> @@ -52,10 +49,10 @@ namespace StardewModdingAPI.Framework.ModHelpers /// <summary>The observable implementation of <see cref="AssetLoaders"/>.</summary> internal ObservableCollection<IAssetLoader> ObservableAssetLoaders { get; } = new ObservableCollection<IAssetLoader>(); - /// <summary>Interceptors which provide the initial versions of matching content assets.</summary> + /// <inheritdoc /> public IList<IAssetLoader> AssetLoaders => this.ObservableAssetLoaders; - /// <summary>Interceptors which edit matching content assets after they're loaded.</summary> + /// <inheritdoc /> public IList<IAssetEditor> AssetEditors => this.ObservableAssetEditors; @@ -80,12 +77,7 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Monitor = monitor; } - /// <summary>Load content from the game folder or mod folder (if not already cached), and return it. When loading a <c>.png</c> file, this must be called outside the game's draw loop.</summary> - /// <typeparam name="T">The expected data type. The main supported types are <see cref="Map"/>, <see cref="Texture2D"/>, and dictionaries; other types may be supported by the game's content pipeline.</typeparam> - /// <param name="key">The asset key to fetch (if the <paramref name="source"/> is <see cref="ContentSource.GameContent"/>), or the local path to a content file relative to the mod folder.</param> - /// <param name="source">Where to search for a matching content asset.</param> - /// <exception cref="ArgumentException">The <paramref name="key"/> is empty or contains invalid characters.</exception> - /// <exception cref="ContentLoadException">The content asset couldn't be loaded (e.g. because it doesn't exist).</exception> + /// <inheritdoc /> public T Load<T>(string key, ContentSource source = ContentSource.ModFolder) { try @@ -109,18 +101,14 @@ namespace StardewModdingAPI.Framework.ModHelpers } } - /// <summary>Normalize an asset name so it's consistent with those generated by the game. This is mainly useful for string comparisons like <see cref="string.StartsWith(string)"/> on generated asset names, and isn't necessary when passing asset names into other content helper methods.</summary> - /// <param name="assetName">The asset key.</param> + /// <inheritdoc /> [Pure] public string NormalizeAssetName(string assetName) { return this.ModContentManager.AssertAndNormalizeAssetName(assetName); } - /// <summary>Get the underlying key in the game's content cache for an asset. This can be used to load custom map tilesheets, but should be avoided when you can use the content API instead. This does not validate whether the asset exists.</summary> - /// <param name="key">The asset key to fetch (if the <paramref name="source"/> is <see cref="ContentSource.GameContent"/>), or the local path to a content file relative to the mod folder.</param> - /// <param name="source">Where to search for a matching content asset.</param> - /// <exception cref="ArgumentException">The <paramref name="key"/> is empty or contains invalid characters.</exception> + /// <inheritdoc /> public string GetActualAssetKey(string key, ContentSource source = ContentSource.ModFolder) { switch (source) @@ -136,10 +124,7 @@ namespace StardewModdingAPI.Framework.ModHelpers } } - /// <summary>Remove an asset from the content cache so it's reloaded on the next request. This will reload core game assets if needed, but references to the former asset will still show the previous content.</summary> - /// <param name="key">The asset key to invalidate in the content folder.</param> - /// <exception cref="ArgumentException">The <paramref name="key"/> is empty or contains invalid characters.</exception> - /// <returns>Returns whether the given asset key was cached.</returns> + /// <inheritdoc /> public bool InvalidateCache(string key) { string actualKey = this.GetActualAssetKey(key, ContentSource.GameContent); @@ -147,28 +132,21 @@ namespace StardewModdingAPI.Framework.ModHelpers return this.ContentCore.InvalidateCache(asset => asset.AssetNameEquals(actualKey)).Any(); } - /// <summary>Remove all assets of the given type from the cache so they're reloaded on the next request. <b>This can be a very expensive operation and should only be used in very specific cases.</b> This will reload core game assets if needed, but references to the former assets will still show the previous content.</summary> - /// <typeparam name="T">The asset type to remove from the cache.</typeparam> - /// <returns>Returns whether any assets were invalidated.</returns> + /// <inheritdoc /> public bool InvalidateCache<T>() { this.Monitor.Log($"Requested cache invalidation for all assets of type {typeof(T)}. This is an expensive operation and should be avoided if possible.", LogLevel.Trace); return this.ContentCore.InvalidateCache((key, type) => typeof(T).IsAssignableFrom(type)).Any(); } - /// <summary>Remove matching assets from the content cache so they're reloaded on the next request. This will reload core game assets if needed, but references to the former asset will still show the previous content.</summary> - /// <param name="predicate">A predicate matching the assets to invalidate.</param> - /// <returns>Returns whether any cache entries were invalidated.</returns> + /// <inheritdoc /> public bool InvalidateCache(Func<IAssetInfo, bool> predicate) { this.Monitor.Log("Requested cache invalidation for all assets matching a predicate.", LogLevel.Trace); return this.ContentCore.InvalidateCache(predicate).Any(); } - /// <summary>Get a patch helper for arbitrary data.</summary> - /// <typeparam name="T">The data type.</typeparam> - /// <param name="data">The asset data.</param> - /// <param name="assetName">The asset name. This is only used for tracking purposes and has no effect on the patch helper.</param> + /// <inheritdoc /> public IAssetData GetPatchHelper<T>(T data, string assetName = null) { if (data == null) |