From 5997857064f4d6bb0747e84e1dbd1556c97b7481 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 12 Apr 2018 00:18:32 -0400 Subject: fix various net field conversions in SMAPI code (#453) --- src/SMAPI/Context.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Context.cs') diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs index 7ed9b052..79067b2d 100644 --- a/src/SMAPI/Context.cs +++ b/src/SMAPI/Context.cs @@ -35,7 +35,7 @@ namespace StardewModdingAPI ** Internal ****/ /// Whether a player save has been loaded. - internal static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.name); + 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 From 79ad322a8e31e977e455817469427f9c3cf218fd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 30 Jun 2018 13:40:48 -0400 Subject: tweak world-ready events to handle edge cases In particular: - world was never considered ready if the player's name was blank; - AfterReturnToTitle didn't trigger after being disconnected in multiplayer (#545). --- docs/release-notes.md | 1 + src/SMAPI/Context.cs | 2 +- src/SMAPI/Framework/SGame.cs | 31 ++++++++++++++----------------- 3 files changed, 16 insertions(+), 18 deletions(-) (limited to 'src/SMAPI/Context.cs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 14cf78a2..2b449ac7 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -26,6 +26,7 @@ * Fixed `world_settime` sometimes breaking NPC schedules (e.g. so they stay in bed). * Fixed launch issue for Linux players with some terminals. (Thanks to HanFox and kurumushi!) * Fixed issue where a mod crashing in `CanEdit` or `CanLoad` could cause an abort-retry loop. + * Fixed many mods not working if the player name is blank. * Renamed `install.exe` to `install on Windows.exe` to avoid confusion. * Updated compatibility list. diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs index 79067b2d..74def086 100644 --- a/src/SMAPI/Context.cs +++ b/src/SMAPI/Context.cs @@ -35,7 +35,7 @@ namespace StardewModdingAPI ** Internal ****/ /// Whether a player save has been loaded. - internal static bool IsSaveLoaded => Game1.hasLoadedGame && !string.IsNullOrEmpty(Game1.player.Name); + 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 diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 57afec06..def0943c 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -61,7 +61,7 @@ namespace StardewModdingAPI.Framework /// The number of ticks until SMAPI should notify mods that the game has loaded. /// Skipping a few frames ensures the game finishes initialising the world before mods try to change it. - private int AfterLoadTimer = 5; + private readonly Countdown AfterLoadTimer = new Countdown(5); /// Whether the after-load events were raised for this session. private bool RaisedAfterLoadEvent; @@ -313,13 +313,14 @@ namespace StardewModdingAPI.Framework /********* ** Update context *********/ - if (Context.IsWorldReady && !Context.IsSaveLoaded) + bool wasWorldReady = Context.IsWorldReady; + if ((Context.IsWorldReady && !Context.IsSaveLoaded) || Game1.exitToTitle) this.MarkWorldNotReady(); - else if (Context.IsSaveLoaded && !SaveGame.IsProcessing /*still loading save*/ && this.AfterLoadTimer >= 0 && Game1.currentLocation != null) + else if (Context.IsSaveLoaded && !SaveGame.IsProcessing /*still loading save*/ && this.AfterLoadTimer.Current > 0 && Game1.currentLocation != null) { if (Game1.dayOfMonth != 0) // wait until new-game intro finishes (world not fully initialised yet) - this.AfterLoadTimer--; - Context.IsWorldReady = this.AfterLoadTimer <= 0; + this.AfterLoadTimer.Decrement(); + Context.IsWorldReady = this.AfterLoadTimer.Current == 0; } /********* @@ -342,9 +343,14 @@ namespace StardewModdingAPI.Framework } /********* - ** After load events + ** Load / return-to-title events *********/ - if (!this.RaisedAfterLoadEvent && Context.IsWorldReady) + if (wasWorldReady && !Context.IsWorldReady) + { + this.Monitor.Log("Context: returned to title", LogLevel.Trace); + this.Events.Save_AfterReturnToTitle.Raise(); + } + else if (!this.RaisedAfterLoadEvent && Context.IsWorldReady) { // print context string context = $"Context: loaded saved game '{Constants.SaveFolderName}', starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}."; @@ -363,15 +369,6 @@ namespace StardewModdingAPI.Framework this.Events.Time_AfterDayStarted.Raise(); } - /********* - ** Exit to title events - *********/ - if (Game1.exitToTitle) - { - this.Monitor.Log("Context: returned to title", LogLevel.Trace); - this.Events.Save_AfterReturnToTitle.Raise(); - } - /********* ** Window events *********/ @@ -1342,7 +1339,7 @@ namespace StardewModdingAPI.Framework private void MarkWorldNotReady() { Context.IsWorldReady = false; - this.AfterLoadTimer = 5; + this.AfterLoadTimer.Reset(); this.RaisedAfterLoadEvent = false; } -- cgit From 8b9d1baaea415dfb3d845e990898c29c024c5c18 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 30 Jun 2018 16:55:59 -0400 Subject: fix Context.IsPlayerFree being false during festivals (#550) --- docs/release-notes.md | 3 ++- src/SMAPI/Context.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/SMAPI/Context.cs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 2b449ac7..ae7f766d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -48,11 +48,12 @@ * Added absolute pixels to `ICursorPosition`. * Added support for reading/writing `ISemanticVersion` to JSON. * Update checks now use the update key order when deciding which to link to. - * Fixed error if a mod loads a PNG while the game is loading (e.g. custom map tilesheets via `IAssetLoader`). * Fixed assets loaded by temporary content managers not being editable by mods. * Fixed assets not reloaded consistently when the player switches language. + * Fixed error if a mod loads a PNG while the game is loading (e.g. custom map tilesheets via `IAssetLoader`). * Fixed input suppression not working consistently for clicks. * Fixed console command input not saved to the log. + * Fixed `Context.IsPlayerFree` being false during festivals. * Fixed `helper.ModRegistry.GetApi` interface validation errors not mentioning which interface caused the issue. * Fixed some common non-mod build output being included in release zip. * Fixed mods able to intercept other mods' assets via the internal asset keys. diff --git a/src/SMAPI/Context.cs b/src/SMAPI/Context.cs index 74def086..3905699e 100644 --- a/src/SMAPI/Context.cs +++ b/src/SMAPI/Context.cs @@ -17,7 +17,7 @@ namespace StardewModdingAPI 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; + public static bool IsPlayerFree => Context.IsWorldReady && 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; -- cgit