summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Events/AssetReadyEventArgs.cs8
-rw-r--r--src/SMAPI/Events/AssetRequestedEventArgs.cs8
-rw-r--r--src/SMAPI/Events/AssetsInvalidatedEventArgs.cs9
-rw-r--r--src/SMAPI/Framework/Content/AssetInfo.cs12
-rw-r--r--src/SMAPI/Framework/Content/AssetName.cs9
-rw-r--r--src/SMAPI/Framework/ContentCoordinator.cs6
-rw-r--r--src/SMAPI/Framework/SCore.cs8
-rw-r--r--src/SMAPI/IAssetInfo.cs8
-rw-r--r--src/SMAPI/IAssetName.cs3
9 files changed, 54 insertions, 17 deletions
diff --git a/src/SMAPI/Events/AssetReadyEventArgs.cs b/src/SMAPI/Events/AssetReadyEventArgs.cs
index 946c9173..2c308f18 100644
--- a/src/SMAPI/Events/AssetReadyEventArgs.cs
+++ b/src/SMAPI/Events/AssetReadyEventArgs.cs
@@ -11,15 +11,21 @@ namespace StardewModdingAPI.Events
/// <summary>The name of the asset being requested.</summary>
public IAssetName Name { get; }
+ /// <summary>The <see cref="Name"/> with any locale codes stripped.</summary>
+ /// <remarks>For example, if <see cref="Name"/> contains a locale like <c>Data/Bundles.fr-FR</c>, this will be the name without locale like <c>Data/Bundles</c>. If the name has no locale, this field is equivalent.</remarks>
+ public IAssetName NameWithoutLocale { get; }
+
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="name">The name of the asset being requested.</param>
- internal AssetReadyEventArgs(IAssetName name)
+ /// <param name="nameWithoutLocale">The <paramref name="name"/> with any locale codes stripped.</param>
+ internal AssetReadyEventArgs(IAssetName name, IAssetName nameWithoutLocale)
{
this.Name = name;
+ this.NameWithoutLocale = nameWithoutLocale;
}
}
}
diff --git a/src/SMAPI/Events/AssetRequestedEventArgs.cs b/src/SMAPI/Events/AssetRequestedEventArgs.cs
index d022a4de..9e2cde7f 100644
--- a/src/SMAPI/Events/AssetRequestedEventArgs.cs
+++ b/src/SMAPI/Events/AssetRequestedEventArgs.cs
@@ -26,6 +26,10 @@ namespace StardewModdingAPI.Events
/// <summary>The name of the asset being requested.</summary>
public IAssetName Name { get; }
+ /// <summary>The <see cref="Name"/> with any locale codes stripped.</summary>
+ /// <remarks>For example, if <see cref="Name"/> contains a locale like <c>Data/Bundles.fr-FR</c>, this will be the name without locale like <c>Data/Bundles</c>. If the name has no locale, this field is equivalent.</remarks>
+ public IAssetName NameWithoutLocale { get; }
+
/// <summary>The load operations requested by the event handler.</summary>
internal IList<AssetLoadOperation> LoadOperations { get; } = new List<AssetLoadOperation>();
@@ -39,11 +43,13 @@ namespace StardewModdingAPI.Events
/// <summary>Construct an instance.</summary>
/// <param name="mod">The mod handling the event.</param>
/// <param name="name">The name of the asset being requested.</param>
+ /// <param name="nameWithoutLocale">The <paramref name="name"/> with any locale codes stripped.</param>
/// <param name="getOnBehalfOf">Get the mod metadata for a content pack, if it's a valid content pack for the mod.</param>
- internal AssetRequestedEventArgs(IModMetadata mod, IAssetName name, Func<IModMetadata, string, string, IModMetadata> getOnBehalfOf)
+ internal AssetRequestedEventArgs(IModMetadata mod, IAssetName name, IAssetName nameWithoutLocale, Func<IModMetadata, string, string, IModMetadata> getOnBehalfOf)
{
this.Mod = mod;
this.Name = name;
+ this.NameWithoutLocale = nameWithoutLocale;
this.GetOnBehalfOf = getOnBehalfOf;
}
diff --git a/src/SMAPI/Events/AssetsInvalidatedEventArgs.cs b/src/SMAPI/Events/AssetsInvalidatedEventArgs.cs
index f3d83dd6..614cdf49 100644
--- a/src/SMAPI/Events/AssetsInvalidatedEventArgs.cs
+++ b/src/SMAPI/Events/AssetsInvalidatedEventArgs.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
-using System.Linq;
namespace StardewModdingAPI.Events
{
@@ -14,15 +13,21 @@ namespace StardewModdingAPI.Events
/// <summary>The asset names that were invalidated.</summary>
public IReadOnlySet<IAssetName> Names { get; }
+ /// <summary>The <see cref="Names"/> with any locale codes stripped.</summary>
+ /// <remarks>For example, if <see cref="Names"/> contains a locale like <c>Data/Bundles.fr-FR</c>, this will have the name without locale like <c>Data/Bundles</c>. If the name has no locale, this field is equivalent.</remarks>
+ public IReadOnlySet<IAssetName> NamesWithoutLocale { get; }
+
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="names">The asset names that were invalidated.</param>
- internal AssetsInvalidatedEventArgs(IEnumerable<IAssetName> names)
+ /// <param name="namesWithoutLocale">The <paramref name="names"/> with any locale codes stripped.</param>
+ internal AssetsInvalidatedEventArgs(IEnumerable<IAssetName> names, IEnumerable<IAssetName> namesWithoutLocale)
{
this.Names = names.ToImmutableHashSet();
+ this.NamesWithoutLocale = namesWithoutLocale.ToImmutableHashSet();
}
}
}
diff --git a/src/SMAPI/Framework/Content/AssetInfo.cs b/src/SMAPI/Framework/Content/AssetInfo.cs
index 6a5b4f31..556f1c2a 100644
--- a/src/SMAPI/Framework/Content/AssetInfo.cs
+++ b/src/SMAPI/Framework/Content/AssetInfo.cs
@@ -23,8 +23,11 @@ namespace StardewModdingAPI.Framework.Content
public IAssetName Name { get; }
/// <inheritdoc />
- [Obsolete($"Use {nameof(Name)} instead.")]
- public string AssetName => this.Name.Name;
+ public IAssetName NameWithoutLocale { get; }
+
+ /// <inheritdoc />
+ [Obsolete($"Use {nameof(Name)} or {nameof(NameWithoutLocale)} instead.")]
+ public string AssetName => this.NameWithoutLocale.Name;
/// <inheritdoc />
public Type DataType { get; }
@@ -42,15 +45,16 @@ namespace StardewModdingAPI.Framework.Content
{
this.Locale = locale;
this.Name = assetName;
+ this.NameWithoutLocale = assetName.GetBaseAssetName();
this.DataType = type;
this.GetNormalizedPath = getNormalizedPath;
}
/// <inheritdoc />
- [Obsolete($"Use {nameof(Name)}.{nameof(IAssetName.IsEquivalentTo)} instead.")]
+ [Obsolete($"Use {nameof(Name)}.{nameof(IAssetName.IsEquivalentTo)} or {nameof(NameWithoutLocale)}.{nameof(IAssetName.IsEquivalentTo)} instead.")]
public bool AssetNameEquals(string path)
{
- return this.Name.IsEquivalentTo(path);
+ return this.NameWithoutLocale.IsEquivalentTo(path);
}
diff --git a/src/SMAPI/Framework/Content/AssetName.cs b/src/SMAPI/Framework/Content/AssetName.cs
index 992647f8..7ce0f8ee 100644
--- a/src/SMAPI/Framework/Content/AssetName.cs
+++ b/src/SMAPI/Framework/Content/AssetName.cs
@@ -142,12 +142,21 @@ namespace StardewModdingAPI.Framework.Content
}
+ /// <inheritdoc />
public bool IsDirectlyUnderPath(string assetFolder)
{
return this.StartsWith(assetFolder + "/", allowPartialWord: false, allowSubfolder: false);
}
/// <inheritdoc />
+ IAssetName IAssetName.GetBaseAssetName()
+ {
+ return this.LocaleCode == null
+ ? this
+ : new AssetName(this.BaseName, null, null);
+ }
+
+ /// <inheritdoc />
public bool Equals(IAssetName other)
{
return other switch
diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs
index 144832b2..fc137e50 100644
--- a/src/SMAPI/Framework/ContentCoordinator.cs
+++ b/src/SMAPI/Framework/ContentCoordinator.cs
@@ -53,7 +53,7 @@ namespace StardewModdingAPI.Framework
private readonly Action<BaseContentManager, IAssetName> OnAssetLoaded;
/// <summary>A callback to invoke when any asset names have been invalidated from the cache.</summary>
- private readonly Action<IEnumerable<IAssetName>> OnAssetsInvalidated;
+ private readonly Action<IList<IAssetName>> OnAssetsInvalidated;
/// <summary>Get the load/edit operations to apply to an asset by querying registered <see cref="IContentEvents.AssetRequested"/> event handlers.</summary>
private readonly Func<IAssetInfo, IList<AssetOperationGroup>> RequestAssetOperations;
@@ -118,7 +118,7 @@ namespace StardewModdingAPI.Framework
/// <param name="aggressiveMemoryOptimizations">Whether to enable more aggressive memory optimizations.</param>
/// <param name="onAssetsInvalidated">A callback to invoke when any asset names have been invalidated from the cache.</param>
/// <param name="requestAssetOperations">Get the load/edit operations to apply to an asset by querying registered <see cref="IContentEvents.AssetRequested"/> event handlers.</param>
- public ContentCoordinator(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action onLoadingFirstAsset, Action<BaseContentManager, IAssetName> onAssetLoaded, bool aggressiveMemoryOptimizations, Action<IEnumerable<IAssetName>> onAssetsInvalidated, Func<IAssetInfo, IList<AssetOperationGroup>> requestAssetOperations)
+ public ContentCoordinator(IServiceProvider serviceProvider, string rootDirectory, CultureInfo currentCulture, IMonitor monitor, Reflector reflection, JsonHelper jsonHelper, Action onLoadingFirstAsset, Action<BaseContentManager, IAssetName> onAssetLoaded, bool aggressiveMemoryOptimizations, Action<IList<IAssetName>> onAssetsInvalidated, Func<IAssetInfo, IList<AssetOperationGroup>> requestAssetOperations)
{
this.AggressiveMemoryOptimizations = aggressiveMemoryOptimizations;
this.Monitor = monitor ?? throw new ArgumentNullException(nameof(monitor));
@@ -414,7 +414,7 @@ namespace StardewModdingAPI.Framework
this.AssetOperationsByKey.Remove(name);
// raise event
- this.OnAssetsInvalidated(invalidatedAssets.Keys);
+ this.OnAssetsInvalidated(invalidatedAssets.Keys.ToArray());
// propagate changes to the game
this.CoreAssets.Propagate(
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index dd682e40..dd952dee 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -1113,15 +1113,15 @@ namespace StardewModdingAPI.Framework
private void OnAssetLoaded(IContentManager contentManager, IAssetName assetName)
{
if (this.EventManager.AssetReady.HasListeners())
- this.EventManager.AssetReady.Raise(new AssetReadyEventArgs(assetName));
+ this.EventManager.AssetReady.Raise(new AssetReadyEventArgs(assetName, assetName.GetBaseAssetName()));
}
/// <summary>A callback invoked after assets have been invalidated from the content cache.</summary>
/// <param name="assetNames">The invalidated asset names.</param>
- private void OnAssetsInvalidated(IEnumerable<IAssetName> assetNames)
+ private void OnAssetsInvalidated(IList<IAssetName> assetNames)
{
if (this.EventManager.AssetsInvalidated.HasListeners())
- this.EventManager.AssetsInvalidated.Raise(new AssetsInvalidatedEventArgs(assetNames));
+ this.EventManager.AssetsInvalidated.Raise(new AssetsInvalidatedEventArgs(assetNames, assetNames.Select(p => p.GetBaseAssetName())));
}
/// <summary>Get the load/edit operations to apply to an asset by querying registered <see cref="IContentEvents.AssetRequested"/> event handlers.</summary>
@@ -1133,7 +1133,7 @@ namespace StardewModdingAPI.Framework
this.EventManager.AssetRequested.Raise(
invoke: (mod, invoke) =>
{
- AssetRequestedEventArgs args = new(mod, asset.Name, this.GetOnBehalfOfContentPack);
+ AssetRequestedEventArgs args = new(mod, asset.Name, asset.NameWithoutLocale, this.GetOnBehalfOfContentPack);
invoke(args);
diff --git a/src/SMAPI/IAssetInfo.cs b/src/SMAPI/IAssetInfo.cs
index 6ac8358d..c7b2ab62 100644
--- a/src/SMAPI/IAssetInfo.cs
+++ b/src/SMAPI/IAssetInfo.cs
@@ -14,8 +14,12 @@ namespace StardewModdingAPI
/// <summary>The asset name being read.</summary>
public IAssetName Name { get; }
+ /// <summary>The <see cref="Name"/> with any locale codes stripped.</summary>
+ /// <remarks>For example, if <see cref="Name"/> contains a locale like <c>Data/Bundles.fr-FR</c>, this will be the name without locale like <c>Data/Bundles</c>. If the name has no locale, this field is equivalent.</remarks>
+ public IAssetName NameWithoutLocale { get; }
+
/// <summary>The normalized asset name being read. The format may change between platforms; see <see cref="AssetNameEquals"/> to compare with a known path.</summary>
- [Obsolete($"Use {nameof(Name)} instead.")]
+ [Obsolete($"Use {nameof(Name)} or {nameof(NameWithoutLocale)} instead.")]
string AssetName { get; }
/// <summary>The content data type.</summary>
@@ -27,7 +31,7 @@ namespace StardewModdingAPI
*********/
/// <summary>Get whether the asset name being loaded matches a given name after normalization.</summary>
/// <param name="path">The expected asset path, relative to the game's content folder and without the .xnb extension or locale suffix (like 'Data\ObjectInformation').</param>
- [Obsolete($"Use {nameof(Name)}.{nameof(IAssetName.IsEquivalentTo)} instead.")]
+ [Obsolete($"Use {nameof(Name)}.{nameof(IAssetName.IsEquivalentTo)} or {nameof(NameWithoutLocale)}.{nameof(IAssetName.IsEquivalentTo)} instead.")]
bool AssetNameEquals(string path);
}
}
diff --git a/src/SMAPI/IAssetName.cs b/src/SMAPI/IAssetName.cs
index a5bfea93..89f02adf 100644
--- a/src/SMAPI/IAssetName.cs
+++ b/src/SMAPI/IAssetName.cs
@@ -40,5 +40,8 @@ namespace StardewModdingAPI
/// <remarks>For example, <c>Characters/Dialogue/Abigail</c> is directly under <c>Characters/Dialogue</c> but not <c>Characters</c> or <c>Characters/Dialogue/Ab</c>. To allow sub-paths, use <see cref="StartsWith"/> instead.</remarks>
/// <param name="assetFolder">The asset path to check. This doesn't need a trailing slash.</param>
bool IsDirectlyUnderPath(string assetFolder);
+
+ /// <summary>Get an asset name representing the <see cref="BaseName"/> without locale.</summary>
+ internal IAssetName GetBaseAssetName();
}
}