Esempio n. 1
0
 public static void CommandQuery(commandSet targetCommandSet, commandData targetCommand)
 {
     if (targetCommandSet != null)
     {
         for (int i = 0; i < targetCommandSet.commands.Length; i++)
         {
             if (targetCommand.commandID == targetCommandSet.commands[i].commandID)
             {
                 targetCommandSet.commands[i].onCommandCall.Invoke(targetCommand.args);
             }
         }
     }
 }
Esempio n. 2
0
        // This function iterates over raw user input and breaks it down to valid commandData.
        public static commandData[] commandParse(string command)
        {
            string[] comStrings = new string[0];

            // Separate all words by " " spaces into divided strings.
            bool inString     = false;
            bool stringBounty = false;
            bool sbFirst      = false;

            char[] newString = new char[0];
            for (int i = 0; i < command.Length; i++)
            {
                if (command[i].ToString() == "\"" && !stringBounty)
                {
                    stringBounty = true;
                    sbFirst      = true;
                }
                if (command[i].ToString() == " " && !stringBounty)
                {
                    if (inString)
                    {
                        if (comStrings.Length != 0)
                        {
                            comStrings[comStrings.Length - 1] = new string(newString);
                        }
                    }
                    inString = false;
                }
                else
                {
                    if (!inString)
                    {
                        newString = new char[0];
                        Array.Resize(ref comStrings, comStrings.Length + 1);
                    }
                    inString = true;
                    Array.Resize(ref newString, newString.Length + 1);
                    newString[newString.Length - 1] = command[i];
                }
                if (stringBounty && command[i].ToString() == "\"" && !sbFirst)
                {
                    stringBounty = false;
                }
                if (command.Length - 1 == i)
                {
                    if (inString)
                    {
                        if (comStrings.Length != 0)
                        {
                            comStrings[comStrings.Length - 1] = new string(newString);
                        }
                    }
                }
                sbFirst = false;
            }

            // Identify witch strings are arg/variables

            bool isVar = false;

            commandData[] parsedCommands = new commandData[0];

            for (int a = 0; a < comStrings.Length; a++)
            {
                // Identify strings.
                if (comStrings[a][0].ToString() == "\"" && comStrings[a][comStrings[a].Length - 1].ToString() == "\"")
                {
                    isVar = true;
                }

                // Identify booleans
                if (comStrings[a] == "true" || comStrings[a] == "TRUE" || comStrings[a] == "false" || comStrings[a] == "FALSE")
                {
                    isVar = true;
                }

                // Identify integers


                //Identify command specific property ( --Command-Property )
                if (comStrings[a].Length >= 3)
                {
                    if (comStrings[a][0].ToString() == "-" && comStrings[a][1].ToString() == "-")
                    {
                        isVar = true;
                    }
                }

                if (!isVar)
                {
                    Array.Resize(ref parsedCommands, parsedCommands.Length + 1);
                    parsedCommands[parsedCommands.Length - 1]           = new commandData();
                    parsedCommands[parsedCommands.Length - 1].commandID = comStrings[a];
                    parsedCommands[parsedCommands.Length - 1].args      = new string[0];
                }
                else
                {
                    if (parsedCommands.Length != 0)
                    {
                        Array.Resize(ref parsedCommands[parsedCommands.Length - 1].args, parsedCommands[parsedCommands.Length - 1].args.Length + 1);
                        parsedCommands[parsedCommands.Length - 1].args[parsedCommands[parsedCommands.Length - 1].args.Length - 1] = comStrings[a];
                    }
                }
                isVar = false;
            }
            return(parsedCommands);
        }