From 173dd8cd030992983ddea36c944f22f7ad6ed9bd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 27 May 2017 23:48:16 -0400 Subject: add Context.IsPlayerFree --- release-notes.md | 1 + src/StardewModdingAPI/Context.cs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/release-notes.md b/release-notes.md index 622fcd49..ce4ec082 100644 --- a/release-notes.md +++ b/release-notes.md @@ -29,6 +29,7 @@ For modders: * You can now load unpacked `.tbin` files from your mod folder through the content API. * SMAPI now automatically fixes tilesheet references for maps loaded from the mod folder. _When loading a map from the mod folder, SMAPI will automatically use tilesheets relative to the map file if they exists. Otherwise it will default to tilesheets in the game content._ +* Added `Context.IsPlayerFree` for mods that need to check if the player can act (i.e. save is loaded, no menu is displayed, no cutscene is in progress, etc). * Added `Context.IsInDrawLoop` for specialised mods. * Fixed `smapi-crash.txt` being copied from the default log even if a different path is specified with `--log-path`. * Fixed the content API not matching XNB filenames with two dots (like `a.b.xnb`) if you don't specify the `.xnb` extension. diff --git a/src/StardewModdingAPI/Context.cs b/src/StardewModdingAPI/Context.cs index 3fe70c68..6c5ae40e 100644 --- a/src/StardewModdingAPI/Context.cs +++ b/src/StardewModdingAPI/Context.cs @@ -16,6 +16,9 @@ namespace StardewModdingAPI /// 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; } -- cgit