summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-05-08 02:18:58 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-05-08 02:18:58 -0400
commit85f609dc6c2f02d89b9fccaacfe837f8822d6b7c (patch)
treee4c62d91cf63f9828e6295f6ee2afb7eff53c727 /src/StardewModdingAPI
parent72a0b4fc6d268c67c3fba171793d5864f9710276 (diff)
downloadSMAPI-85f609dc6c2f02d89b9fccaacfe837f8822d6b7c.tar.gz
SMAPI-85f609dc6c2f02d89b9fccaacfe837f8822d6b7c.tar.bz2
SMAPI-85f609dc6c2f02d89b9fccaacfe837f8822d6b7c.zip
add optional verbose context logging
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Framework/Models/SConfig.cs3
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs32
-rw-r--r--src/StardewModdingAPI/Program.cs3
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.config.json5
4 files changed, 38 insertions, 5 deletions
diff --git a/src/StardewModdingAPI/Framework/Models/SConfig.cs b/src/StardewModdingAPI/Framework/Models/SConfig.cs
index 0de96297..c3f0816e 100644
--- a/src/StardewModdingAPI/Framework/Models/SConfig.cs
+++ b/src/StardewModdingAPI/Framework/Models/SConfig.cs
@@ -12,6 +12,9 @@
/// <summary>Whether to check if a newer version of SMAPI is available on startup.</summary>
public bool CheckForUpdates { get; set; } = true;
+ /// <summary>Whether SMAPI should log more information about the game context.</summary>
+ public bool VerboseLogging { get; set; } = false;
+
/// <summary>A list of mod versions which should be considered compatible or incompatible regardless of whether SMAPI detects incompatible code.</summary>
public ModCompatibility[] ModCompatibility { get; set; }
}
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index 6932af2a..d248c3ca 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -30,13 +30,13 @@ namespace StardewModdingAPI.Framework
/****
** SMAPI state
****/
+ /// <summary>The maximum number of consecutive attempts SMAPI should make to recover from a draw error.</summary>
+ private readonly int MaxFailedDraws = 120; // roughly two seconds
+
/// <summary>The number of ticks until SMAPI should notify mods that the game has loaded.</summary>
/// <remarks>Skipping a few frames ensures the game finishes initialising the world before mods try to change it.</remarks>
private int AfterLoadTimer = 5;
- /// <summary>The maximum number of consecutive attempts SMAPI should make to recover from a draw error.</summary>
- private readonly int MaxFailedDraws = 120; // roughly two seconds
-
/// <summary>The number of consecutive failed draws.</summary>
private int FailedDraws;
@@ -176,6 +176,12 @@ namespace StardewModdingAPI.Framework
private readonly Action renderScreenBuffer = () => SGame.Reflection.GetPrivateMethod(SGame.Instance, nameof(renderScreenBuffer)).Invoke(new object[0]);
// ReSharper restore ArrangeStaticMemberQualifier, ArrangeThisQualifier, InconsistentNaming
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Whether SMAPI should log more information about the game context.</summary>
+ public bool VerboseLogging { get; set; }
+
/*********
** Protected methods
@@ -1133,6 +1139,9 @@ namespace StardewModdingAPI.Framework
var oldValue = this.PreviousLocale;
var newValue = LocalizedContentManager.CurrentLanguageCode;
+ if (this.VerboseLogging)
+ this.Monitor.Log($"Context: locale set to {newValue}.", LogLevel.Trace);
+
if (oldValue != null)
ContentEvents.InvokeAfterLocaleChanged(this.Monitor, oldValue.ToString(), newValue.ToString());
this.PreviousLocale = newValue;
@@ -1143,7 +1152,7 @@ namespace StardewModdingAPI.Framework
{
if (this.AfterLoadTimer == 0)
{
- this.Monitor.Log($"Context: loaded saved game '{Constants.SaveFolderName}'.", LogLevel.Trace);
+ this.Monitor.Log($"Context: loaded saved game '{Constants.SaveFolderName}', starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace);
SaveEvents.InvokeAfterLoad(this.Monitor);
PlayerEvents.InvokeLoadedGame(this.Monitor, new EventArgsLoadedGameChanged(Game1.hasLoadedGame));
@@ -1224,6 +1233,17 @@ namespace StardewModdingAPI.Framework
IClickableMenu previousMenu = this.PreviousActiveMenu;
IClickableMenu newMenu = Game1.activeClickableMenu;
+ // log context
+ if (this.VerboseLogging)
+ {
+ if (previousMenu == null)
+ this.Monitor.Log($"Context: opened menu {newMenu?.GetType().FullName ?? "(none)"}.", LogLevel.Trace);
+ else if (newMenu == null)
+ this.Monitor.Log($"Context: closed menu {previousMenu.GetType().FullName}.", LogLevel.Trace);
+ else
+ this.Monitor.Log($"Context: changed menu from {previousMenu.GetType().FullName} to {newMenu.GetType().FullName}.", LogLevel.Trace);
+ }
+
// raise save events
// (saving is performed by SaveGameMenu; on days when the player shipping something, ShippingMenu wraps SaveGameMenu)
if (newMenu is SaveGameMenu || newMenu is ShippingMenu)
@@ -1233,7 +1253,7 @@ namespace StardewModdingAPI.Framework
}
else if (previousMenu is SaveGameMenu || previousMenu is ShippingMenu)
{
- this.Monitor.Log("Context: after save, starting new day.", LogLevel.Trace);
+ this.Monitor.Log($"Context: after save, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace);
SaveEvents.InvokeAfterSave(this.Monitor);
TimeEvents.InvokeAfterDayStarted(this.Monitor);
}
@@ -1262,6 +1282,8 @@ namespace StardewModdingAPI.Framework
// raise current location changed
if (Game1.currentLocation != this.PreviousGameLocation)
{
+ if (this.VerboseLogging)
+ this.Monitor.Log($"Context: set location to {Game1.currentLocation?.Name ?? "(none)"}.", LogLevel.Trace);
LocationEvents.InvokeCurrentLocationChanged(this.Monitor, this.PreviousGameLocation, Game1.currentLocation);
this.PreviousGameLocation = Game1.currentLocation;
}
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index 1e5fcfc3..1913544f 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -230,6 +230,7 @@ namespace StardewModdingAPI
{
// load settings
this.Settings = JsonConvert.DeserializeObject<SConfig>(File.ReadAllText(Constants.ApiConfigPath));
+ this.GameInstance.VerboseLogging = this.Settings.VerboseLogging;
// load core components
this.ModRegistry = new ModRegistry(this.Settings.ModCompatibility);
@@ -266,6 +267,8 @@ namespace StardewModdingAPI
this.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by reinstalling SMAPI or editing {Constants.ApiConfigPath}.", LogLevel.Warn);
if (!this.Monitor.WriteToConsole)
this.Monitor.Log("Writing to the terminal is disabled because the --no-terminal argument was received. This usually means launching the terminal failed.", LogLevel.Warn);
+ if (this.Settings.VerboseLogging)
+ this.Monitor.Log("Verbose logging enabled.", LogLevel.Trace);
// validate XNB integrity
if (!this.ValidateContentIntegrity())
diff --git a/src/StardewModdingAPI/StardewModdingAPI.config.json b/src/StardewModdingAPI/StardewModdingAPI.config.json
index 9438c621..f42a4dfc 100644
--- a/src/StardewModdingAPI/StardewModdingAPI.config.json
+++ b/src/StardewModdingAPI/StardewModdingAPI.config.json
@@ -22,6 +22,11 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha
"CheckForUpdates": true,
/**
+ * Whether SMAPI should log more information about the game context.
+ */
+ "VerboseLogging": false,
+
+ /**
* A list of mod versions SMAPI should consider compatible or broken regardless of whether it
* detects incompatible code. Each record can be set to `AssumeCompatible` or `AssumeBroken`.
* Changing this field is not recommended and may destabilise your game.