using System;
namespace StardewModdingAPI.Events
{
/// Events raised when the game changes state.
public static class GameEvents
{
/*********
** Events
*********/
/// Raised during launch after configuring XNA or MonoGame. The game window hasn't been opened by this point. Called during .
public static event EventHandler Initialize;
/// Raised during launch after configuring Stardew Valley, loading it into memory, and opening the game window. The window is still blank by this point.
public static event EventHandler GameLoaded;
/// Raised before XNA loads or reloads graphics resources. Called during .
public static event EventHandler LoadContent;
/// Raised during the first game update tick.
public static event EventHandler FirstUpdateTick;
/// Raised when the game updates its state (≈60 times per second).
public static event EventHandler UpdateTick;
/// Raised every other tick (≈30 times per second).
public static event EventHandler SecondUpdateTick;
/// Raised every fourth tick (≈15 times per second).
public static event EventHandler FourthUpdateTick;
/// Raised every eighth tick (≈8 times per second).
public static event EventHandler EighthUpdateTick;
/// Raised every 15th tick (≈4 times per second).
public static event EventHandler QuarterSecondTick;
/// Raised every 30th tick (≈twice per second).
public static event EventHandler HalfSecondTick;
/// Raised every 60th tick (≈once per second).
public static event EventHandler OneSecondTick;
/*********
** Internal methods
*********/
/// Raise a event.
internal static void InvokeGameLoaded()
{
GameEvents.GameLoaded?.Invoke(null, EventArgs.Empty);
}
/// Raise an event.
/// Encapsulates logging and monitoring.
internal static void InvokeInitialize(IMonitor monitor)
{
try
{
GameEvents.Initialize?.Invoke(null, EventArgs.Empty);
}
catch (Exception ex)
{
monitor.Log($"A mod crashed handling an event.\n{ex}", LogLevel.Error);
}
}
/// Raise a event.
/// Encapsulates logging and monitoring.
internal static void InvokeLoadContent(IMonitor monitor)
{
try
{
GameEvents.LoadContent?.Invoke(null, EventArgs.Empty);
}
catch (Exception ex)
{
monitor.Log($"A mod crashed handling an event.\n{ex}", LogLevel.Error);
}
}
/// Raise an event.
/// Encapsulates logging and monitoring.
internal static void InvokeUpdateTick(IMonitor monitor)
{
try
{
GameEvents.UpdateTick?.Invoke(null, EventArgs.Empty);
}
catch (Exception ex)
{
monitor.Log($"A mod crashed handling an event.\n{ex}", LogLevel.Error);
}
}
/// Raise a event.
internal static void InvokeSecondUpdateTick()
{
GameEvents.SecondUpdateTick?.Invoke(null, EventArgs.Empty);
}
/// Raise a event.
internal static void InvokeFourthUpdateTick()
{
GameEvents.FourthUpdateTick?.Invoke(null, EventArgs.Empty);
}
/// Raise a event.
internal static void InvokeEighthUpdateTick()
{
GameEvents.EighthUpdateTick?.Invoke(null, EventArgs.Empty);
}
/// Raise a event.
internal static void InvokeQuarterSecondTick()
{
GameEvents.QuarterSecondTick?.Invoke(null, EventArgs.Empty);
}
/// Raise a event.
internal static void InvokeHalfSecondTick()
{
GameEvents.HalfSecondTick?.Invoke(null, EventArgs.Empty);
}
/// Raise a event.
internal static void InvokeOneSecondTick()
{
GameEvents.OneSecondTick?.Invoke(null, EventArgs.Empty);
}
/// Raise a event.
internal static void InvokeFirstUpdateTick()
{
GameEvents.FirstUpdateTick?.Invoke(null, EventArgs.Empty);
}
}
}