summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Events/TimeEvents.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-06-02 18:25:34 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-06-02 18:25:34 -0400
commit559203922bcad4071f8be53b1a61b0026da14396 (patch)
tree2ed664798183d77779beb68b61bd7622140413df /src/StardewModdingAPI/Events/TimeEvents.cs
parent933e889c24e565d9028d3719ba2d65d512890564 (diff)
parent3a8e77a3098572fa413a27f41f832563daec3453 (diff)
downloadSMAPI-559203922bcad4071f8be53b1a61b0026da14396.tar.gz
SMAPI-559203922bcad4071f8be53b1a61b0026da14396.tar.bz2
SMAPI-559203922bcad4071f8be53b1a61b0026da14396.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Events/TimeEvents.cs')
-rw-r--r--src/StardewModdingAPI/Events/TimeEvents.cs75
1 files changed, 60 insertions, 15 deletions
diff --git a/src/StardewModdingAPI/Events/TimeEvents.cs b/src/StardewModdingAPI/Events/TimeEvents.cs
index 3f06a46b..5dadf567 100644
--- a/src/StardewModdingAPI/Events/TimeEvents.cs
+++ b/src/StardewModdingAPI/Events/TimeEvents.cs
@@ -1,6 +1,8 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Framework;
+#pragma warning disable 618 // Suppress obsolete-symbol errors in this file. Since several events are marked obsolete, this produces unnecessary warnings.
namespace StardewModdingAPI.Events
{
/// <summary>Events raised when the in-game date or time changes.</summary>
@@ -12,6 +14,21 @@ namespace StardewModdingAPI.Events
/// <summary>Manages deprecation warnings.</summary>
private static DeprecationManager DeprecationManager;
+ /// <summary>The backing field for <see cref="OnNewDay"/>.</summary>
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
+ private static event EventHandler<EventArgsNewDay> _OnNewDay;
+
+ /// <summary>The backing field for <see cref="DayOfMonthChanged"/>.</summary>
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
+ private static event EventHandler<EventArgsIntChanged> _DayOfMonthChanged;
+
+ /// <summary>The backing field for <see cref="SeasonOfYearChanged"/>.</summary>
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
+ private static event EventHandler<EventArgsStringChanged> _SeasonOfYearChanged;
+
+ /// <summary>The backing field for <see cref="YearOfGameChanged"/>.</summary>
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
+ private static event EventHandler<EventArgsIntChanged> _YearOfGameChanged;
/*********
** Events
@@ -23,17 +40,52 @@ namespace StardewModdingAPI.Events
public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged;
/// <summary>Raised after the day-of-month value changes, including when loading a save. This may happen before save; in most cases you should use <see cref="AfterDayStarted"/> instead.</summary>
- public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged;
+ [Obsolete("Use " + nameof(TimeEvents) + "." + nameof(TimeEvents.AfterDayStarted) + " or " + nameof(SaveEvents) + " instead")]
+ public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged
+ {
+ add
+ {
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.DayOfMonthChanged)}", "1.14", DeprecationLevel.Info);
+ TimeEvents._DayOfMonthChanged += value;
+ }
+ remove => TimeEvents._DayOfMonthChanged -= value;
+ }
/// <summary>Raised after the year value changes.</summary>
- public static event EventHandler<EventArgsIntChanged> YearOfGameChanged;
+ [Obsolete("Use " + nameof(TimeEvents) + "." + nameof(TimeEvents.AfterDayStarted) + " or " + nameof(SaveEvents) + " instead")]
+ public static event EventHandler<EventArgsIntChanged> YearOfGameChanged
+ {
+ add
+ {
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.YearOfGameChanged)}", "1.14", DeprecationLevel.Info);
+ TimeEvents._YearOfGameChanged += value;
+ }
+ remove => TimeEvents._YearOfGameChanged -= value;
+ }
/// <summary>Raised after the season value changes.</summary>
- public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged;
+ [Obsolete("Use " + nameof(TimeEvents) + "." + nameof(TimeEvents.AfterDayStarted) + " or " + nameof(SaveEvents) + " instead")]
+ public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged
+ {
+ add
+ {
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.SeasonOfYearChanged)}", "1.14", DeprecationLevel.Info);
+ TimeEvents._SeasonOfYearChanged += value;
+ }
+ remove => TimeEvents._SeasonOfYearChanged -= value;
+ }
/// <summary>Raised when the player is transitioning to a new day and the game is performing its day update logic. This event is triggered twice: once after the game starts transitioning, and again after it finishes.</summary>
[Obsolete("Use " + nameof(TimeEvents) + "." + nameof(TimeEvents.AfterDayStarted) + " or " + nameof(SaveEvents) + " instead")]
- public static event EventHandler<EventArgsNewDay> OnNewDay;
+ public static event EventHandler<EventArgsNewDay> OnNewDay
+ {
+ add
+ {
+ TimeEvents.DeprecationManager.Warn($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", "1.6", DeprecationLevel.Info);
+ TimeEvents._OnNewDay += value;
+ }
+ remove => TimeEvents._OnNewDay -= value;
+ }
/*********
@@ -68,7 +120,7 @@ namespace StardewModdingAPI.Events
/// <param name="newDay">The current day value.</param>
internal static void InvokeDayOfMonthChanged(IMonitor monitor, int priorDay, int newDay)
{
- monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.DayOfMonthChanged)}", TimeEvents.DayOfMonthChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorDay, newDay));
+ monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.DayOfMonthChanged)}", TimeEvents._DayOfMonthChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorDay, newDay));
}
/// <summary>Raise a <see cref="YearOfGameChanged"/> event.</summary>
@@ -77,7 +129,7 @@ namespace StardewModdingAPI.Events
/// <param name="newYear">The current year value.</param>
internal static void InvokeYearOfGameChanged(IMonitor monitor, int priorYear, int newYear)
{
- monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.YearOfGameChanged)}", TimeEvents.YearOfGameChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorYear, newYear));
+ monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.YearOfGameChanged)}", TimeEvents._YearOfGameChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorYear, newYear));
}
/// <summary>Raise a <see cref="SeasonOfYearChanged"/> event.</summary>
@@ -86,7 +138,7 @@ namespace StardewModdingAPI.Events
/// <param name="newSeason">The current season name.</param>
internal static void InvokeSeasonOfYearChanged(IMonitor monitor, string priorSeason, string newSeason)
{
- monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.SeasonOfYearChanged)}", TimeEvents.SeasonOfYearChanged?.GetInvocationList(), null, new EventArgsStringChanged(priorSeason, newSeason));
+ monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.SeasonOfYearChanged)}", TimeEvents._SeasonOfYearChanged?.GetInvocationList(), null, new EventArgsStringChanged(priorSeason, newSeason));
}
/// <summary>Raise a <see cref="OnNewDay"/> event.</summary>
@@ -96,14 +148,7 @@ namespace StardewModdingAPI.Events
/// <param name="isTransitioning">Whether the game just started the transition (<c>true</c>) or finished it (<c>false</c>).</param>
internal static void InvokeOnNewDay(IMonitor monitor, int priorDay, int newDay, bool isTransitioning)
{
- if (TimeEvents.OnNewDay == null)
- return;
-
- string name = $"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}";
- Delegate[] handlers = TimeEvents.OnNewDay.GetInvocationList();
-
- TimeEvents.DeprecationManager.WarnForEvent(handlers, name, "1.6", DeprecationLevel.Info);
- monitor.SafelyRaiseGenericEvent(name, handlers, null, new EventArgsNewDay(priorDay, newDay, isTransitioning));
+ monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", TimeEvents._OnNewDay?.GetInvocationList(), null, new EventArgsNewDay(priorDay, newDay, isTransitioning));
}
}
}