コード例 #1
0
ファイル: Interpreter.cs プロジェクト: 41ross/sza
    public List <string> Interpret(string userInput)
    {
        //responce.Clear();

        string[] args = userInput.Split();


        commands = commandDB.GetCommands();

        if (commands.ContainsKey(args[0]))
        {
            List <string> res = commands[args[0]].GetActionStatus(args);

            if (res == null)
            {
                return(new List <string>()
                {
                    "Incorrect argument."
                });
            }

            return(res);
        }

        return(new List <string>()
        {
            "Command not found."
        });
    }
コード例 #2
0
ファイル: TerminalAutocomplete.cs プロジェクト: spock254/sza
    public void ValueChange()
    {
        commands = commandDB.GetCommands();

        string input = terminalController.terminalInput.text;

        string[] spletedInput = input.Split();

        KeyValuePair <string, ICommandAction>?commandKeyValue = null;

        CommandValidation(spletedInput, commands);

        if (input == string.Empty)
        {
            foreach (var hint in hintLines)
            {
                hint.text = string.Empty;
            }

            return;
        }

        SetHints(new List <string>(commands.Keys), input);


        foreach (var command in commands)
        {
            if (command.Key == spletedInput[0])
            {
                commandKeyValue = command;
                Dictionary <string, string> param = command.Value.GetFlagDescription();

                if (param == null)
                {
                    return;
                }

                List <string> flags = new List <string>(param.Keys);

                if (spletedInput.Length == 2)
                {
                    SetHints(flags, spletedInput[1], spletedInput[0].Length + 1);
                    //return;
                }
            }
        }

        if (spletedInput.Length == 3 && commandKeyValue != null)
        {
            var    param = commandKeyValue.Value.Value.GetParams();
            string flag  = spletedInput[1];
            string arg   = spletedInput[2];

            if (param != null && param.Keys.Contains(flag))
            {
                SetHints(param[flag], arg, spletedInput[0].Length + 1 + spletedInput[1].Length + 1);
            }
        }
    }
コード例 #3
0
ファイル: CommandDB.cs プロジェクト: 41ross/sza
        public List <string> GetActionStatus(string[] param)
        {
            CommandDB commandDB = Global.UIElement.GetTerminalWindow().GetComponent <CommandDB>();


            if (param.Length == 2)
            {
                if (param[1] == "-all")
                {
                    List <string> responce = new List <string>();

                    foreach (KeyValuePair <string, ICommandAction> entry in commandDB.GetCommands())
                    {
                        responce.Add(entry.Key + " - " + entry.Value.GetDescription());

                        if (entry.Value.GetParams() != null)
                        {
                            List <string> flags = new List <string>(entry.Value.GetParams().Keys);
                            responce.Add(entry.Key + " ( " + string.Join(", ", flags) + " )");

                            foreach (KeyValuePair <string, string> flagData in entry.Value.GetParams())
                            {
                                responce.Add(flagData.Key + " " + flagData.Value);
                            }
                        }

                        responce.Add("");
                    }

                    return(responce);
                }
                else if (param[1] == "-f")
                {
                    List <string> responce = new List <string>();

                    foreach (KeyValuePair <string, ICommandAction> entry in commandDB.GetCommands())
                    {
                        if (entry.Value.GetParams() != null)
                        {
                            List <string> flags = new List <string>(entry.Value.GetParams().Keys);
                            responce.Add(entry.Key + " ( " + string.Join(", ", flags) + " )");
                        }
                        else
                        {
                            responce.Add(entry.Key + "( No flags )");
                        }

                        responce.Add("");
                    }

                    return(responce);
                }
            }
            else if (param.Length == 1)
            {
                return(new List <string>(commandDB.GetCommands().Keys));
            }
            else if (param.Length == 3)
            {
                if (param[1] == "-s")
                {
                    CommandDB commandDb = Global.Component.GetCommandDB();

                    Dictionary <string, ICommandAction> commands = commandDb.GetCommands();

                    if (commands.ContainsKey(param[2]))
                    {
                        return(new List <string>()
                        {
                            param[2] + ": " + commands[param[2]].GetDescription()
                        });
                    }
                    else
                    {
                        return(new List <string> {
                            "Command not found"
                        });
                    }
                }

                if (param[1] == "-sf")
                {
                    CommandDB commandDb = Global.Component.GetCommandDB();

                    Dictionary <string, ICommandAction> commands = commandDb.GetCommands();

                    if (commands.ContainsKey(param[2]))
                    {
                        List <string> resp = new List <string>()
                        {
                            param[2] + ": " + commands[param[2]].GetDescription()
                        };

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

                        foreach (var item in commands[param[2]].GetParams())
                        {
                            temp.Add(item.Key + " " + item.Value);
                        }

                        resp.AddRange(temp);

                        return(resp);
                    }
                    else
                    {
                        return(new List <string> {
                            "Command not found"
                        });
                    }
                }
            }

            return(null);
        }