diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs
index b255dae1..fbbbe2d2 100644
--- a/src/SMAPI/Framework/ContentCoordinator.cs
+++ b/src/SMAPI/Framework/ContentCoordinator.cs
@@ -296,6 +296,22 @@ namespace StardewModdingAPI.Framework
return Path.Combine(this.ManagedPrefix, modID.ToLower());
}
+ /// Get whether an asset from a mod folder exists.
+ /// The unique name for the content manager which should load this asset.
+ /// The asset name within the mod folder.
+ public bool DoesManagedAssetExist(string contentManagerID, IAssetName assetName)
+ {
+ // get content manager
+ IContentManager contentManager = this.ContentManagerLock.InReadLock(() =>
+ this.ContentManagers.FirstOrDefault(p => p.IsNamespaced && p.Name == contentManagerID)
+ );
+ if (contentManager == null)
+ throw new InvalidOperationException($"The '{contentManagerID}' prefix isn't handled by any mod.");
+
+ // get whether the asset exists
+ return contentManager.DoesAssetExist(assetName);
+ }
+
/// Get a copy of an asset from a mod folder.
/// The asset type.
/// The unique name for the content manager which should load this asset.
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index 3efc33bb..030c60a7 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -92,6 +92,12 @@ namespace StardewModdingAPI.Framework.ContentManagers
this.BaseDisposableReferences = reflection.GetField>(this, "disposableAssets").GetValue();
}
+ ///
+ public virtual bool DoesAssetExist(IAssetName assetName)
+ {
+ return this.Cache.ContainsKey(assetName.Name);
+ }
+
///
[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(string assetName)
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
index 9f686f97..e7fb0c5f 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
@@ -62,6 +62,29 @@ namespace StardewModdingAPI.Framework.ContentManagers
this.OnLoadingFirstAsset = onLoadingFirstAsset;
}
+ ///
+ public override bool DoesAssetExist(IAssetName assetName)
+ {
+ if (base.DoesAssetExist(assetName))
+ return true;
+
+ // managed asset
+ if (this.Coordinator.TryParseManagedAssetKey(assetName.Name, out string contentManagerID, out IAssetName relativePath))
+ return this.Coordinator.DoesManagedAssetExist(contentManagerID, relativePath);
+
+ // else check for loaders
+ string locale = this.GetLocale();
+ IAssetInfo info = new AssetInfo(locale, assetName, typeof(object), this.AssertAndNormalizeAssetName);
+ ModLinked[] loaders = this.GetLoaders