From 529e0dbb84548ac47d6b3ca9ac892b743171886e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 25 Feb 2017 19:08:21 -0500 Subject: fix handling of localised XNB files (#173) --- .../Framework/ContentEventHelper.cs | 39 ++++++++-------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'src/StardewModdingAPI/Framework/ContentEventHelper.cs') diff --git a/src/StardewModdingAPI/Framework/ContentEventHelper.cs b/src/StardewModdingAPI/Framework/ContentEventHelper.cs index d4a9bbb8..a58efe32 100644 --- a/src/StardewModdingAPI/Framework/ContentEventHelper.cs +++ b/src/StardewModdingAPI/Framework/ContentEventHelper.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text.RegularExpressions; using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI.Framework @@ -18,8 +17,11 @@ namespace StardewModdingAPI.Framework /********* ** Accessors *********/ - /// The normalised asset path being read. The format may change between platforms; see to compare with a known path. - public string Path { get; } + /// The content's locale code, if the content is localised. + public string Locale { get; } + + /// The normalised asset name being read. The format may change between platforms; see to compare with a known path. + public string AssetName { get; } /// The content data being read. public object Data { get; private set; } @@ -29,37 +31,24 @@ namespace StardewModdingAPI.Framework ** Public methods *********/ /// Construct an instance. - /// The file path being read. + /// The content's locale code, if the content is localised. + /// The normalised asset name being read. /// The content data being read. /// Normalises an asset key to match the cache key. - public ContentEventHelper(string path, object data, Func getNormalisedPath) + public ContentEventHelper(string locale, string assetName, object data, Func getNormalisedPath) { - this.Path = path; + this.Locale = locale; + this.AssetName = assetName; this.Data = data; this.GetNormalisedPath = getNormalisedPath; } - /// Get whether the asset path being loaded matches a given path after normalisation. - /// The expected asset path, relative to the game folder and without the .xnb extension (like 'Data\ObjectInformation'). - /// Whether to match a localised version of the asset file (like 'Data\ObjectInformation.ja-JP'). - public bool IsPath(string path, bool matchLocalisedVersion = true) + /// Get whether the asset name being loaded matches a given name after normalisation. + /// The expected asset path, relative to the game's content folder and without the .xnb extension or locale suffix (like 'Data\ObjectInformation'). + public bool IsAssetName(string path) { path = this.GetNormalisedPath(path); - - // equivalent - if (this.Path.Equals(path, StringComparison.InvariantCultureIgnoreCase)) - return true; - - // localised version - if (matchLocalisedVersion) - { - return - this.Path.StartsWith($"{path}.", StringComparison.InvariantCultureIgnoreCase) // starts with given path - && Regex.IsMatch(this.Path.Substring(path.Length + 1), "^[a-z]+-[A-Z]+$"); // ends with locale (e.g. pt-BR) - } - - // no match - return false; + return this.AssetName.Equals(path, StringComparison.InvariantCultureIgnoreCase); } /// Get the data as a given type. -- cgit