diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-11-01 17:42:18 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-11-01 17:42:18 -0400 |
commit | e0b72374cd14298aacc6f71dc391fdc9814be37c (patch) | |
tree | 2e5d85937c34539c1a0df48423b5136508693ca8 /src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs | |
parent | 79118316065a01322d8ea12a14589ec016794c32 (diff) | |
parent | 089e6de749ae7cb109af00164d2597c6644c255e (diff) | |
download | SMAPI-e0b72374cd14298aacc6f71dc391fdc9814be37c.tar.gz SMAPI-e0b72374cd14298aacc6f71dc391fdc9814be37c.tar.bz2 SMAPI-e0b72374cd14298aacc6f71dc391fdc9814be37c.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs')
-rw-r--r-- | src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs new file mode 100644 index 00000000..d6c71387 --- /dev/null +++ b/src/SMAPI.Mods.ConsoleCommands/Framework/Commands/World/SetTimeCommand.cs @@ -0,0 +1,39 @@ +using System.Linq; +using StardewValley; + +namespace StardewModdingAPI.Mods.ConsoleCommands.Framework.Commands.World +{ + /// <summary>A command which sets the current time.</summary> + internal class SetTimeCommand : TrainerCommand + { + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + public SetTimeCommand() + : base("world_settime", "Sets the time to the specified value.\n\nUsage: world_settime <value>\n- value: the target time in military time (like 0600 for 6am and 1800 for 6pm).") { } + + /// <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) + { + // no-argument mode + if (!args.Any()) + { + monitor.Log($"The current time is {Game1.timeOfDay}. Specify a value to change it.", LogLevel.Info); + return; + } + + // parse arguments + if (!args.TryGetInt(0, "time", out int time, min: 600, max: 2600)) + return; + + // handle + Game1.timeOfDay = time; + FreezeTimeCommand.FrozenTime = Game1.timeOfDay; + monitor.Log($"OK, the time is now {Game1.timeOfDay.ToString().PadLeft(4, '0')}.", LogLevel.Info); + } + } +} |