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/Framework/Content/AssetEditOperation.cs | 39 +++------------------- src/SMAPI/Framework/Content/AssetLoadOperation.cs | 39 +++------------------- src/SMAPI/Framework/Content/AssetOperationGroup.cs | 33 +++--------------- src/SMAPI/Framework/ContentCoordinator.cs | 28 ++++++++-------- 4 files changed, 28 insertions(+), 111 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Content/AssetEditOperation.cs b/src/SMAPI/Framework/Content/AssetEditOperation.cs index 464948b0..11b8811b 100644 --- a/src/SMAPI/Framework/Content/AssetEditOperation.cs +++ b/src/SMAPI/Framework/Content/AssetEditOperation.cs @@ -4,38 +4,9 @@ using StardewModdingAPI.Events; namespace StardewModdingAPI.Framework.Content { /// An edit to apply to an asset when it's requested from the content pipeline. - internal class AssetEditOperation - { - /********* - ** Accessors - *********/ - /// The mod applying the edit. - public IModMetadata Mod { get; } - - /// If there are multiple edits that apply to the same asset, the priority with which this one should be applied. - public AssetEditPriority Priority { get; } - - /// The content pack on whose behalf the edit is being applied, if any. - public IModMetadata? OnBehalfOf { get; } - - /// Apply the edit to an asset. - public Action ApplyEdit { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The mod applying the edit. - /// If there are multiple edits that apply to the same asset, the priority with which this one should be applied. - /// The content pack on whose behalf the edit is being applied, if any. - /// Apply the edit to an asset. - public AssetEditOperation(IModMetadata mod, AssetEditPriority priority, IModMetadata? onBehalfOf, Action applyEdit) - { - this.Mod = mod; - this.Priority = priority; - this.OnBehalfOf = onBehalfOf; - this.ApplyEdit = applyEdit; - } - } + /// The mod applying the edit. + /// If there are multiple edits that apply to the same asset, the priority with which this one should be applied. + /// The content pack on whose behalf the edit is being applied, if any. + /// Apply the edit to an asset. + internal record AssetEditOperation(IModMetadata Mod, AssetEditPriority Priority, IModMetadata? OnBehalfOf, Action ApplyEdit); } diff --git a/src/SMAPI/Framework/Content/AssetLoadOperation.cs b/src/SMAPI/Framework/Content/AssetLoadOperation.cs index b6cdec27..7af07dfd 100644 --- a/src/SMAPI/Framework/Content/AssetLoadOperation.cs +++ b/src/SMAPI/Framework/Content/AssetLoadOperation.cs @@ -4,38 +4,9 @@ using StardewModdingAPI.Events; namespace StardewModdingAPI.Framework.Content { /// An operation which provides the initial instance of an asset when it's requested from the content pipeline. - internal class AssetLoadOperation - { - /********* - ** Accessors - *********/ - /// The mod loading the asset. - public IModMetadata Mod { get; } - - /// The content pack on whose behalf the asset is being loaded, if any. - public IModMetadata? OnBehalfOf { get; } - - /// If there are multiple loads that apply to the same asset, the priority with which this one should be applied. - public AssetLoadPriority Priority { get; } - - /// Load the initial value for an asset. - public Func GetData { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The mod applying the edit. - /// If there are multiple loads that apply to the same asset, the priority with which this one should be applied. - /// The content pack on whose behalf the asset is being loaded, if any. - /// Load the initial value for an asset. - public AssetLoadOperation(IModMetadata mod, AssetLoadPriority priority, IModMetadata? onBehalfOf, Func getData) - { - this.Mod = mod; - this.Priority = priority; - this.OnBehalfOf = onBehalfOf; - this.GetData = getData; - } - } + /// The mod applying the edit. + /// If there are multiple loads that apply to the same asset, the priority with which this one should be applied. + /// The content pack on whose behalf the asset is being loaded, if any. + /// Load the initial value for an asset. + internal record AssetLoadOperation(IModMetadata Mod, IModMetadata? OnBehalfOf, AssetLoadPriority Priority, Func GetData); } diff --git a/src/SMAPI/Framework/Content/AssetOperationGroup.cs b/src/SMAPI/Framework/Content/AssetOperationGroup.cs index a2fcb722..1566a8f0 100644 --- a/src/SMAPI/Framework/Content/AssetOperationGroup.cs +++ b/src/SMAPI/Framework/Content/AssetOperationGroup.cs @@ -1,33 +1,8 @@ namespace StardewModdingAPI.Framework.Content { /// A set of operations to apply to an asset for a given or implementation. - internal class AssetOperationGroup - { - /********* - ** Accessors - *********/ - /// The mod applying the changes. - public IModMetadata Mod { get; } - - /// The load operations to apply. - public AssetLoadOperation[] LoadOperations { get; } - - /// The edit operations to apply. - public AssetEditOperation[] EditOperations { get; } - - - /********* - ** Public methods - *********/ - /// Construct an instance. - /// The mod applying the changes. - /// The load operations to apply. - /// The edit operations to apply. - public AssetOperationGroup(IModMetadata mod, AssetLoadOperation[] loadOperations, AssetEditOperation[] editOperations) - { - this.Mod = mod; - this.LoadOperations = loadOperations; - this.EditOperations = editOperations; - } - } + /// The mod applying the changes. + /// The load operations to apply. + /// The edit operations to apply. + internal record AssetOperationGroup(IModMetadata Mod, AssetLoadOperation[] LoadOperations, AssetEditOperation[] EditOperations); } diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index f7cab23d..6702f5e6 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -615,19 +615,19 @@ namespace StardewModdingAPI.Framework editor: loader.Data, dataType: info.DataType, createGroup: () => new AssetOperationGroup( - mod: loader.Mod, - loadOperations: new[] + Mod: loader.Mod, + LoadOperations: new[] { new AssetLoadOperation( - mod: loader.Mod, - priority: AssetLoadPriority.Exclusive, - onBehalfOf: null, - getData: assetInfo => loader.Data.Load( + Mod: loader.Mod, + OnBehalfOf: null, + Priority: AssetLoadPriority.Exclusive, + GetData: assetInfo => loader.Data.Load( this.GetLegacyAssetInfo(assetInfo) ) ) }, - editOperations: Array.Empty() + EditOperations: Array.Empty() ) ); } @@ -674,15 +674,15 @@ namespace StardewModdingAPI.Framework editor: editor.Data, dataType: info.DataType, createGroup: () => new AssetOperationGroup( - mod: editor.Mod, - loadOperations: Array.Empty(), - editOperations: new[] + Mod: editor.Mod, + LoadOperations: Array.Empty(), + EditOperations: new[] { new AssetEditOperation( - mod: editor.Mod, - priority: priority, - onBehalfOf: null, - applyEdit: assetData => editor.Data.Edit( + Mod: editor.Mod, + OnBehalfOf: null, + Priority: priority, + ApplyEdit: assetData => editor.Data.Edit( this.GetLegacyAssetData(assetData) ) ) -- cgit