From 929dccb75a1405737975d76648e015a3e7c00177 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 Oct 2017 23:07:10 -0400 Subject: reorganise repo structure --- src/SMAPI/Context.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/SMAPI/Context.cs (limited to 'src/SMAPI/Context.cs') diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs new file mode 100644 index 00000000..119e14c8 --- /dev/null +++ b/src/SMAPI/Context.cs @@ -0,0 +1,37 @@ +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 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.activeClickableMenu == null && !Game1.dialogueUp && !Game1.eventUp; + + /// 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 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 + } +} -- cgit