summaryrefslogtreecommitdiff
path: root/StardewModdingAPI/Command.cs
diff options
context:
space:
mode:
authorGormogon <Gormogon@users.noreply.github.com>2016-05-29 18:23:01 -0400
committerGormogon <Gormogon@users.noreply.github.com>2016-05-29 18:23:01 -0400
commit27dece2cf445147c5e2848f9ec26f38a101f50fc (patch)
tree2579d0979dd9f295972e5ba2a81f4177589f7395 /StardewModdingAPI/Command.cs
parent85142935b63324f7c6131a8855acea0a2d534879 (diff)
downloadSMAPI-27dece2cf445147c5e2848f9ec26f38a101f50fc.tar.gz
SMAPI-27dece2cf445147c5e2848f9ec26f38a101f50fc.tar.bz2
SMAPI-27dece2cf445147c5e2848f9ec26f38a101f50fc.zip
Attempt to migrate to new directory structure.
Diffstat (limited to 'StardewModdingAPI/Command.cs')
-rw-r--r--StardewModdingAPI/Command.cs109
1 files changed, 0 insertions, 109 deletions
diff --git a/StardewModdingAPI/Command.cs b/StardewModdingAPI/Command.cs
deleted file mode 100644
index 4214b1a7..00000000
--- a/StardewModdingAPI/Command.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-using System;
-using System.Collections.Generic;
-using StardewModdingAPI.Events;
-
-namespace StardewModdingAPI
-{
- public class Command
- {
- internal static List<Command> RegisteredCommands = new List<Command>();
- public string[] CalledArgs;
- public string[] CommandArgs;
- public string CommandDesc;
-
- public string CommandName;
-
- /// <summary>
- /// Creates a Command from a Name, Description, and Arguments
- /// </summary>
- /// <param name="cname">Name</param>
- /// <param name="cdesc">Description</param>
- /// <param name="args">Arguments</param>
- public Command(string cname, string cdesc, string[] args = null)
- {
- CommandName = cname;
- CommandDesc = cdesc;
- if (args == null)
- args = new string[0];
- CommandArgs = args;
- }
-
- public event EventHandler<EventArgsCommand> CommandFired;
-
- /// <summary>
- /// Calls the specified command. (It runs the command)
- /// </summary>
- /// <param name="input">The command to run</param>
- public static void CallCommand(string input)
- {
- input = input.TrimEnd(' ');
- var args = new string[0];
- Command fnd;
- if (input.Contains(" "))
- {
- args = input.Split(new[] {" "}, 2, StringSplitOptions.RemoveEmptyEntries);
- fnd = FindCommand(args[0]);
- args = args[1].Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries);
- }
- else
- {
- fnd = FindCommand(input);
- }
-
- if (fnd != null)
- {
- fnd.CalledArgs = args;
- fnd.Fire();
- }
- else
- {
- Log.AsyncR("Unknown Command");
- }
- }
-
- /// <summary>
- /// Registers a command to the list of commands properly
- /// </summary>
- /// <param name="command">Name of the command to register</param>
- /// <param name="cdesc">Description</param>
- /// <param name="args">Arguments (these are purely for viewing so that a user can see what an argument needs to be)</param>
- /// <returns></returns>
- public static Command RegisterCommand(string command, string cdesc, string[] args = null)
- {
- var c = new Command(command, cdesc, args);
- if (RegisteredCommands.Contains(c))
- {
- Log.AsyncR($"Command already registered! [{c.CommandName}]");
- return RegisteredCommands.Find(x => x.Equals(c));
- }
-
- RegisteredCommands.Add(c);
- Log.Async("Registered command: " + command);
-
- return c;
- }
-
- /// <summary>
- /// Looks up a command in the list of registered commands. Returns null if it doesn't exist (I think)
- /// </summary>
- /// <param name="name">Name of command to find</param>
- /// <returns></returns>
- public static Command FindCommand(string name)
- {
- return RegisteredCommands.Find(x => x.CommandName.Equals(name));
- }
-
- /// <summary>
- /// Runs a command. Fires it. Calls it. Any of those.
- /// </summary>
- public void Fire()
- {
- if (CommandFired == null)
- {
- Log.AsyncR("Command failed to fire because it's fire event is null: " + CommandName);
- return;
- }
- CommandFired.Invoke(this, new EventArgsCommand(this));
- }
- }
-} \ No newline at end of file