diff options
Diffstat (limited to 'src/SMAPI')
-rw-r--r-- | src/SMAPI/Events/AssetRequestedEventArgs.cs | 7 | ||||
-rw-r--r-- | src/SMAPI/Framework/ContentCoordinator.cs | 5 | ||||
-rw-r--r-- | src/SMAPI/Framework/ContentManagers/BaseContentManager.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/Framework/ContentManagers/GameContentManager.cs | 8 | ||||
-rw-r--r-- | src/SMAPI/Framework/ContentManagers/IContentManager.cs | 3 | ||||
-rw-r--r-- | src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 4 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 2 | ||||
-rw-r--r-- | src/SMAPI/IContentHelper.cs | 4 |
9 files changed, 24 insertions, 13 deletions
diff --git a/src/SMAPI/Events/AssetRequestedEventArgs.cs b/src/SMAPI/Events/AssetRequestedEventArgs.cs index 4d9ee236..c0cbd8fb 100644 --- a/src/SMAPI/Events/AssetRequestedEventArgs.cs +++ b/src/SMAPI/Events/AssetRequestedEventArgs.cs @@ -30,6 +30,9 @@ namespace StardewModdingAPI.Events /// <remarks>For example, if <see cref="Name"/> contains a locale like <c>Data/Bundles.fr-FR</c>, this will be the name without locale like <c>Data/Bundles</c>. If the name has no locale, this field is equivalent.</remarks> public IAssetName NameWithoutLocale { get; } + /// <summary>The requested data type.</summary> + public Type DataType { get; } + /// <summary>The load operations requested by the event handler.</summary> internal IList<AssetLoadOperation> LoadOperations { get; } = new List<AssetLoadOperation>(); @@ -43,13 +46,15 @@ namespace StardewModdingAPI.Events /// <summary>Construct an instance.</summary> /// <param name="mod">The mod handling the event.</param> /// <param name="name">The name of the asset being requested.</param> + /// <param name="dataType">The requested data type.</param> /// <param name="nameWithoutLocale">The <paramref name="name"/> with any locale codes stripped.</param> /// <param name="getOnBehalfOf">Get the mod metadata for a content pack, if it's a valid content pack for the mod.</param> - internal AssetRequestedEventArgs(IModMetadata mod, IAssetName name, IAssetName nameWithoutLocale, Func<IModMetadata, string, string, IModMetadata> getOnBehalfOf) + internal AssetRequestedEventArgs(IModMetadata mod, IAssetName name, IAssetName nameWithoutLocale, Type dataType, Func<IModMetadata, string, string, IModMetadata> getOnBehalfOf) { this.Mod = mod; this.Name = name; this.NameWithoutLocale = nameWithoutLocale; + this.DataType = dataType; this.GetOnBehalfOf = getOnBehalfOf; } diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index ee8b6893..108257bf 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -315,9 +315,10 @@ namespace StardewModdingAPI.Framework } /// <summary>Get whether an asset from a mod folder exists.</summary> + /// <typeparam name="T">The expected asset type.</typeparam> /// <param name="contentManagerID">The unique name for the content manager which should load this asset.</param> /// <param name="assetName">The asset name within the mod folder.</param> - public bool DoesManagedAssetExist(string contentManagerID, IAssetName assetName) + public bool DoesManagedAssetExist<T>(string contentManagerID, IAssetName assetName) { // get content manager IContentManager contentManager = this.ContentManagerLock.InReadLock(() => @@ -327,7 +328,7 @@ namespace StardewModdingAPI.Framework throw new InvalidOperationException($"The '{contentManagerID}' prefix isn't handled by any mod."); // get whether the asset exists - return contentManager.DoesAssetExist(assetName); + return contentManager.DoesAssetExist<T>(assetName); } /// <summary>Get a copy of an asset from a mod folder.</summary> diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs index 1ca84792..f41a9354 100644 --- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs @@ -97,7 +97,7 @@ namespace StardewModdingAPI.Framework.ContentManagers } /// <inheritdoc /> - public virtual bool DoesAssetExist(IAssetName assetName) + public virtual bool DoesAssetExist<T>(IAssetName assetName) { return this.Cache.ContainsKey(assetName.Name); } diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index 0fcad30a..3d37e32a 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -58,9 +58,9 @@ namespace StardewModdingAPI.Framework.ContentManagers } /// <inheritdoc /> - public override bool DoesAssetExist(IAssetName assetName) + public override bool DoesAssetExist<T>(IAssetName assetName) { - if (base.DoesAssetExist(assetName)) + if (base.DoesAssetExist<T>(assetName)) return true; // vanilla asset @@ -69,11 +69,11 @@ namespace StardewModdingAPI.Framework.ContentManagers // managed asset if (this.Coordinator.TryParseManagedAssetKey(assetName.Name, out string contentManagerID, out IAssetName relativePath)) - return this.Coordinator.DoesManagedAssetExist(contentManagerID, relativePath); + return this.Coordinator.DoesManagedAssetExist<T>(contentManagerID, relativePath); // custom asset from a loader string locale = this.GetLocale(); - IAssetInfo info = new AssetInfo(locale, assetName, typeof(object), this.AssertAndNormalizeAssetName); + IAssetInfo info = new AssetInfo(locale, assetName, typeof(T), this.AssertAndNormalizeAssetName); AssetLoadOperation[] loaders = this.GetLoaders<object>(info).ToArray(); if (!this.AssertMaxOneRequiredLoader(info, loaders, out string error)) diff --git a/src/SMAPI/Framework/ContentManagers/IContentManager.cs b/src/SMAPI/Framework/ContentManagers/IContentManager.cs index 774b20d9..90095492 100644 --- a/src/SMAPI/Framework/ContentManagers/IContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/IContentManager.cs @@ -29,8 +29,9 @@ namespace StardewModdingAPI.Framework.ContentManagers ** Methods *********/ /// <summary>Get whether an asset exists and can be loaded.</summary> + /// <typeparam name="T">The expected asset type.</typeparam> /// <param name="assetName">The normalized asset name.</param> - bool DoesAssetExist(IAssetName assetName); + bool DoesAssetExist<T>(IAssetName assetName); /// <summary>Load an asset through the content pipeline, using a localized variant of the <paramref name="assetName"/> if available.</summary> /// <typeparam name="T">The type of asset to load.</typeparam> diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 375b5e0e..2a5a3f16 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -66,9 +66,9 @@ namespace StardewModdingAPI.Framework.ContentManagers } /// <inheritdoc /> - public override bool DoesAssetExist(IAssetName assetName) + public override bool DoesAssetExist<T>(IAssetName assetName) { - if (base.DoesAssetExist(assetName)) + if (base.DoesAssetExist<T>(assetName)) return true; FileInfo file = this.GetModFile(assetName.Name); diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 5d58ee26..3a5c8938 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -44,9 +44,11 @@ namespace StardewModdingAPI.Framework.ModHelpers public LocalizedContentManager.LanguageCode CurrentLocaleConstant => this.GameContentManager.Language; /// <summary>The observable implementation of <see cref="AssetEditors"/>.</summary> + [Obsolete] internal ObservableCollection<IAssetEditor> ObservableAssetEditors { get; } = new(); /// <summary>The observable implementation of <see cref="AssetLoaders"/>.</summary> + [Obsolete] internal ObservableCollection<IAssetLoader> ObservableAssetLoaders { get; } = new(); /// <inheritdoc /> diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 5deb177c..efdfabe7 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1151,7 +1151,7 @@ namespace StardewModdingAPI.Framework this.EventManager.AssetRequested.Raise( invoke: (mod, invoke) => { - AssetRequestedEventArgs args = new(mod, asset.Name, asset.NameWithoutLocale, this.GetOnBehalfOfContentPack); + AssetRequestedEventArgs args = new(mod, asset.Name, asset.NameWithoutLocale, asset.DataType, this.GetOnBehalfOfContentPack); invoke(args); diff --git a/src/SMAPI/IContentHelper.cs b/src/SMAPI/IContentHelper.cs index 6fcd18cd..1d36abff 100644 --- a/src/SMAPI/IContentHelper.cs +++ b/src/SMAPI/IContentHelper.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI.Framework.Content; +using StardewModdingAPI.Events; using StardewValley; using xTile; @@ -16,9 +16,11 @@ namespace StardewModdingAPI ** Accessors *********/ /// <summary>Interceptors which provide the initial versions of matching content assets.</summary> + [Obsolete($"Use {nameof(IMod.Helper)}.{nameof(IModHelper.Events)}.{nameof(IModEvents.Content)} instead. This interface will be removed in SMAPI 4.0.0.")] IList<IAssetLoader> AssetLoaders { get; } /// <summary>Interceptors which edit matching content assets after they're loaded.</summary> + [Obsolete($"Use {nameof(IMod.Helper)}.{nameof(IModHelper.Events)}.{nameof(IModEvents.Content)} instead. This interface will be removed in SMAPI 4.0.0.")] IList<IAssetEditor> AssetEditors { get; } /// <summary>The game's current locale code (like <c>pt-BR</c>).</summary> |