예제 #1
0
        public static List <string> FetchAutocompleteOptions(string command, string[] tokens)
        {
            // can only autocomplete if there is a single token or no token
            if (tokens.Length > 1)
            {
                return(null);
            }

            // fetch the autocomplete options
            return(CommandHelpers.GetComponentAutocompleteOptions(tokens.Length > 0 ? tokens[0] : "", command));
        }
예제 #2
0
        public static List <string> FetchAutocompleteOptions(string command, string[] tokens)
        {
            // don't autocomplete once we are entering the variable
            if (tokens.Length >= 2)
            {
                return(null);
            }

            // at the variable autocomplete stage (ie. need reflection)
            if (tokens.Length > 0 && tokens[0].Count(character => character == '.') > 1)
            {
                return(CommandHelpers.GetAutocompleteOptions(tokens[0], command, CommandHelpers.AutocompleteCandidates.Variables));
            }

            // fetch the game object autocomplete options
            string        path = tokens.Length > 0 ? tokens[0] : "";
            List <string> autocompleteOptions = CommandHelpers.GetComponentAutocompleteOptions(path, command);

            if (autocompleteOptions == null)
            {
                autocompleteOptions = new List <string>();
            }

            // user has entered exact path to a component - switch to variable autocomplete stage
            if ((tokens.Length > 0) && (autocompleteOptions.Count <= 1) && (CommandHelpers.GetComponent(tokens[0]) != null))
            {
                return(CommandHelpers.GetAutocompleteOptions(tokens[0], command, CommandHelpers.AutocompleteCandidates.Variables));
            }

            // append the type based autocomplete options
            autocompleteOptions.AddRange(ConsoleDaemon.Instance.AvailableTypes.Keys
                                         .Where(typeName => typeName.StartsWith(path))
                                         .Select(typeName => command + " " + typeName).ToList());

            // if we have no autocomplete options at this stage then we are working with a class
            if (tokens.Length > 0 && (autocompleteOptions == null || autocompleteOptions.Count <= 1))
            {
                string[] pathElements = tokens[0].Split('.');

                // check if the class is in the cached types
                if (ConsoleDaemon.Instance.AvailableTypes.ContainsKey(pathElements[0]))
                {
                    return(CommandHelpers.GetAutocompleteOptions(tokens[0], command, CommandHelpers.AutocompleteCandidates.Variables));
                }
            }

            return(autocompleteOptions);
        }
예제 #3
0
        public static List <string> FetchAutocompleteOptions(string command, string[] tokens)
        {
            // no tokens so just return these options
            if (tokens.Length == 0)
            {
                return(new List <string>(new string[] { command + " enabled", command + " disabled", command + " true", command + " false" }));
            }

            // if we have one token then it may be a partial one
            if (tokens.Length == 1 &&
                tokens[0].ToLower() != "enabled" && tokens[0].ToLower() != "disabled" &&
                tokens[0].ToLower() != "true" && tokens[0].ToLower() != "false")
            {
                List <string> options = new List <string>();

                if ("enabled".StartsWith(tokens[0].ToLower()))
                {
                    options.Add(command + " enabled");
                }
                if ("disabled".StartsWith(tokens[0].ToLower()))
                {
                    options.Add(command + " disabled");
                }
                if ("true".StartsWith(tokens[0].ToLower()))
                {
                    options.Add(command + " true");
                }
                if ("false".StartsWith(tokens[0].ToLower()))
                {
                    options.Add(command + " false");
                }

                return(options);
            }

            // invalid number of tokens so no autocompletion
            if (tokens.Length > 2)
            {
                return(null);
            }

            // fetch the autocomplete options
            return(CommandHelpers.GetComponentAutocompleteOptions(tokens.Length > 1 ? tokens[1] : "", command + " " + tokens[0]));
        }