using StardewModdingAPI.Events; using StardewValley; using StardewValley.Menus; namespace StardewModdingAPI { /// Provides information about the current game state. public static class Context { /********* ** Accessors *********/ /**** ** Public ****/ /// Whether the player has loaded a save and the world has finished initialising. public static bool IsWorldReady { get; internal set; } /// Whether the player is free to move around (e.g. save is loaded, no menu is displayed, no cutscene is in progress, etc). public static bool IsPlayerFree => Context.IsWorldReady && Game1.activeClickableMenu == null && Game1.player.CanMove && !Game1.dialogueUp && !Game1.eventUp; /// Whether the game is currently running the draw loop. This isn't relevant to most mods, since you should use to draw to the screen. public static bool IsInDrawLoop { get; internal set; } /**** ** Internal ****/ /// Whether a player save has been loaded. internal static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.name); /// Whether the game is currently writing to the save file. internal static bool IsSaving => Game1.activeClickableMenu is SaveGameMenu || Game1.activeClickableMenu is ShippingMenu; // saving is performed by SaveGameMenu, but it's wrapped by ShippingMenu on days when the player shipping something } }