using System; using StardewModdingAPI.Framework; namespace StardewModdingAPI.Events { /// Events raised before and after the player saves/loads the game. public static class SaveEvents { /********* ** Events *********/ /// Raised before the game creates the save file. public static event EventHandler BeforeCreate; /// Raised after the game finishes creating the save file. public static event EventHandler AfterCreate; /// Raised before the game begins writes data to the save file. public static event EventHandler BeforeSave; /// Raised after the game finishes writing data to the save file. public static event EventHandler AfterSave; /// Raised after the player loads a save slot. public static event EventHandler AfterLoad; /// Raised after the game returns to the title screen. public static event EventHandler AfterReturnToTitle; /********* ** Internal methods *********/ /// Raise a event. /// Encapsulates monitoring and logging. internal static void InvokeBeforeCreate(IMonitor monitor) { monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.BeforeCreate)}", SaveEvents.BeforeCreate?.GetInvocationList(), null, EventArgs.Empty); } /// Raise a event. /// Encapsulates monitoring and logging. internal static void InvokeAfterCreated(IMonitor monitor) { monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterCreate)}", SaveEvents.AfterCreate?.GetInvocationList(), null, EventArgs.Empty); } /// Raise a event. /// Encapsulates monitoring and logging. internal static void InvokeBeforeSave(IMonitor monitor) { monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.BeforeSave)}", SaveEvents.BeforeSave?.GetInvocationList(), null, EventArgs.Empty); } /// Raise a event. /// Encapsulates monitoring and logging. internal static void InvokeAfterSave(IMonitor monitor) { monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterSave)}", SaveEvents.AfterSave?.GetInvocationList(), null, EventArgs.Empty); } /// Raise a event. /// Encapsulates monitoring and logging. internal static void InvokeAfterLoad(IMonitor monitor) { monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterLoad)}", SaveEvents.AfterLoad?.GetInvocationList(), null, EventArgs.Empty); } /// Raise a event. /// Encapsulates monitoring and logging. internal static void InvokeAfterReturnToTitle(IMonitor monitor) { monitor.SafelyRaisePlainEvent($"{nameof(SaveEvents)}.{nameof(SaveEvents.AfterReturnToTitle)}", SaveEvents.AfterReturnToTitle?.GetInvocationList(), null, EventArgs.Empty); } } }