summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Events
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-10 20:48:54 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-10 20:48:54 -0500
commit363f5aeef2dac07299d8d37229fd205a8dff7a61 (patch)
tree2730882f02a29638dde3870e931bc19269a3a3ec /src/StardewModdingAPI/Events
parente3522edddd0636116bd4772b4e4dbfce9c7c0f8d (diff)
downloadSMAPI-363f5aeef2dac07299d8d37229fd205a8dff7a61.tar.gz
SMAPI-363f5aeef2dac07299d8d37229fd205a8dff7a61.tar.bz2
SMAPI-363f5aeef2dac07299d8d37229fd205a8dff7a61.zip
rename content event for consistency, simplify usage (#173)
Diffstat (limited to 'src/StardewModdingAPI/Events')
-rw-r--r--src/StardewModdingAPI/Events/ContentEvents.cs34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/StardewModdingAPI/Events/ContentEvents.cs b/src/StardewModdingAPI/Events/ContentEvents.cs
index 558fc070..f19a33e2 100644
--- a/src/StardewModdingAPI/Events/ContentEvents.cs
+++ b/src/StardewModdingAPI/Events/ContentEvents.cs
@@ -28,7 +28,7 @@ namespace StardewModdingAPI.Events
public static event EventHandler<EventArgsValueChanged<string>> AfterLocaleChanged;
/// <summary>Raised when an XNB file is being read into the cache. Mods can change the data here before it's cached.</summary>
- public static event EventHandler<IContentEventHelper> AssetLoading;
+ public static event EventHandler<IContentEventHelper> AfterAssetLoaded;
/*********
@@ -52,13 +52,28 @@ namespace StardewModdingAPI.Events
monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterLocaleChanged)}", ContentEvents.AfterLocaleChanged?.GetInvocationList(), null, new EventArgsValueChanged<string>(oldLocale, newLocale));
}
- /// <summary>Raise an <see cref="AssetLoading"/> event.</summary>
+ /// <summary>Raise an <see cref="AfterAssetLoaded"/> event.</summary>
/// <param name="monitor">Encapsulates monitoring and logging.</param>
/// <param name="contentHelper">Encapsulates access and changes to content being read from a data file.</param>
- internal static void InvokeAssetLoading(IMonitor monitor, IContentEventHelper contentHelper)
+ internal static void InvokeAfterAssetLoaded(IMonitor monitor, IContentEventHelper contentHelper)
{
- // raise warning about experimental API
- foreach (Delegate handler in ContentEvents.AssetLoading.GetInvocationList())
+ if (ContentEvents.AfterAssetLoaded != null)
+ {
+ Delegate[] handlers = ContentEvents.AfterAssetLoaded.GetInvocationList();
+ ContentEvents.RaiseDeprecationWarning(handlers);
+ monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterAssetLoaded)}", handlers, null, contentHelper);
+ }
+ }
+
+
+ /*********
+ ** Private methods
+ *********/
+ /// <summary>Raise a 'experimental API' warning for each mod using the content API.</summary>
+ /// <param name="handlers">The event handlers.</param>
+ private static void RaiseDeprecationWarning(Delegate[] handlers)
+ {
+ foreach (Delegate handler in handlers)
{
string modName = ContentEvents.ModRegistry.GetModFrom(handler) ?? "An unknown mod";
if (!ContentEvents.WarnedMods.Contains(modName))
@@ -67,15 +82,6 @@ namespace StardewModdingAPI.Events
ContentEvents.Monitor.Log($"{modName} used the undocumented and experimental content API, which may change or be removed without warning.", LogLevel.Warn);
}
}
-
- // raise event
- monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AssetLoading)}", ContentEvents.AssetLoading?.GetInvocationList(), null, contentHelper);
- }
-
- /// <summary>Get whether there are any <see cref="AssetLoading"/> listeners.</summary>
- internal static bool HasAssetLoadingListeners()
- {
- return ContentEvents.AssetLoading != null;
}
}
}