summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/TestInputCommand.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-01-22 20:36:24 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-01-22 20:36:24 -0500
commit381de5eba9f9822c3483abdf64396cec794e3d03 (patch)
treee256864f213a6bdbcfddb526b326d11d9f1c91e5 /src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/TestInputCommand.cs
parent1670a2f3a6263da158db5231f60d42d529734209 (diff)
downloadSMAPI-381de5eba9f9822c3483abdf64396cec794e3d03.tar.gz
SMAPI-381de5eba9f9822c3483abdf64396cec794e3d03.tar.bz2
SMAPI-381de5eba9f9822c3483abdf64396cec794e3d03.zip
add test_input console command
Diffstat (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/TestInputCommand.cs')
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/TestInputCommand.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/TestInputCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/TestInputCommand.cs
new file mode 100644
index 00000000..11aa10c3
--- /dev/null
+++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/Other/TestInputCommand.cs
@@ -0,0 +1,59 @@
+using System;
+
+namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.Other
+{
+ /// <summary>A command which logs the keys being pressed for 30 seconds once enabled.</summary>
+ internal class TestInputCommand : TrainerCommand
+ {
+ /*********
+ ** Fields
+ *********/
+ /// <summary>The number of seconds for which to log input.</summary>
+ private readonly int LogSeconds = 30;
+
+ /// <summary>When the command should stop printing input, or <c>null</c> if currently disabled.</summary>
+ private long? ExpiryTicks;
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public TestInputCommand()
+ : base("test_input", "Prints all input to the console for 30 seconds.", mayNeedUpdate: true, mayNeedInput: true) { }
+
+ /// <summary>Handle the command.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="command">The command name.</param>
+ /// <param name="args">The command arguments.</param>
+ public override void Handle(IMonitor monitor, string command, ArgumentParser args)
+ {
+ this.ExpiryTicks = DateTime.UtcNow.Add(TimeSpan.FromSeconds(this.LogSeconds)).Ticks;
+ monitor.Log($"OK, logging all player input for {this.LogSeconds} seconds.", LogLevel.Info);
+ }
+
+ /// <summary>Perform any logic needed on update tick.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ public override void OnUpdated(IMonitor monitor)
+ {
+ // handle expiry
+ if (this.ExpiryTicks == null)
+ return;
+ if (this.ExpiryTicks <= DateTime.UtcNow.Ticks)
+ {
+ monitor.Log("No longer logging input.", LogLevel.Info);
+ this.ExpiryTicks = null;
+ return;
+ }
+ }
+
+ /// <summary>Perform any logic when input is received.</summary>
+ /// <param name="monitor">Writes messages to the console and log file.</param>
+ /// <param name="button">The button that was pressed.</param>
+ public override void OnButtonPressed(IMonitor monitor, SButton button)
+ {
+ if (this.ExpiryTicks != null)
+ monitor.Log($"Pressed {button}", LogLevel.Info);
+ }
+ }
+}