diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-08 18:37:23 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-05-08 18:37:23 -0400 |
commit | 5f2e83969a0994d798b869b1b53e9fc82d556093 (patch) | |
tree | d6e9ed8e6091223f3f5e2a7686e404c65573af75 /src | |
parent | e2a3fc4f9974e4ea0c575c82be9b431904d6706d (diff) | |
download | SMAPI-5f2e83969a0994d798b869b1b53e9fc82d556093.tar.gz SMAPI-5f2e83969a0994d798b869b1b53e9fc82d556093.tar.bz2 SMAPI-5f2e83969a0994d798b869b1b53e9fc82d556093.zip |
only build AssetWithoutLocale when it's used
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI/Events/AssetRequestedEventArgs.cs | 19 | ||||
-rw-r--r-- | src/SMAPI/Framework/Content/AssetInfo.cs | 6 | ||||
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 2 |
3 files changed, 14 insertions, 13 deletions
diff --git a/src/SMAPI/Events/AssetRequestedEventArgs.cs b/src/SMAPI/Events/AssetRequestedEventArgs.cs index 3bcf83b9..6b00b1d9 100644 --- a/src/SMAPI/Events/AssetRequestedEventArgs.cs +++ b/src/SMAPI/Events/AssetRequestedEventArgs.cs @@ -19,19 +19,22 @@ namespace StardewModdingAPI.Events /// <summary>Get the mod metadata for a content pack, if it's a valid content pack for the mod.</summary> private readonly Func<IModMetadata, string?, string, IModMetadata?> GetOnBehalfOf; + /// <summary>The asset info being requested.</summary> + private readonly IAssetInfo AssetInfo; + /********* ** Accessors *********/ /// <summary>The name of the asset being requested.</summary> - public IAssetName Name { get; } + public IAssetName Name => this.AssetInfo.Name; /// <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 IAssetName NameWithoutLocale => this.AssetInfo.NameWithoutLocale; /// <summary>The requested data type.</summary> - public Type DataType { get; } + public Type DataType => this.AssetInfo.DataType; /// <summary>The load operations requested by the event handler.</summary> internal IList<AssetLoadOperation> LoadOperations { get; } = new List<AssetLoadOperation>(); @@ -45,16 +48,12 @@ 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="dataType">The requested data type.</param> - /// <param name="nameWithoutLocale">The <paramref name="name"/> with any locale codes stripped.</param> + /// <param name="assetInfo">The asset info being requested.</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, IAssetName nameWithoutLocale, Type dataType, Func<IModMetadata, string?, string, IModMetadata?> getOnBehalfOf) + internal AssetRequestedEventArgs(IModMetadata mod, IAssetInfo assetInfo, Func<IModMetadata, string?, string, IModMetadata?> getOnBehalfOf) { this.Mod = mod; - this.Name = name; - this.NameWithoutLocale = nameWithoutLocale; - this.DataType = dataType; + this.AssetInfo = assetInfo; this.GetOnBehalfOf = getOnBehalfOf; } diff --git a/src/SMAPI/Framework/Content/AssetInfo.cs b/src/SMAPI/Framework/Content/AssetInfo.cs index 363fffb3..a4f0a408 100644 --- a/src/SMAPI/Framework/Content/AssetInfo.cs +++ b/src/SMAPI/Framework/Content/AssetInfo.cs @@ -13,6 +13,9 @@ namespace StardewModdingAPI.Framework.Content /// <summary>Normalizes an asset key to match the cache key.</summary> protected readonly Func<string, string> GetNormalizedPath; + /// <summary>The backing field for <see cref="NameWithoutLocale"/>.</summary> + private IAssetName? NameWithoutLocaleImpl; + /********* ** Accessors @@ -24,7 +27,7 @@ namespace StardewModdingAPI.Framework.Content public IAssetName Name { get; } /// <inheritdoc /> - public IAssetName NameWithoutLocale { get; } + public IAssetName NameWithoutLocale => this.NameWithoutLocaleImpl ??= this.Name.GetBaseAssetName(); /// <inheritdoc /> [Obsolete($"Use {nameof(AssetInfo.Name)} or {nameof(AssetInfo.NameWithoutLocale)} instead. This property will be removed in SMAPI 4.0.0.")] @@ -64,7 +67,6 @@ namespace StardewModdingAPI.Framework.Content { this.Locale = locale; this.Name = assetName; - this.NameWithoutLocale = assetName.GetBaseAssetName(); this.DataType = type; this.GetNormalizedPath = getNormalizedPath; } diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 3c6e1b6c..f882682e 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1160,7 +1160,7 @@ namespace StardewModdingAPI.Framework this.EventManager.AssetRequested.Raise( invoke: (mod, invoke) => { - AssetRequestedEventArgs args = new(mod, asset.Name, asset.NameWithoutLocale, asset.DataType, this.GetOnBehalfOfContentPack); + AssetRequestedEventArgs args = new(mod, asset, this.GetOnBehalfOfContentPack); invoke(args); |