using StardewModdingAPI.Enums;
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 game has performed core initialization. This becomes true right before the first update tick.
public static bool IsGameLaunched { get; internal set; }
/// Whether the player has loaded a save and the world has finished initializing.
public static bool IsWorldReady { get; internal set; }
/// Whether is true and the player is free to act in the world (no menu is displayed, no cutscene is in progress, etc).
public static bool IsPlayerFree => Context.IsWorldReady && Game1.currentLocation != null && Game1.activeClickableMenu == null && !Game1.dialogueUp && (!Game1.eventUp || Game1.isFestival());
/// Whether is true and the player is free to move (e.g. not using a tool).
public static bool CanPlayerMove => Context.IsPlayerFree && Game1.player.CanMove;
/// Whether the game is currently running the draw loop. This isn't relevant to most mods, since you should use events to draw to the screen.
public static bool IsInDrawLoop { get; internal set; }
/// Whether and the player loaded the save in multiplayer mode (regardless of whether any other players are connected).
public static bool IsMultiplayer => Context.IsWorldReady && Game1.multiplayerMode != Game1.singlePlayer;
/// Whether and the current player is the main player. This is always true in single-player, and true when hosting in multiplayer.
public static bool IsMainPlayer => Context.IsWorldReady && Game1.IsMasterGame;
/****
** Internal
****/
/// Whether a player save has been loaded.
internal static bool IsSaveLoaded => Game1.hasLoadedGame && !(Game1.activeClickableMenu is TitleMenu);
/// 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
/// The current stage in the game's loading process.
internal static LoadStage LoadStage { get; set; }
}
}