示例#1
0
        public static List <string> FetchAutocompleteOptions(string command, string[] tokens)
        {
            // if there are no or only a single parameter then attempt to autocomplete the type
            if (tokens.Length <= 1)
            {
                string typeString = tokens.Length == 1 ? tokens[0] : "";

                // filter the options based on the type name
                List <string> autocompleteOptions = ConsoleDaemon.Instance.AvailableComponents.Keys.
                                                    Where(typeName => typeName.StartsWith(typeString)).
                                                    Select(typeName => command + " " + typeName).ToList();

                // if we found results then return them
                if (autocompleteOptions != null && autocompleteOptions.Count > 0)
                {
                    // only return if there was not an exact match
                    if (!(tokens.Length > 0 && autocompleteOptions.Contains(command + " " + tokens[0])))
                    {
                        return(autocompleteOptions);
                    }
                }
            }

            // if there are more than 2 tokens then don't run the autocomplete
            if (tokens.Length > 2)
            {
                return(null);
            }

            // fetch the autocomplete options
            return(CommandHelpers.GetGameObjectAutocompleteOptions(tokens.Length > 1 ? tokens[1] : "", command + " " + tokens[0]));
        }
示例#2
0
        public static List <string> FetchAutocompleteOptions(string command, string[] tokens)
        {
            // can only autocomplete if there is only 1 or two tokens
            if (tokens.Length > 2)
            {
                return(null);
            }

            List <string> autocompleteOptions = new List <string>();

            // check if we're just at the specifying local or world stage
            if (tokens.Length <= 1)
            {
                string lowerCaseToken = tokens.Length == 1 ? tokens[0].ToLower() : "";

                // autocomplete the coordinate space
                if (lowerCaseToken != "local" && "local".StartsWith(lowerCaseToken))
                {
                    autocompleteOptions.Add(command + " local");
                }
                else if (lowerCaseToken != "world" && "world".StartsWith(lowerCaseToken))
                {
                    autocompleteOptions.Add(command + " world");
                }

                // found valid autocomplete options?
                if (autocompleteOptions.Count > 0)
                {
                    return(autocompleteOptions);
                }
            }

            // fetch the autocomplete options
            return(CommandHelpers.GetGameObjectAutocompleteOptions(tokens.Length > 1 ? tokens[1] : "", command + " " + tokens[0]));
        }
示例#3
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.GetGameObjectAutocompleteOptions(tokens.Length > 0 ? tokens[0] : "", command));
        }
示例#4
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 + " active", command + " inactive", command + " true", command + " false" }));
            }

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

                if ("active".StartsWith(tokens[0].ToLower()))
                {
                    options.Add(command + " active");
                }
                if ("inactive".StartsWith(tokens[0].ToLower()))
                {
                    options.Add(command + " inactive");
                }
                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.GetGameObjectAutocompleteOptions(tokens.Length > 1 ? tokens[1] : "", command + " " + tokens[0]));
        }
示例#5
0
        public static List <string> FetchAutocompleteOptions(string command, string[] tokens)
        {
            // can only autocomplete if there are no, 1 or 2 tokens
            if (tokens.Length > 2)
            {
                return(null);
            }

            // none or one token?
            if (tokens.Length <= 1)
            {
                List <string> autocompleteOptions = CommandHelpers.GetGameObjectAutocompleteOptions(tokens.Length > 0 ? tokens[0] : "", command);

                if (autocompleteOptions != null)
                {
                    return(autocompleteOptions);
                }
            }

            // this shouldn't happen! but just in case
            if (tokens.Length == 0)
            {
                Debug.LogError("Failed to find autocomplete options and have no tokens. This shouldn't be possible.");
                return(null);
            }

            // setup the base path for the autocomplete options
            string basePath = tokens[0];

            if (basePath.Contains(" "))
            {
                basePath = command + " \"" + tokens[0] + "\"";
            }
            else
            {
                basePath = command + " " + tokens[0];
            }

            // fetch the autocomplete options
            return(CommandHelpers.GetGameObjectAutocompleteOptions(tokens.Length > 1 ? tokens[1] : "", basePath));
        }