summaryrefslogtreecommitdiff
path: root/src/SMAPI/Events
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-03-25 23:53:30 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-03-25 23:53:30 -0400
commit3707f481a567df5149aea00ffb14cddb7b14fccb (patch)
treea078b00dd396853ed23f4f542d1877d6a40c3482 /src/SMAPI/Events
parent021891ff0ceb6b327bc196c336aa56ddfaf99b0e (diff)
downloadSMAPI-3707f481a567df5149aea00ffb14cddb7b14fccb.tar.gz
SMAPI-3707f481a567df5149aea00ffb14cddb7b14fccb.tar.bz2
SMAPI-3707f481a567df5149aea00ffb14cddb7b14fccb.zip
extend load conflict resolution into load priority (#766)
Diffstat (limited to 'src/SMAPI/Events')
-rw-r--r--src/SMAPI/Events/AssetLoadPriority.cs19
-rw-r--r--src/SMAPI/Events/AssetRequestedEventArgs.cs14
2 files changed, 26 insertions, 7 deletions
diff --git a/src/SMAPI/Events/AssetLoadPriority.cs b/src/SMAPI/Events/AssetLoadPriority.cs
new file mode 100644
index 00000000..e07b5a40
--- /dev/null
+++ b/src/SMAPI/Events/AssetLoadPriority.cs
@@ -0,0 +1,19 @@
+namespace StardewModdingAPI.Events
+{
+ /// <summary>The priority for an asset load when multiple apply for the same asset.</summary>
+ /// <remarks>If multiple non-<see cref="Exclusive"/> loads have the same priority, the one registered first will be selected. You can also specify arbitrary intermediate values, like <c>AssetLoadPriority.Low + 5</c>.</remarks>
+ public enum AssetLoadPriority
+ {
+ /// <summary>This load is optional and can safely be skipped if there are higher-priority loads.</summary>
+ Low = -1000,
+
+ /// <summary>The load is optional and can safely be skipped if there are higher-priority loads, but it should still be preferred over any <see cref="Low"/>-priority loads.</summary>
+ Medium = 0,
+
+ /// <summary>The load is optional and can safely be skipped if there are higher-priority loads, but it should still be preferred over any <see cref="Low"/>- or <see cref="Medium"/>-priority loads.</summary>
+ High = 1000,
+
+ /// <summary>The load is not optional. If more than one loader has <see cref="Exclusive"/> priority, SMAPI will log an error and ignore all of them.</summary>
+ Exclusive = int.MaxValue
+ }
+}
diff --git a/src/SMAPI/Events/AssetRequestedEventArgs.cs b/src/SMAPI/Events/AssetRequestedEventArgs.cs
index 9942079b..d022a4de 100644
--- a/src/SMAPI/Events/AssetRequestedEventArgs.cs
+++ b/src/SMAPI/Events/AssetRequestedEventArgs.cs
@@ -49,21 +49,21 @@ namespace StardewModdingAPI.Events
/// <summary>Provide the initial instance for the asset, instead of trying to load it from the game's <c>Content</c> folder.</summary>
/// <param name="load">Get the initial instance of an asset.</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 ID on whose behalf you're applying the change. This is only valid for content packs for your mod.</param>
- /// <param name="allowSkipOnConflict">When there are multiple loads that apply to the same asset, this indicates whether this one can be skipped to resolve the conflict. If all loads allow skipping, the first one that was registered will be applied. If this is false, SMAPI will raise an error and apply none of them.</param>
/// <remarks>
/// Usage notes:
/// <list type="bullet">
/// <item>The asset doesn't need to exist in the game's <c>Content</c> folder. If any mod loads the asset, the game will see it as an existing asset as if it was in that folder.</item>
- /// <item>Each asset can logically only have one initial instance. If multiple loads apply at the same time, SMAPI will use the <paramref name="allowSkipOnConflict"/> parameter to decide what happens. If you're making changes to the existing asset instead of replacing it, you should use <see cref="Edit"/> instead to avoid those limitations and improve mod compatibility.</item>
+ /// <item>Each asset can logically only have one initial instance. If multiple loads apply at the same time, SMAPI will use the <paramref name="priority"/> parameter to decide what happens. If you're making changes to the existing asset instead of replacing it, you should use <see cref="Edit"/> instead to avoid those limitations and improve mod compatibility.</item>
/// </list>
/// </remarks>
- public void LoadFrom(Func<object> load, string onBehalfOf = null, bool allowSkipOnConflict = false)
+ public void LoadFrom(Func<object> load, AssetLoadPriority priority, string onBehalfOf = null)
{
this.LoadOperations.Add(
new AssetLoadOperation(
mod: this.Mod,
- allowSkipOnConflict: allowSkipOnConflict,
+ priority: priority,
onBehalfOf: this.GetOnBehalfOf(this.Mod, onBehalfOf, "load assets"),
getData: _ => load()
)
@@ -73,7 +73,7 @@ namespace StardewModdingAPI.Events
/// <summary>Provide the initial instance for the asset from a file in your mod folder, instead of trying to load it from the game's <c>Content</c> folder.</summary>
/// <typeparam name="TAsset">The expected data type. The main supported types are <see cref="Map"/>, <see cref="Texture2D"/>, dictionaries, and lists; other types may be supported by the game's content pipeline.</typeparam>
/// <param name="relativePath">The relative path to the file in your mod folder.</param>
- /// <param name="allowSkipOnConflict">When there are multiple loads that apply to the same asset, this indicates whether this one can be skipped to resolve the conflict. If all loads allow skipping, the first one that was registered will be applied. If this is false, SMAPI will raise an error and apply none of them.</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>
/// <remarks>
/// Usage notes:
/// <list type="bullet">
@@ -81,12 +81,12 @@ namespace StardewModdingAPI.Events
/// <item>Each asset can logically only have one initial instance. If multiple loads apply at the same time, SMAPI will raise an error and ignore all of them. If you're making changes to the existing asset instead of replacing it, you should use <see cref="Edit"/> instead to avoid those limitations and improve mod compatibility.</item>
/// </list>
/// </remarks>
- public void LoadFromModFile<TAsset>(string relativePath, bool allowSkipOnConflict = false)
+ public void LoadFromModFile<TAsset>(string relativePath, AssetLoadPriority priority)
{
this.LoadOperations.Add(
new AssetLoadOperation(
mod: this.Mod,
- allowSkipOnConflict: allowSkipOnConflict,
+ priority: priority,
onBehalfOf: null,
_ => this.Mod.Mod.Helper.Content.Load<TAsset>(relativePath))
);