From 5f2e83969a0994d798b869b1b53e9fc82d556093 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 May 2022 18:37:23 -0400 Subject: only build AssetWithoutLocale when it's used --- src/SMAPI/Events/AssetRequestedEventArgs.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/SMAPI/Events') 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 /// Get the mod metadata for a content pack, if it's a valid content pack for the mod. private readonly Func GetOnBehalfOf; + /// The asset info being requested. + private readonly IAssetInfo AssetInfo; + /********* ** Accessors *********/ /// The name of the asset being requested. - public IAssetName Name { get; } + public IAssetName Name => this.AssetInfo.Name; /// The with any locale codes stripped. /// For example, if contains a locale like Data/Bundles.fr-FR, this will be the name without locale like Data/Bundles. If the name has no locale, this field is equivalent. - public IAssetName NameWithoutLocale { get; } + public IAssetName NameWithoutLocale => this.AssetInfo.NameWithoutLocale; /// The requested data type. - public Type DataType { get; } + public Type DataType => this.AssetInfo.DataType; /// The load operations requested by the event handler. internal IList LoadOperations { get; } = new List(); @@ -45,16 +48,12 @@ namespace StardewModdingAPI.Events *********/ /// Construct an instance. /// The mod handling the event. - /// The name of the asset being requested. - /// The requested data type. - /// The with any locale codes stripped. + /// The asset info being requested. /// Get the mod metadata for a content pack, if it's a valid content pack for the mod. - internal AssetRequestedEventArgs(IModMetadata mod, IAssetName name, IAssetName nameWithoutLocale, Type dataType, Func getOnBehalfOf) + internal AssetRequestedEventArgs(IModMetadata mod, IAssetInfo assetInfo, Func getOnBehalfOf) { this.Mod = mod; - this.Name = name; - this.NameWithoutLocale = nameWithoutLocale; - this.DataType = dataType; + this.AssetInfo = assetInfo; this.GetOnBehalfOf = getOnBehalfOf; } -- cgit From f8f8b237996a1c883d43e539a379bf713a5fd7be Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 May 2022 18:50:07 -0400 Subject: use records for asset edit operations --- src/SMAPI/Events/AssetRequestedEventArgs.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/SMAPI/Events') diff --git a/src/SMAPI/Events/AssetRequestedEventArgs.cs b/src/SMAPI/Events/AssetRequestedEventArgs.cs index 6b00b1d9..d0aef1db 100644 --- a/src/SMAPI/Events/AssetRequestedEventArgs.cs +++ b/src/SMAPI/Events/AssetRequestedEventArgs.cs @@ -72,10 +72,10 @@ namespace StardewModdingAPI.Events { this.LoadOperations.Add( new AssetLoadOperation( - mod: this.Mod, - priority: priority, - onBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "load assets"), - getData: _ => load() + Mod: this.Mod, + OnBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "load assets"), + Priority: priority, + GetData: _ => load() ) ); } @@ -96,10 +96,10 @@ namespace StardewModdingAPI.Events { this.LoadOperations.Add( new AssetLoadOperation( - mod: this.Mod, - priority: priority, - onBehalfOf: null, - _ => this.Mod.Mod!.Helper.ModContent.Load(relativePath) + Mod: this.Mod, + OnBehalfOf: null, + Priority: priority, + GetData: _ => this.Mod.Mod!.Helper.ModContent.Load(relativePath) ) ); } @@ -119,10 +119,10 @@ namespace StardewModdingAPI.Events { this.EditOperations.Add( new AssetEditOperation( - mod: this.Mod, - priority: priority, - onBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "edit assets"), - apply + Mod: this.Mod, + Priority: priority, + OnBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "edit assets"), + ApplyEdit: apply ) ); } -- cgit