From 2ca49fba62f59135c2ed3ec7958cb78073ff486b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 Jul 2017 02:45:02 -0400 Subject: encapsulate TrainerMod's argument parsing (#302) --- .../Framework/Commands/Player/SetSpeedCommand.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs') diff --git a/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs b/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs index a8c05d0c..40b87b62 100644 --- a/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs +++ b/src/TrainerMod/Framework/Commands/Player/SetSpeedCommand.cs @@ -1,5 +1,4 @@ -using System.Linq; -using StardewModdingAPI; +using StardewModdingAPI; using StardewValley; namespace TrainerMod.Framework.Commands.Player @@ -18,22 +17,14 @@ namespace TrainerMod.Framework.Commands.Player /// Writes messages to the console and log file. /// The command name. /// The command arguments. - public override void Handle(IMonitor monitor, string command, string[] args) + public override void Handle(IMonitor monitor, string command, ArgumentParser args) { - // validate - if (!args.Any()) - { - monitor.Log($"You currently have {Game1.player.addedSpeed} added speed. Specify a value to change it.", LogLevel.Info); + // parse arguments + if (!args.TryGetInt(0, "added speed", out int amount, min: 0)) return; - } - if (!int.TryParse(args[0], out int addedSpeed)) - { - this.LogArgumentNotInt(monitor, command); - return; - } // handle - Game1.player.addedSpeed = addedSpeed; + Game1.player.addedSpeed = amount; monitor.Log($"OK, your added speed is now {Game1.player.addedSpeed}.", LogLevel.Info); } } -- cgit