Beispiel #1
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);
        }