public Program()
 {
     PROGRAM = this;
     InitializeParsers();
     ParameterProcessorRegistry.InitializeProcessors();
     Runtime.UpdateFrequency = UPDATE_FREQUENCY;
 }
        private static Command ParseCommand(List <CommandParameter> parameters)
        {
            Trace("Parsing Command");
            Trace("Pre Processed Parameters:");
            parameters.ForEach(param => Trace("Type: " + param.GetType()));

            ParameterProcessorRegistry.Process(parameters);

            if (parameters.Count != 1 || !(parameters[0] is CommandReferenceParameter))
            {
                throw new Exception("Unable to parse command from command parameters!");
            }
            return(((CommandReferenceParameter)parameters[0]).Value);
        }
示例#3
0
        private void DoParameterSuggestions(int termIdx)
        {
            // TODO - null ptr checks for suggestion text box

            CommandDef commandDef = CommandRegistry.GetCommand(UserInputTerms[0]);

            if (!commandDef.IsValid())
            {
                SuggestionText.text = "No Matching Commands!";
                return;
            }
            Assert.IsTrue(commandDef.IsValid());

            if (termIdx < 0 || termIdx >= commandDef.Command.GetNumExpectedTerms())
            {
                return;
            }

            string[] terms = commandDef.GetCommandFormatAsTerms();
            if (termIdx < terms.Length)
            {
                terms[termIdx] = "<b><color=#ffffffff>" + terms[termIdx] + "</color></b>";
            }

            SuggestionText.text += Utils.GetCommand(terms) + "\n";

            string searchTerm       = termIdx < UserInputTerms.Length ? UserInputTerms[termIdx] : "";
            int    paramIdx         = termIdx - 1;
            var    cmd              = commandDef.Command;
            var    paramSuggestions = ParameterProcessorRegistry.FindSuggestionsFor(cmd.GetParamType(paramIdx), cmd.GetParameterAttributes(paramIdx), searchTerm, 20);

            if (paramSuggestions != null)
            {
                string suggestionDisplayPrefix = "";
                for (int i = 0; i < Mathf.Min(terms.Length, termIdx); i++)
                {
                    suggestionDisplayPrefix += terms[i] + " ";
                }

                suggestionDisplayPrefix = "<color=#ffffff00>" + suggestionDisplayPrefix + "</color>";

                for (int i = 0, num = paramSuggestions.Count; i < num; i++)
                {
                    var paramSuggestion = paramSuggestions[i];
                    Suggestions.Add(paramSuggestion);
                    SuggestionText.text += suggestionDisplayPrefix + paramSuggestion.Display + "\n";
                }
            }
        }
示例#4
0
        private void DoCommandSuggestions()
        {
            // TODO - null ptr checks for suggestion text box

            var suggestions = ParameterProcessorRegistry.FindSuggestionsFor(typeof(CommandDef), null, UserInputTerms[0], 20);

            for (int i = 0, num = suggestions.Count; i < num; i++)
            {
                var suggestion = suggestions[i];
                var commandDef = (CommandDef)ParameterProcessorRegistry.ConvertString(typeof(CommandDef), suggestion.Value);
                if (commandDef.IsValid())
                {
                    Suggestions.Add(commandDef.Name);
                    SuggestionText.text += commandDef.GetCommandFormat() + "\n";
                }
                else
                {
                    Suggestions.Add(suggestion.Value);
                    SuggestionText.text += suggestion.Display + "\n";
                }
            }
        }