summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Events/TimeEvents.cs
blob: 1b367230a86b8dda4c709730ffdcb86e2ea32cee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using StardewModdingAPI.Framework;

namespace StardewModdingAPI.Events
{
    /// <summary>Events raised when the in-game date or time changes.</summary>
    public static class TimeEvents
    {
        /*********
        ** Events
        *********/
        /// <summary>Raised after the in-game clock changes.</summary>
        public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged;

        /// <summary>Raised after the day-of-month value changes, including when loading a save (unlike <see cref="OnNewDay"/>).</summary>
        public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged;

        /// <summary>Raised after the year value changes.</summary>
        public static event EventHandler<EventArgsIntChanged> YearOfGameChanged;

        /// <summary>Raised after the season value changes.</summary>
        public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged;

        /// <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>
        public static event EventHandler<EventArgsNewDay> OnNewDay;


        /*********
        ** Internal methods
        *********/
        /// <summary>Raise a <see cref="InvokeDayOfMonthChanged"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="priorTime">The previous time in military time format (e.g. 6:00pm is 1800).</param>
        /// <param name="newTime">The current time in military time format (e.g. 6:10pm is 1810).</param>
        internal static void InvokeTimeOfDayChanged(IMonitor monitor, int priorTime, int newTime)
        {
            monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.TimeOfDayChanged)}", TimeEvents.TimeOfDayChanged?.GetInvocationList(), null, new EventArgsIntChanged(priorTime, newTime));
        }

        /// <summary>Raise a <see cref="DayOfMonthChanged"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="priorDay">The previous day value.</param>
        /// <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));
        }

        /// <summary>Raise a <see cref="YearOfGameChanged"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="priorYear">The previous year value.</param>
        /// <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));
        }

        /// <summary>Raise a <see cref="SeasonOfYearChanged"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="priorSeason">The previous season name.</param>
        /// <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));
        }

        /// <summary>Raise a <see cref="OnNewDay"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="priorDay">The previous day value.</param>
        /// <param name="newDay">The current day value.</param>
        /// <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)
        {
            monitor.SafelyRaiseGenericEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.OnNewDay)}", TimeEvents.OnNewDay?.GetInvocationList(), null, new EventArgsNewDay(priorDay, newDay, isTransitioning));
        }
    }
}