From bacb851d7b186946ba1ead1caeab72e7604cfe6b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 26 Mar 2022 17:44:48 -0400 Subject: [PATCH] add IContentHelper.ParseAssetName (#766) --- docs/release-notes.md | 1 + src/SMAPI/Framework/ModHelpers/ContentHelper.cs | 6 ++++++ src/SMAPI/IContentHelper.cs | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/docs/release-notes.md b/docs/release-notes.md index 464049b9..99ac86df 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -24,6 +24,7 @@ * Added `Constants.ContentPath`. * Added `IAssetName` fields to the info received by `IAssetEditor` and `IAssetLoader` methods. _This adds methods for working with asset names, parsed locales, etc._ + * Added `helper.Content.ParseAssetName` to get an `IAssetName` for an arbitrary asset key. * If an asset is loaded multiple times in the same tick, `IAssetLoader.CanLoad` and `IAssetEditor.CanEdit` are now cached unless invalidated by `helper.Content.InvalidateCache`. * Fixed the `SDate` constructor being case-sensitive. * Fixed support for using locale codes from custom languages in asset names (e.g. `Data/Achievements.eo-EU`). diff --git a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs index 3727b909..5d58ee26 100644 --- a/src/SMAPI/Framework/ModHelpers/ContentHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/ContentHelper.cs @@ -103,6 +103,12 @@ namespace StardewModdingAPI.Framework.ModHelpers this.Monitor = monitor; } + /// + public IAssetName ParseAssetName(string rawName) + { + return this.ContentCore.ParseAssetName(rawName); + } + /// public T Load(string key, ContentSource source = ContentSource.ModFolder) { diff --git a/src/SMAPI/IContentHelper.cs b/src/SMAPI/IContentHelper.cs index 207b4a33..6fcd18cd 100644 --- a/src/SMAPI/IContentHelper.cs +++ b/src/SMAPI/IContentHelper.cs @@ -3,6 +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 StardewValley; using xTile; @@ -30,6 +31,11 @@ namespace StardewModdingAPI /********* ** Public methods *********/ + /// Parse a raw asset name. + /// The raw asset name to parse. + /// The is null or empty. + IAssetName ParseAssetName(string rawName); + /// Load content from the game folder or mod folder (if not already cached), and return it. When loading a .png file, this must be called outside the game's draw loop. /// The expected data type. The main supported types are , , dictionaries, and lists; other types may be supported by the game's content pipeline. /// The asset key to fetch (if the is ), or the local path to a content file relative to the mod folder.