using StardewModdingAPI; namespace TrainerMod.Framework.Commands { /// The base implementation for a trainer command. internal abstract class TrainerCommand : ITrainerCommand { /********* ** Accessors *********/ /// The command name the user must type. public string Name { get; } /// The command description. public string Description { get; } /// Whether the command needs to perform logic when the game updates. public virtual bool NeedsUpdate { get; } = false; /********* ** Public methods *********/ /// Handle the command. /// Writes messages to the console and log file. /// The command name. /// The command arguments. public abstract void Handle(IMonitor monitor, string command, ArgumentParser args); /// Perform any logic needed on update tick. /// Writes messages to the console and log file. public virtual void Update(IMonitor monitor) { } /********* ** Protected methods *********/ /// Construct an instance. /// The command name the user must type. /// The command description. protected TrainerCommand(string name, string description) { this.Name = name; this.Description = description; } /// Log an error indicating incorrect usage. /// Writes messages to the console and log file. /// A sentence explaining the problem. protected void LogUsageError(IMonitor monitor, string error) { monitor.Log($"{error} Type 'help {this.Name}' for usage.", LogLevel.Error); } /// Log an error indicating a value must be an integer. /// Writes messages to the console and log file. protected void LogArgumentNotInt(IMonitor monitor) { this.LogUsageError(monitor, "The value must be a whole number."); } } }