summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Content
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-02-19 20:18:30 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-02-19 20:18:30 -0500
commit3b4e81bf69e28c9bcc33c782f58e5099d73c4f91 (patch)
treeaf170db0e147740b7acaa231b59d11a87ad15ad6 /src/SMAPI/Framework/Content
parent049952de33b9d3e1ba81c27212f75268d8ed76f1 (diff)
downloadSMAPI-3b4e81bf69e28c9bcc33c782f58e5099d73c4f91.tar.gz
SMAPI-3b4e81bf69e28c9bcc33c782f58e5099d73c4f91.tar.bz2
SMAPI-3b4e81bf69e28c9bcc33c782f58e5099d73c4f91.zip
encapsulate path utilities for reuse, add unit tests
Diffstat (limited to 'src/SMAPI/Framework/Content')
-rw-r--r--src/SMAPI/Framework/Content/ContentCache.cs19
1 files changed, 3 insertions, 16 deletions
diff --git a/src/SMAPI/Framework/Content/ContentCache.cs b/src/SMAPI/Framework/Content/ContentCache.cs
index 4508e641..533da398 100644
--- a/src/SMAPI/Framework/Content/ContentCache.cs
+++ b/src/SMAPI/Framework/Content/ContentCache.cs
@@ -5,6 +5,7 @@ using System.Linq;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading;
using StardewModdingAPI.Framework.Reflection;
+using StardewModdingAPI.Framework.Utilities;
using StardewValley;
namespace StardewModdingAPI.Framework.Content
@@ -18,12 +19,6 @@ namespace StardewModdingAPI.Framework.Content
/// <summary>The underlying asset cache.</summary>
private readonly IDictionary<string, object> Cache;
- /// <summary>The possible directory separator characters in an asset key.</summary>
- private readonly char[] PossiblePathSeparators;
-
- /// <summary>The preferred directory separator chaeacter in an asset key.</summary>
- private readonly string PreferredPathSeparator;
-
/// <summary>Applies platform-specific asset key normalisation so it's consistent with the underlying cache.</summary>
private readonly Func<string, string> NormaliseAssetNameForPlatform;
@@ -52,14 +47,10 @@ namespace StardewModdingAPI.Framework.Content
/// <summary>Construct an instance.</summary>
/// <param name="contentManager">The underlying content manager whose cache to manage.</param>
/// <param name="reflection">Simplifies access to private game code.</param>
- /// <param name="possiblePathSeparators">The possible directory separator characters in an asset key.</param>
- /// <param name="preferredPathSeparator">The preferred directory separator chaeacter in an asset key.</param>
- public ContentCache(LocalizedContentManager contentManager, Reflector reflection, char[] possiblePathSeparators, string preferredPathSeparator)
+ public ContentCache(LocalizedContentManager contentManager, Reflector reflection)
{
// init
this.Cache = reflection.GetField<Dictionary<string, object>>(contentManager, "loadedAssets").GetValue();
- this.PossiblePathSeparators = possiblePathSeparators;
- this.PreferredPathSeparator = preferredPathSeparator;
// get key normalisation logic
if (Constants.TargetPlatform == Platform.Windows)
@@ -90,11 +81,7 @@ namespace StardewModdingAPI.Framework.Content
[Pure]
public string NormalisePathSeparators(string path)
{
- string[] parts = path.Split(this.PossiblePathSeparators, StringSplitOptions.RemoveEmptyEntries);
- string normalised = string.Join(this.PreferredPathSeparator, parts);
- if (path.StartsWith(this.PreferredPathSeparator))
- normalised = this.PreferredPathSeparator + normalised; // keep root slash
- return normalised;
+ return PathUtilities.NormalisePathSeparators(path);
}
/// <summary>Normalise a cache key so it's consistent with the underlying cache.</summary>