Ejemplo n.º 1
0
        /// <summary>
        /// Add a new command with names separated by folders/namespaces, last is command name, others are holders.
        /// These will be made as required
        /// during the add.
        /// </summary>
        /// <param name="names">separated command name e.g. Physics.gravity is now {"Physics","gravity"}</param>
        /// <param name="callback">action of the command to add</param>
        /// <param name="helpText">help text to show to user about the command</param>
        /// <param name="command_index">used in the recursion, indicates current depth in names array</param>
        public void Add(string[] names, Console.CommandCallback callback, string helpText, int command_index = 0)
        {
            if (names.Length == command_index)
            {
                Command = new ConsoleCommandData {
                    localName = names.Last(), callback = callback, help = helpText
                };
                return;
            }

            string token      = names[command_index];
            string lowerToken = token.ToLowerInvariant();

            if (!subCommandsLookUp.ContainsKey(lowerToken))
            {
                ConsoleCommandData data = new ConsoleCommandData
                {
                    localName = token
                };
                subCommandsLookUp[lowerToken] = new ConsoleCommandTreeNode(this, data);
            }
            subCommandsLookUp[lowerToken].Add(names, callback, helpText, command_index + 1);
        }
Ejemplo n.º 2
0
 protected ConsoleCommandTreeNode(ConsoleCommandTreeNode parent, ConsoleCommandData data)
 {
     parentNode = parent;
     Command    = data;
 }