summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/SChatBox.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/SChatBox.cs')
-rw-r--r--src/SMAPI/Framework/SChatBox.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/SChatBox.cs b/src/SMAPI/Framework/SChatBox.cs
new file mode 100644
index 00000000..e000d1cd
--- /dev/null
+++ b/src/SMAPI/Framework/SChatBox.cs
@@ -0,0 +1,49 @@
+using StardewValley;
+using StardewValley.Menus;
+
+namespace StardewModdingAPI.Framework
+{
+ /// <summary>SMAPI's implementation of the chatbox which intercepts errors for logging.</summary>
+ internal class SChatBox : ChatBox
+ {
+ /*********
+ ** Fields
+ *********/
+ /// <summary>Encapsulates monitoring and logging.</summary>
+ private readonly IMonitor Monitor;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging.</param>
+ public SChatBox(IMonitor monitor)
+ {
+ this.Monitor = monitor;
+ }
+
+ /// <inheritdoc />
+ protected override void runCommand(string command)
+ {
+ this.Monitor.Log($"> chat command: {command}");
+ base.runCommand(command);
+ }
+
+ /// <inheritdoc />
+ public override void receiveChatMessage(long sourceFarmer, int chatKind, LocalizedContentManager.LanguageCode language, string message)
+ {
+ if (chatKind == ChatBox.errorMessage)
+ {
+ // log error
+ this.Monitor.Log(message, LogLevel.Error);
+
+ // add event details if applicable
+ if (Game1.CurrentEvent != null && message.StartsWith("Event script error:"))
+ this.Monitor.Log($"In event #{Game1.CurrentEvent.id} for location {Game1.currentLocation?.NameOrUniqueName}", LogLevel.Error);
+ }
+
+ base.receiveChatMessage(sourceFarmer, chatKind, language, message);
+ }
+ }
+}