summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Events/GameEvents.cs
blob: e4a0e08d7b5d8107b6c68e0a5c18dee827774f99 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;

namespace StardewModdingAPI.Events
{
    /// <summary>Events raised when the game changes state.</summary>
    public static class GameEvents
    {
        /*********
        ** Events
        *********/
        /// <summary>Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called during <see cref="Microsoft.Xna.Framework.Game.Initialize"/>.</summary>
        public static event EventHandler Initialize = delegate { };

        /// <summary>Raised during launch after configuring Stardew Valley, loading it into memory, and opening the game window. The window is still blank by this point.</summary>
        public static event EventHandler GameLoaded = delegate { };

        /// <summary>Raised before XNA loads or reloads graphics resources. Called during <see cref="Microsoft.Xna.Framework.Game.LoadContent"/>.</summary>
        public static event EventHandler LoadContent = delegate { };

        /// <summary>Raised during the first game update tick.</summary>
        public static event EventHandler FirstUpdateTick = delegate { };

        /// <summary>Raised when the game updates its state (≈60 times per second).</summary>
        public static event EventHandler UpdateTick = delegate { };

        /// <summary>Raised every other tick (≈30 times per second).</summary>
        public static event EventHandler SecondUpdateTick = delegate { };

        /// <summary>Raised every fourth tick (≈15 times per second).</summary>
        public static event EventHandler FourthUpdateTick = delegate { };

        /// <summary>Raised every eighth tick (≈8 times per second).</summary>
        public static event EventHandler EighthUpdateTick = delegate { };

        /// <summary>Raised every 15th tick (≈4 times per second).</summary>
        public static event EventHandler QuarterSecondTick = delegate { };

        /// <summary>Raised every 30th tick (≈twice per second).</summary>
        public static event EventHandler HalfSecondTick = delegate { };

        /// <summary>Raised every 60th tick (≈once per second).</summary>
        public static event EventHandler OneSecondTick = delegate { };


        /*********
        ** Internal methods
        *********/
        /// <summary>Raise a <see cref="GameLoaded"/> event.</summary>
        internal static void InvokeGameLoaded()
        {
            GameEvents.GameLoaded.Invoke(null, EventArgs.Empty);
        }

        /// <summary>Raise an <see cref="Initialize"/> event.</summary>
        internal static void InvokeInitialize()
        {
            try
            {
                GameEvents.Initialize.Invoke(null, EventArgs.Empty);
            }
            catch (Exception ex)
            {
                Log.AsyncR("An exception occured in XNA Initialize: " + ex);
            }
        }

        /// <summary>Raise a <see cref="LoadContent"/> event.</summary>
        internal static void InvokeLoadContent()
        {
            try
            {
                GameEvents.LoadContent.Invoke(null, EventArgs.Empty);
            }
            catch (Exception ex)
            {
                Log.AsyncR("An exception occured in XNA LoadContent: " + ex);
            }
        }

        /// <summary>Raise an <see cref="UpdateTick"/> event.</summary>
        internal static void InvokeUpdateTick()
        {
            try
            {
                GameEvents.UpdateTick.Invoke(null, EventArgs.Empty);
            }
            catch (Exception ex)
            {
                Log.AsyncR("An exception occured in XNA UpdateTick: " + ex);
            }
        }

        /// <summary>Raise a <see cref="SecondUpdateTick"/> event.</summary>
        internal static void InvokeSecondUpdateTick()
        {
            GameEvents.SecondUpdateTick.Invoke(null, EventArgs.Empty);
        }

        /// <summary>Raise a <see cref="FourthUpdateTick"/> event.</summary>
        internal static void InvokeFourthUpdateTick()
        {
            GameEvents.FourthUpdateTick.Invoke(null, EventArgs.Empty);
        }

        /// <summary>Raise a <see cref="EighthUpdateTick"/> event.</summary>
        internal static void InvokeEighthUpdateTick()
        {
            GameEvents.EighthUpdateTick.Invoke(null, EventArgs.Empty);
        }

        /// <summary>Raise a <see cref="QuarterSecondTick"/> event.</summary>
        internal static void InvokeQuarterSecondTick()
        {
            GameEvents.QuarterSecondTick.Invoke(null, EventArgs.Empty);
        }

        /// <summary>Raise a <see cref="HalfSecondTick"/> event.</summary>
        internal static void InvokeHalfSecondTick()
        {
            GameEvents.HalfSecondTick.Invoke(null, EventArgs.Empty);
        }

        /// <summary>Raise a <see cref="OneSecondTick"/> event.</summary>
        internal static void InvokeOneSecondTick()
        {
            GameEvents.OneSecondTick.Invoke(null, EventArgs.Empty);
        }

        /// <summary>Raise a <see cref="FirstUpdateTick"/> event.</summary>
        internal static void InvokeFirstUpdateTick()
        {
            GameEvents.FirstUpdateTick.Invoke(null, EventArgs.Empty);
        }
    }
}