diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-09-02 18:54:56 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-09-02 18:54:56 -0400 |
commit | 8789b7efa816aab0f4ce9d3149c26b8033e0b0a5 (patch) | |
tree | 392f2f010ebcb7f795c8e1cc75286396f3fa8e44 /src/SMAPI.Toolkit/Utilities | |
parent | 5848a355bac789ba8d879df64bea400d17ea83f5 (diff) | |
download | SMAPI-8789b7efa816aab0f4ce9d3149c26b8033e0b0a5.tar.gz SMAPI-8789b7efa816aab0f4ce9d3149c26b8033e0b0a5.tar.bz2 SMAPI-8789b7efa816aab0f4ce9d3149c26b8033e0b0a5.zip |
prepare path utilities for the upcoming Stardew Valley 1.5.5
The game will use Linux-style paths for assets on all platforms, which will break the current equivalence between path and asset name formats.
Diffstat (limited to 'src/SMAPI.Toolkit/Utilities')
-rw-r--r-- | src/SMAPI.Toolkit/Utilities/PathUtilities.cs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs index babc0981..020ebc6d 100644 --- a/src/SMAPI.Toolkit/Utilities/PathUtilities.cs +++ b/src/SMAPI.Toolkit/Utilities/PathUtilities.cs @@ -23,9 +23,12 @@ namespace StardewModdingAPI.Toolkit.Utilities /// <summary>The possible directory separator characters in a file path.</summary> public static readonly char[] PossiblePathSeparators = new[] { '/', '\\', Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }.Distinct().ToArray(); - /// <summary>The preferred directory separator character in an asset key.</summary> + /// <summary>The preferred directory separator character in a file path.</summary> public static readonly char PreferredPathSeparator = Path.DirectorySeparatorChar; + /// <summary>The preferred directory separator character in an asset key.</summary> + public static readonly char PreferredAssetSeparator = PathUtilities.PreferredPathSeparator; + /********* ** Public methods @@ -41,8 +44,16 @@ namespace StardewModdingAPI.Toolkit.Utilities : path.Split(PathUtilities.PossiblePathSeparators, StringSplitOptions.RemoveEmptyEntries); } - /// <summary>Normalize separators in a file path.</summary> + /// <summary>Normalize an asset name to match how MonoGame's content APIs would normalize and cache it.</summary> + /// <param name="assetName">The asset name to normalize.</param> + public static string NormalizeAssetName(string assetName) + { + return string.Join(PathUtilities.PreferredAssetSeparator.ToString(), PathUtilities.GetSegments(assetName)); // based on MonoGame's ContentManager.Load<T> logic + } + + /// <summary>Normalize separators in a file path for the current platform.</summary> /// <param name="path">The file path to normalize.</param> + /// <remarks>This should only be used for file paths. For asset names, use <see cref="NormalizeAssetName"/> instead.</remarks> [Pure] public static string NormalizePath(string path) { |