diff options
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/SCore.cs | 13 | ||||
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 13 |
2 files changed, 16 insertions, 10 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 24a15fc6..5f30c9ef 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -52,6 +52,9 @@ namespace StardewModdingAPI.Framework /// <summary>The core logger and monitor for SMAPI.</summary> private readonly Monitor Monitor; + /// <summary>The core logger and monitor on behalf of the game.</summary> + private readonly Monitor MonitorForGame; + /// <summary>Tracks whether the game should exit immediately and any pending initialisation should be cancelled.</summary> private readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource(); @@ -128,6 +131,7 @@ namespace StardewModdingAPI.Framework ShowTraceInConsole = this.Settings.DeveloperMode, ShowFullStampInConsole = this.Settings.DeveloperMode }; + this.MonitorForGame = this.GetSecondaryMonitor("game"); this.EventManager = new EventManager(this.Monitor, this.ModRegistry); // init logging @@ -200,7 +204,7 @@ namespace StardewModdingAPI.Framework // override game SGame.ConstructorHack = new SGameConstructorHack(this.Monitor, this.Reflection, this.Toolkit.JsonHelper); - this.GameInstance = new SGame(this.Monitor, this.Reflection, this.EventManager, this.InitialiseAfterGameStart, this.Dispose); + this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.InitialiseAfterGameStart, this.Dispose); StardewValley.Program.gamePtr = this.GameInstance; // add exit handler @@ -338,11 +342,8 @@ namespace StardewModdingAPI.Framework this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); // redirect direct console output - { - Monitor monitor = this.GetSecondaryMonitor("game"); - if (monitor.WriteToConsole) - this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(monitor, message); - } + if (this.MonitorForGame.WriteToConsole) + this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message); // add headers if (this.Settings.DeveloperMode) diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 166f958c..1bd583bf 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -39,9 +39,12 @@ namespace StardewModdingAPI.Framework /**** ** SMAPI state ****/ - /// <summary>Encapsulates monitoring and logging.</summary> + /// <summary>Encapsulates monitoring and logging for SMAPI.</summary> private readonly IMonitor Monitor; + /// <summary>Encapsulates monitoring and logging on the game's behalf.</summary> + private readonly IMonitor MonitorForGame; + /// <summary>Manages SMAPI events for mods.</summary> private readonly EventManager Events; @@ -122,12 +125,13 @@ namespace StardewModdingAPI.Framework ** Protected methods *********/ /// <summary>Construct an instance.</summary> - /// <param name="monitor">Encapsulates monitoring and logging.</param> + /// <param name="monitor">Encapsulates monitoring and logging for SMAPI.</param> + /// <param name="monitorForGame">Encapsulates monitoring and logging on the game's behalf.</param> /// <param name="reflection">Simplifies access to private game code.</param> /// <param name="eventManager">Manages SMAPI events for mods.</param> /// <param name="onGameInitialised">A callback to invoke after the game finishes initialising.</param> /// <param name="onGameExiting">A callback to invoke when the game exits.</param> - internal SGame(IMonitor monitor, Reflector reflection, EventManager eventManager, Action onGameInitialised, Action onGameExiting) + internal SGame(IMonitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, Action onGameInitialised, Action onGameExiting) { SGame.ConstructorHack = null; @@ -140,6 +144,7 @@ namespace StardewModdingAPI.Framework // init SMAPI this.Monitor = monitor; + this.MonitorForGame = monitorForGame; this.Events = eventManager; this.Reflection = reflection; this.OnGameInitialised = onGameInitialised; @@ -697,7 +702,7 @@ namespace StardewModdingAPI.Framework } catch (Exception ex) { - this.Monitor.Log($"An error occured in the base update loop: {ex.GetLogSummary()}", LogLevel.Error); + this.MonitorForGame.Log($"An error occured in the base update loop: {ex.GetLogSummary()}", LogLevel.Error); } this.Events.GameLoop_Updated.Raise(new GameLoopUpdatedEventArgs(this.TicksElapsed)); |