From 8789b7efa816aab0f4ce9d3149c26b8033e0b0a5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 2 Sep 2021 18:54:56 -0400 Subject: 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. --- src/SMAPI.Toolkit/Utilities/PathUtilities.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Toolkit/Utilities') 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 /// The possible directory separator characters in a file path. public static readonly char[] PossiblePathSeparators = new[] { '/', '\\', Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }.Distinct().ToArray(); - /// The preferred directory separator character in an asset key. + /// The preferred directory separator character in a file path. public static readonly char PreferredPathSeparator = Path.DirectorySeparatorChar; + /// The preferred directory separator character in an asset key. + public static readonly char PreferredAssetSeparator = PathUtilities.PreferredPathSeparator; + /********* ** Public methods @@ -41,8 +44,16 @@ namespace StardewModdingAPI.Toolkit.Utilities : path.Split(PathUtilities.PossiblePathSeparators, StringSplitOptions.RemoveEmptyEntries); } - /// Normalize separators in a file path. + /// Normalize an asset name to match how MonoGame's content APIs would normalize and cache it. + /// The asset name to normalize. + public static string NormalizeAssetName(string assetName) + { + return string.Join(PathUtilities.PreferredAssetSeparator.ToString(), PathUtilities.GetSegments(assetName)); // based on MonoGame's ContentManager.Load logic + } + + /// Normalize separators in a file path for the current platform. /// The file path to normalize. + /// This should only be used for file paths. For asset names, use instead. [Pure] public static string NormalizePath(string path) { -- cgit