Пример #1
0
        /// <summary>
        /// Prepares the command system, registering all base commands.
        /// </summary>
        public void Init()
        {
            PlaceholderQueue = new CommandQueue(new CommandScript("PLACEHOLDER_QUEUE", new List<CommandEntry>()), new List<CommandEntry>(), this);
            RegisteredCommands = new Dictionary<string, AbstractCommand>(30);
            RegisteredCommandList = new List<AbstractCommand>(30);
            Scripts = new Dictionary<string, CommandScript>(30);
            Functions = new Dictionary<string, CommandScript>(30);
            Events = new Dictionary<string, ScriptEvent>(30);
            Queues = new List<CommandQueue>(20);
            TagSystem = new TagParser();
            TagSystem.Init(this);

            // Common Commands
            RegisterCommand(new CleanmemCommand());
            RegisterCommand(new CvarinfoCommand());
            RegisterCommand(new EchoCommand());
            RegisterCommand(new NoopCommand());
            RegisterCommand(new SetCommand());
            RegisterCommand(new ToggleCommand());

            // Queue-related Commands
            RegisterCommand(new BreakCommand());
            RegisterCommand(new CallCommand());
            RegisterCommand(new DebugCommand());
            RegisterCommand(new DefineCommand());
            RegisterCommand(new DetermineCommand());
            RegisterCommand(new ElseCommand());
            RegisterCommand(new EventCommand());
            RegisterCommand(new ForeachCommand());
            RegisterCommand(new FunctionCommand());
            RegisterCommand(new GotoCommand());
            RegisterCommand(new IfCommand());
            RegisterCommand(new InsertCommand());
            RegisterCommand(new MarkCommand());
            RegisterCommand(new ParsingCommand());
            RegisterCommand(new RepeatCommand());
            RegisterCommand(TheRunCommand = new RunCommand());
            RegisterCommand(new ScriptCacheCommand());
            RegisterCommand(new StopCommand());
            RegisterCommand(new UndefineCommand());
            RegisterCommand(new WaitCommand());
            RegisterCommand(new WhileCommand());

            // Register debug command
            RegisterCommand(DebugInvalidCommand = new DebugOutputInvalidCommand());

            // Command-Related Events
            RegisterEvent(new ScriptRanPreScriptEvent(this));
            RegisterEvent(new ScriptRanScriptEvent(this));
            RegisterEvent(new ScriptRanPostScriptEvent(this));
        }
Пример #2
0
 /// <summary>
 /// Executes a command script.
 /// Returns the determined value(s).
 /// </summary>
 /// <param name="script">The script to execute.</param>
 /// <param name="Variables">What variables to add to the commandqueue.</param>
 /// <param name="queue">Outputs the generated queue (already ran or running).</param>
 public List<string> ExecuteScript(CommandScript script, Dictionary<string, TemplateObject> Variables, out CommandQueue queue)
 {
     queue = script.ToQueue(this);
     if (Variables != null)
     {
         foreach (KeyValuePair<string, TemplateObject> variable in Variables)
         {
             queue.SetVariable(variable.Key, variable.Value);
         }
     }
     queue.Execute();
     return queue.Determinations;
 }
Пример #3
0
 /// <summary>
 /// Executes a single command.
 /// </summary>
 /// <param name="entry">The command entry to execute.</param>
 /// <param name="queue">The queue that is executing it.</param>
 public void ExecuteCommand(CommandEntry entry, CommandQueue queue)
 {
     try
     {
         entry.Queue = queue;
         entry.Output = Output;
         if (entry.Command == DebugInvalidCommand)
         {
             // Last try - perhaps a command was registered after the script was loaded.
             AbstractCommand cmd;
             if (RegisteredCommands.TryGetValue(entry.Name.ToLower(), out cmd))
             {
                 entry.Command = cmd;
             }
         }
         entry.Command.Execute(entry);
     }
     catch (Exception ex)
     {
         Output.Bad("Command '" + TextStyle.Color_Standout + TagParser.Escape(entry.CommandLine) +
             TextStyle.Color_Error + "' threw an error: " + TagParser.Escape(ex.ToString()), DebugMode.NONE);
     }
 }
Пример #4
0
 /// <summary>
 /// Creates a new queue for this script.
 /// </summary>
 /// <param name="system">The command system to make the queue in.</param>
 /// <returns>The created queue.</returns>
 public CommandQueue ToQueue(Commands system)
 {
     CommandQueue queue = new CommandQueue(this, GetEntries(), system);
     queue.Debug = Debug;
     return queue;
 }
Пример #5
0
 /// <summary>
 /// Constructs the event args.
 /// </summary>
 /// <param name="queue">The relevant queue.</param>
 public CommandQueueEventArgs(CommandQueue queue)
 {
     Queue = queue;
 }
Пример #6
0
 /// <summary>
 /// Used to properly handle an unknown command.
 /// </summary>
 /// <param name="queue">The queue firing this unknown command.</param>
 /// <param name="basecommand">The command that wasn't recognized.</param>
 /// <param name="arguments">The commands arguments.</param>
 public abstract void UnknownCommand(CommandQueue queue, string basecommand, string[] arguments);