summaryrefslogtreecommitdiff
path: root/src/SMAPI.Mods.ConsoleCommands/ModEntry.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/ModEntry.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/ModEntry.cs')
-rw-r--r--src/SMAPI.Mods.ConsoleCommands/ModEntry.cs31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs b/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs
index 4807c46d..5c4f3bba 100644
--- a/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs
+++ b/src/SMAPI.Mods.ConsoleCommands/ModEntry.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using StardewModdingAPI.Events;
using StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands;
namespace StardewModdingAPI.Mods.ConsoleCommands
@@ -14,6 +15,12 @@ namespace StardewModdingAPI.Mods.ConsoleCommands
/// <summary>The commands to handle.</summary>
private ITrainerCommand[] Commands;
+ /// <summary>The commands which may need to handle update ticks.</summary>
+ private ITrainerCommand[] UpdateHandlers;
+
+ /// <summary>The commands which may need to handle input.</summary>
+ private ITrainerCommand[] InputHandlers;
+
/*********
** Public methods
@@ -27,27 +34,35 @@ namespace StardewModdingAPI.Mods.ConsoleCommands
foreach (ITrainerCommand command in this.Commands)
helper.ConsoleCommands.Add(command.Name, command.Description, (name, args) => this.HandleCommand(command, name, args));
+ // cache commands
+ this.InputHandlers = this.Commands.Where(p => p.MayNeedInput).ToArray();
+ this.UpdateHandlers = this.Commands.Where(p => p.MayNeedUpdate).ToArray();
+
// hook events
helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
+ helper.Events.Input.ButtonPressed += this.OnButtonPressed;
}
/*********
** Private methods
*********/
+ /// <summary>The method invoked when a button is pressed.</summary>
+ /// <param name="sender">The event sender.</param>
+ /// <param name="e">The event arguments.</param>
+ private void OnButtonPressed(object sender, ButtonPressedEventArgs e)
+ {
+ foreach (ITrainerCommand command in this.InputHandlers)
+ command.OnButtonPressed(this.Monitor, e.Button);
+ }
+
/// <summary>The method invoked when the game updates its state.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnUpdateTicked(object sender, EventArgs e)
{
- if (!Context.IsWorldReady)
- return;
-
- foreach (ITrainerCommand command in this.Commands)
- {
- if (command.NeedsUpdate)
- command.Update(this.Monitor);
- }
+ foreach (ITrainerCommand command in this.UpdateHandlers)
+ command.OnUpdated(this.Monitor);
}
/// <summary>Handle a console command.</summary>