From f9482906ae7ce4dfd41bb4236e094be5d4fa7689 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 2 Jul 2017 01:32:07 -0400 Subject: split TrainerMod commands into separate classes (#302) --- .../Framework/Commands/World/SetTimeCommand.cs | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs (limited to 'src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs') diff --git a/src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs b/src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs new file mode 100644 index 00000000..4ecff485 --- /dev/null +++ b/src/TrainerMod/Framework/Commands/World/SetTimeCommand.cs @@ -0,0 +1,46 @@ +using System.Linq; +using StardewModdingAPI; +using StardewValley; + +namespace TrainerMod.Framework.Commands.World +{ + /// A command which sets the current time. + internal class SetTimeCommand : TrainerCommand + { + /********* + ** Public methods + *********/ + /// Construct an instance. + public SetTimeCommand() + : base("world_settime", "Sets the time to the specified value.\n\nUsage: world_settime \n- value: the target time in military time (like 0600 for 6am and 1800 for 6pm).") { } + + /// Handle the command. + /// Writes messages to the console and log file. + /// The command name. + /// The command arguments. + public override void Handle(IMonitor monitor, string command, string[] args) + { + // validate + if (!args.Any()) + { + monitor.Log($"The current time is {Game1.timeOfDay}. Specify a value to change it.", LogLevel.Info); + return; + } + if (!int.TryParse(args[0], out int time)) + { + this.LogArgumentNotInt(monitor, command); + return; + } + if (time > 2600 || time < 600) + { + this.LogUsageError(monitor, "That isn't a valid time.", command); + return; + } + + // handle + Game1.timeOfDay = time; + FreezeTimeCommand.FrozenTime = Game1.timeOfDay; + monitor.Log($"OK, the time is now {Game1.timeOfDay.ToString().PadLeft(4, '0')}.", LogLevel.Info); + } + } +} -- cgit