use records for asset edit operations
This commit is contained in:
parent
5f2e83969a
commit
f8f8b23799
|
@ -72,10 +72,10 @@ namespace StardewModdingAPI.Events
|
||||||
{
|
{
|
||||||
this.LoadOperations.Add(
|
this.LoadOperations.Add(
|
||||||
new AssetLoadOperation(
|
new AssetLoadOperation(
|
||||||
mod: this.Mod,
|
Mod: this.Mod,
|
||||||
priority: priority,
|
OnBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "load assets"),
|
||||||
onBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "load assets"),
|
Priority: priority,
|
||||||
getData: _ => load()
|
GetData: _ => load()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,10 @@ namespace StardewModdingAPI.Events
|
||||||
{
|
{
|
||||||
this.LoadOperations.Add(
|
this.LoadOperations.Add(
|
||||||
new AssetLoadOperation(
|
new AssetLoadOperation(
|
||||||
mod: this.Mod,
|
Mod: this.Mod,
|
||||||
priority: priority,
|
OnBehalfOf: null,
|
||||||
onBehalfOf: null,
|
Priority: priority,
|
||||||
_ => this.Mod.Mod!.Helper.ModContent.Load<TAsset>(relativePath)
|
GetData: _ => this.Mod.Mod!.Helper.ModContent.Load<TAsset>(relativePath)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -119,10 +119,10 @@ namespace StardewModdingAPI.Events
|
||||||
{
|
{
|
||||||
this.EditOperations.Add(
|
this.EditOperations.Add(
|
||||||
new AssetEditOperation(
|
new AssetEditOperation(
|
||||||
mod: this.Mod,
|
Mod: this.Mod,
|
||||||
priority: priority,
|
Priority: priority,
|
||||||
onBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "edit assets"),
|
OnBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "edit assets"),
|
||||||
apply
|
ApplyEdit: apply
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,38 +4,9 @@ using StardewModdingAPI.Events;
|
||||||
namespace StardewModdingAPI.Framework.Content
|
namespace StardewModdingAPI.Framework.Content
|
||||||
{
|
{
|
||||||
/// <summary>An edit to apply to an asset when it's requested from the content pipeline.</summary>
|
/// <summary>An edit to apply to an asset when it's requested from the content pipeline.</summary>
|
||||||
internal class AssetEditOperation
|
/// <param name="Mod">The mod applying the edit.</param>
|
||||||
{
|
/// <param name="Priority">If there are multiple edits that apply to the same asset, the priority with which this one should be applied.</param>
|
||||||
/*********
|
/// <param name="OnBehalfOf">The content pack on whose behalf the edit is being applied, if any.</param>
|
||||||
** Accessors
|
/// <param name="ApplyEdit">Apply the edit to an asset.</param>
|
||||||
*********/
|
internal record AssetEditOperation(IModMetadata Mod, AssetEditPriority Priority, IModMetadata? OnBehalfOf, Action<IAssetData> ApplyEdit);
|
||||||
/// <summary>The mod applying the edit.</summary>
|
|
||||||
public IModMetadata Mod { get; }
|
|
||||||
|
|
||||||
/// <summary>If there are multiple edits that apply to the same asset, the priority with which this one should be applied.</summary>
|
|
||||||
public AssetEditPriority Priority { get; }
|
|
||||||
|
|
||||||
/// <summary>The content pack on whose behalf the edit is being applied, if any.</summary>
|
|
||||||
public IModMetadata? OnBehalfOf { get; }
|
|
||||||
|
|
||||||
/// <summary>Apply the edit to an asset.</summary>
|
|
||||||
public Action<IAssetData> ApplyEdit { get; }
|
|
||||||
|
|
||||||
|
|
||||||
/*********
|
|
||||||
** Public methods
|
|
||||||
*********/
|
|
||||||
/// <summary>Construct an instance.</summary>
|
|
||||||
/// <param name="mod">The mod applying the edit.</param>
|
|
||||||
/// <param name="priority">If there are multiple edits that apply to the same asset, the priority with which this one should be applied.</param>
|
|
||||||
/// <param name="onBehalfOf">The content pack on whose behalf the edit is being applied, if any.</param>
|
|
||||||
/// <param name="applyEdit">Apply the edit to an asset.</param>
|
|
||||||
public AssetEditOperation(IModMetadata mod, AssetEditPriority priority, IModMetadata? onBehalfOf, Action<IAssetData> applyEdit)
|
|
||||||
{
|
|
||||||
this.Mod = mod;
|
|
||||||
this.Priority = priority;
|
|
||||||
this.OnBehalfOf = onBehalfOf;
|
|
||||||
this.ApplyEdit = applyEdit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,38 +4,9 @@ using StardewModdingAPI.Events;
|
||||||
namespace StardewModdingAPI.Framework.Content
|
namespace StardewModdingAPI.Framework.Content
|
||||||
{
|
{
|
||||||
/// <summary>An operation which provides the initial instance of an asset when it's requested from the content pipeline.</summary>
|
/// <summary>An operation which provides the initial instance of an asset when it's requested from the content pipeline.</summary>
|
||||||
internal class AssetLoadOperation
|
/// <param name="Mod">The mod applying the edit.</param>
|
||||||
{
|
/// <param name="Priority">If there are multiple loads that apply to the same asset, the priority with which this one should be applied.</param>
|
||||||
/*********
|
/// <param name="OnBehalfOf">The content pack on whose behalf the asset is being loaded, if any.</param>
|
||||||
** Accessors
|
/// <param name="GetData">Load the initial value for an asset.</param>
|
||||||
*********/
|
internal record AssetLoadOperation(IModMetadata Mod, IModMetadata? OnBehalfOf, AssetLoadPriority Priority, Func<IAssetInfo, object> GetData);
|
||||||
/// <summary>The mod loading the asset.</summary>
|
|
||||||
public IModMetadata Mod { get; }
|
|
||||||
|
|
||||||
/// <summary>The content pack on whose behalf the asset is being loaded, if any.</summary>
|
|
||||||
public IModMetadata? OnBehalfOf { get; }
|
|
||||||
|
|
||||||
/// <summary>If there are multiple loads that apply to the same asset, the priority with which this one should be applied.</summary>
|
|
||||||
public AssetLoadPriority Priority { get; }
|
|
||||||
|
|
||||||
/// <summary>Load the initial value for an asset.</summary>
|
|
||||||
public Func<IAssetInfo, object> GetData { get; }
|
|
||||||
|
|
||||||
|
|
||||||
/*********
|
|
||||||
** Public methods
|
|
||||||
*********/
|
|
||||||
/// <summary>Construct an instance.</summary>
|
|
||||||
/// <param name="mod">The mod applying the edit.</param>
|
|
||||||
/// <param name="priority">If there are multiple loads that apply to the same asset, the priority with which this one should be applied.</param>
|
|
||||||
/// <param name="onBehalfOf">The content pack on whose behalf the asset is being loaded, if any.</param>
|
|
||||||
/// <param name="getData">Load the initial value for an asset.</param>
|
|
||||||
public AssetLoadOperation(IModMetadata mod, AssetLoadPriority priority, IModMetadata? onBehalfOf, Func<IAssetInfo, object> getData)
|
|
||||||
{
|
|
||||||
this.Mod = mod;
|
|
||||||
this.Priority = priority;
|
|
||||||
this.OnBehalfOf = onBehalfOf;
|
|
||||||
this.GetData = getData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,8 @@
|
||||||
namespace StardewModdingAPI.Framework.Content
|
namespace StardewModdingAPI.Framework.Content
|
||||||
{
|
{
|
||||||
/// <summary>A set of operations to apply to an asset for a given <see cref="IAssetEditor"/> or <see cref="IAssetLoader"/> implementation.</summary>
|
/// <summary>A set of operations to apply to an asset for a given <see cref="IAssetEditor"/> or <see cref="IAssetLoader"/> implementation.</summary>
|
||||||
internal class AssetOperationGroup
|
/// <param name="Mod">The mod applying the changes.</param>
|
||||||
{
|
/// <param name="LoadOperations">The load operations to apply.</param>
|
||||||
/*********
|
/// <param name="EditOperations">The edit operations to apply.</param>
|
||||||
** Accessors
|
internal record AssetOperationGroup(IModMetadata Mod, AssetLoadOperation[] LoadOperations, AssetEditOperation[] EditOperations);
|
||||||
*********/
|
|
||||||
/// <summary>The mod applying the changes.</summary>
|
|
||||||
public IModMetadata Mod { get; }
|
|
||||||
|
|
||||||
/// <summary>The load operations to apply.</summary>
|
|
||||||
public AssetLoadOperation[] LoadOperations { get; }
|
|
||||||
|
|
||||||
/// <summary>The edit operations to apply.</summary>
|
|
||||||
public AssetEditOperation[] EditOperations { get; }
|
|
||||||
|
|
||||||
|
|
||||||
/*********
|
|
||||||
** Public methods
|
|
||||||
*********/
|
|
||||||
/// <summary>Construct an instance.</summary>
|
|
||||||
/// <param name="mod">The mod applying the changes.</param>
|
|
||||||
/// <param name="loadOperations">The load operations to apply.</param>
|
|
||||||
/// <param name="editOperations">The edit operations to apply.</param>
|
|
||||||
public AssetOperationGroup(IModMetadata mod, AssetLoadOperation[] loadOperations, AssetEditOperation[] editOperations)
|
|
||||||
{
|
|
||||||
this.Mod = mod;
|
|
||||||
this.LoadOperations = loadOperations;
|
|
||||||
this.EditOperations = editOperations;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -615,19 +615,19 @@ namespace StardewModdingAPI.Framework
|
||||||
editor: loader.Data,
|
editor: loader.Data,
|
||||||
dataType: info.DataType,
|
dataType: info.DataType,
|
||||||
createGroup: () => new AssetOperationGroup(
|
createGroup: () => new AssetOperationGroup(
|
||||||
mod: loader.Mod,
|
Mod: loader.Mod,
|
||||||
loadOperations: new[]
|
LoadOperations: new[]
|
||||||
{
|
{
|
||||||
new AssetLoadOperation(
|
new AssetLoadOperation(
|
||||||
mod: loader.Mod,
|
Mod: loader.Mod,
|
||||||
priority: AssetLoadPriority.Exclusive,
|
OnBehalfOf: null,
|
||||||
onBehalfOf: null,
|
Priority: AssetLoadPriority.Exclusive,
|
||||||
getData: assetInfo => loader.Data.Load<T>(
|
GetData: assetInfo => loader.Data.Load<T>(
|
||||||
this.GetLegacyAssetInfo(assetInfo)
|
this.GetLegacyAssetInfo(assetInfo)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
editOperations: Array.Empty<AssetEditOperation>()
|
EditOperations: Array.Empty<AssetEditOperation>()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -674,15 +674,15 @@ namespace StardewModdingAPI.Framework
|
||||||
editor: editor.Data,
|
editor: editor.Data,
|
||||||
dataType: info.DataType,
|
dataType: info.DataType,
|
||||||
createGroup: () => new AssetOperationGroup(
|
createGroup: () => new AssetOperationGroup(
|
||||||
mod: editor.Mod,
|
Mod: editor.Mod,
|
||||||
loadOperations: Array.Empty<AssetLoadOperation>(),
|
LoadOperations: Array.Empty<AssetLoadOperation>(),
|
||||||
editOperations: new[]
|
EditOperations: new[]
|
||||||
{
|
{
|
||||||
new AssetEditOperation(
|
new AssetEditOperation(
|
||||||
mod: editor.Mod,
|
Mod: editor.Mod,
|
||||||
priority: priority,
|
OnBehalfOf: null,
|
||||||
onBehalfOf: null,
|
Priority: priority,
|
||||||
applyEdit: assetData => editor.Data.Edit<T>(
|
ApplyEdit: assetData => editor.Data.Edit<T>(
|
||||||
this.GetLegacyAssetData(assetData)
|
this.GetLegacyAssetData(assetData)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue