示例#1
0
        private static void getCommands(string args)
        {
            if (string.IsNullOrWhiteSpace(args))
            {
                Pigeon.Console.Log("Available engine commands:");
                Pigeon.Console.Log(ConsoleUtilities.BracketedList(Pigeon.Console.EngineCommandNames));

                if (Pigeon.Console.GameCommandNames.Count > 0)
                {
                    Pigeon.Console.Log("Available game commands:");
                    Pigeon.Console.Log(ConsoleUtilities.BracketedList(Pigeon.Console.GameCommandNames));
                }
            }
            else
            {
                var matches = Pigeon.Console.AllCommandNames.FindStringMatches(args);

                if (matches.Count == 0)
                {
                    Pigeon.Console.Log(string.Format("no commands match for '{0}'", args));
                }
                else
                {
                    Pigeon.Console.Log(string.Format("commands matching '{0}':", args));
                    Pigeon.Console.Log(ConsoleUtilities.BracketedList(matches));
                }
            }
        }
示例#2
0
        private static void findKeyboardKeyName(string args)
        {
            var matches = EnumUtil.GetValues <Keys>().Select(k => k.ToString()).FindStringMatches(args);

            if (matches.Count == 0)
            {
                Pigeon.Console.Log(string.Format("no keys match for '{0}'", args));
            }
            else
            {
                Pigeon.Console.Log(string.Format("keys matching '{0}':", args));
                Pigeon.Console.Log(ConsoleUtilities.BracketedList(matches));
            }
        }
示例#3
0
        private static void getComponents(string args)
        {
            var obj = Pigeon.World.FindObj(args);

            if (obj.components?.Count > 0)
            {
                var componentNames = new List <string>();
                foreach (var component in obj.components)
                {
                    componentNames.Add(component.GetType().Name);
                }

                Pigeon.Console.Log(ConsoleUtilities.BracketedList(componentNames));
            }
            else
            {
                Pigeon.Console.Log("object has no components");
            }
        }
示例#4
0
        private static void setAlias(string args)
        {
            var manager = Pigeon.Console.AliasManager;

            if (string.IsNullOrEmpty(args))
            {
                var names = manager.GetNames();
                Pigeon.Console.Log(names.Count > 0 ? ConsoleUtilities.BracketedList(names) : "no aliases currently defined");
                return;
            }

            var splitArgs = args.Split(new[] { ' ' }, 2);
            var aliasName = splitArgs[0];

            if (splitArgs.Length == 1)
            {
                if (manager.Exists(aliasName))
                {
                    var commands = manager.Get(aliasName);

                    Pigeon.Console.Log(string.Format("{0}:", aliasName));
                    foreach (var command in commands)
                    {
                        Pigeon.Console.Log(string.Format("  -{0}", command));
                    }
                }
                else
                {
                    Pigeon.Console.Log(string.Format("no alias with name '{0}'", splitArgs[0]));
                }
                return;
            }

            string aliasValue = splitArgs[1];

            manager.Set(aliasName, aliasValue);
        }
示例#5
0
        private void handleAutocomplete()
        {
            if (commandBuffer.Length == 0)
            {
                return;
            }

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

            int minMatchingChars = 0;

            foreach (var commandPair in engineCommands)
            {
                var commandName = commandPair.Key;
                if (commandName.StartsWith(commandBuffer))
                {
                    minMatchingChars = Math.Min(minMatchingChars, commandName.Length - commandBuffer.Length);
                    possibleCommands.Add(commandName);
                }
            }

            foreach (var commandPair in gameCommands)
            {
                var commandName = commandPair.Key;
                if (commandName.StartsWith(commandBuffer))
                {
                    minMatchingChars = Math.Min(minMatchingChars, commandName.Length - commandBuffer.Length);
                    possibleCommands.Add(commandName);
                }
            }

            switch (possibleCommands.Count)
            {
            case 0:
                Log(string.Format("no commands starting with '{0}'...", commandBuffer));
                break;

            case 1:
                commandBuffer = possibleCommands[0];
                break;

            default:
                var referenceCommand = possibleCommands[0];

                bool breakLoop = false;
                int  charInd   = 0;
                while (charInd < referenceCommand.Length)
                {
                    // check every other command to see how many of their letters match
                    var character = referenceCommand[charInd];
                    for (int commandInd = 1; commandInd < possibleCommands.Count && !breakLoop; commandInd++)
                    {
                        string command = possibleCommands[commandInd];

                        if (charInd >= command.Length || command[charInd] != character)
                        {
                            charInd--;
                            breakLoop = true;
                        }
                    }

                    if (!breakLoop && charInd < referenceCommand.Length - 1)
                    {
                        charInd++;
                    }
                    else
                    {
                        break;
                    }
                }

                if (charInd + 1 > commandBuffer.Length)
                {
                    commandBuffer = referenceCommand.Substring(0, charInd + 1);
                }
                else
                {
                    Log(string.Format("commands starting with '{0}': ", commandBuffer));
                    Log(ConsoleUtilities.BracketedList(possibleCommands));
                }

                break;
            }

            commandCursorIndex = commandBuffer.Length;
        }