From 363f5aeef2dac07299d8d37229fd205a8dff7a61 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 10 Mar 2017 20:48:54 -0500 Subject: rename content event for consistency, simplify usage (#173) --- src/StardewModdingAPI/Events/ContentEvents.cs | 34 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/StardewModdingAPI/Events') 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> AfterLocaleChanged; /// Raised when an XNB file is being read into the cache. Mods can change the data here before it's cached. - public static event EventHandler AssetLoading; + public static event EventHandler AfterAssetLoaded; /********* @@ -52,13 +52,28 @@ namespace StardewModdingAPI.Events monitor.SafelyRaiseGenericEvent($"{nameof(ContentEvents)}.{nameof(ContentEvents.AfterLocaleChanged)}", ContentEvents.AfterLocaleChanged?.GetInvocationList(), null, new EventArgsValueChanged(oldLocale, newLocale)); } - /// Raise an event. + /// Raise an event. /// Encapsulates monitoring and logging. /// Encapsulates access and changes to content being read from a data file. - 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 + *********/ + /// Raise a 'experimental API' warning for each mod using the content API. + /// The event handlers. + 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); - } - - /// Get whether there are any listeners. - internal static bool HasAssetLoadingListeners() - { - return ContentEvents.AssetLoading != null; } } } -- cgit