Example #1
0
        protected override void RefreshCommandSuggestions(List <CommandData> suggestedCommands)
        {
            if (m_FilterCommandData == null)
            {
                MethodInfo filterMethodInfo = this.GetType().GetMethod("CommandFilterChannel", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                m_FilterCommandData = new CommandData(filterMethodInfo, "filter");
                QuantumConsoleProcessor.TryAddCommand(m_FilterCommandData);
            }

            if (m_FilterMethod == null)
            {
                m_FilterMethod = this.GetType().GetMethod("CommandFilterChannelWildcard", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            }

            string[] channels = LogChannel.GetAllChannelIds();
            foreach (var channel in channels)
            {
                if (m_RegisteredFilterChannels.Contains(channel))
                {
                    continue;
                }

                m_RegisteredFilterChannels.Add(channel);
                QuantumConsoleProcessor.TryAddCommand(new CommandData(m_FilterMethod, $"filter {channel}"));
            }

            base.RefreshCommandSuggestions(suggestedCommands);
        }
Example #2
0
        public static void InvokeAutoExec()
        {
            var console = QFSW.QC.QuantumConsole.Instance ? QFSW.QC.QuantumConsole.Instance : Object.FindObjectOfType <QFSW.QC.QuantumConsole>();

            if (!console)
            {
                return;
            }
            InvokeMethod(console, "Initialize");
            QuantumConsoleProcessor.GenerateCommandTable(); // Ensures the command table is generated
            try {
                InvokeConfigStreamingAssets(AUTOEXEC_NAME);
            } catch (FileNotFoundException) {
                // Ignore
            } catch (DirectoryNotFoundException) {
                // Ignore
            }
            try {
                InvokeConfig(Path.Combine(Directory.GetParent(Application.dataPath).ToString(), AUTOEXEC_NAME));
            } catch (FileNotFoundException) {
                // Ignore
            } catch (DirectoryNotFoundException) {
                // Ignore
            }

            try {
                var customExecPath = CommandLineArguments.ReadArgValue("-ExecConfig");
                customExecPath = customExecPath.Replace("{StreamingAssets}", Application.streamingAssetsPath);
                customExecPath = customExecPath.Replace("{DataPath}", Application.dataPath);
                customExecPath = customExecPath.Replace("{Root}", Directory.GetParent(Application.dataPath).ToString());
                InvokeConfig(customExecPath);
            } catch (CommandLineArguments.CommandLineArgumentNotFoundException) {
                // Ignore
            } catch (Exception ex) {
                Debug.LogError(ex.ToString());
            }

            try {
                foreach (var command in CommandLineArguments.ReadArgValues("-Exec"))
                {
                    try {
                        QuantumConsoleProcessor.InvokeCommand(command.Trim('"'));
                    } catch (Exception ex) {
                        Debug.LogError(ex.ToString());
                    }
                }
            } catch (CommandLineArguments.CommandLineArgumentNotFoundException) {
                // Ignore
            } catch (Exception ex) {
                Debug.LogError(ex.ToString());
            }
        }
        private void StartCoroutineCommand(string coroutineCommand)
        {
            object coroutineReturn = QuantumConsoleProcessor.InvokeCommand(coroutineCommand);

            if (coroutineReturn is IEnumerator)
            {
                StartCoroutine(coroutineReturn as IEnumerator);
            }
            else
            {
                throw new ArgumentException($"{coroutineCommand} is not a coroutine");
            }
        }
 private void Update()
 {
     if (!_blocked)
     {
         foreach (Binding binding in _bindings)
         {
             if (Input.GetKeyDown(binding.Key))
             {
                 try
                 {
                     QuantumConsoleProcessor.InvokeCommand(binding.Command);
                 }
                 catch (System.Exception e) { Debug.LogException(e); }
             }
         }
     }
 }
Example #5
0
        public object Parse(string value, Type type, Func <string, Type, object> recursiveParser)
        {
            bool nullable = false;

            if (value.EndsWith("?"))
            {
                nullable = true;
                value    = value.Substring(0, value.Length - 1);
            }

            value = value.ReduceScope('{', '}');
            object result = QuantumConsoleProcessor.InvokeCommand(value);

            if (result is null)
            {
                if (nullable)
                {
                    if (type.IsClass)
                    {
                        return(result);
                    }
                    else
                    {
                        throw new ParserInputException($"Expression body {{{value}}} evaluated to null which is incompatible with the expected type '{type.GetDisplayName()}'.");
                    }
                }
                else
                {
                    throw new ParserInputException($"Expression body {{{value}}} evaluated to null. If this is intended, please use nullable expression bodies, {{expr}}?");
                }
            }
            else if (result.GetType().IsCastableTo(type, true))
            {
                return(type.Cast(result));
            }
            else
            {
                throw new ParserInputException($"Expression body {{{value}}} evaluated to an object of type '{result.GetType().GetDisplayName()}', " +
                                               $"which is incompatible with the expected type '{type.GetDisplayName()}'.");
            }
        }
Example #6
0
        public static string GetCommandList(bool forceReload)
        {
            QuantumConsoleProcessor.GenerateCommandTable(false, forceReload);
            var sb = new StringBuilder();

            foreach (var command in GetOrderedCommands())
            {
                // Name line
                sb.Append(command.CommandName);
                sb.Append(' ');
                sb.Append(command.IsStatic ? "[Static]" : "[Instance]");
                if (!command.IsStatic)
                {
                    sb.Append(' ');
                    sb.Append($"[{command.MonoTarget.ToString()}]");
                }
                sb.AppendLine();

                // Description Line
                if (command.HasDescription)
                {
                    sb.Append('\t');
                    sb.Append("description: ");
                    var desc = command.CommandDescription;
                    // If it's a multiline description put it on a new line
                    if (desc.Contains('\n'))
                    {
                        desc = desc.Insert(0, "\n");
                        // Tab any new lines to match the current indent
                        desc = desc.Replace("\n", $"\n\t\t");
                    }

                    sb.AppendLine(desc);
                }

                // Signature Line
                if (command.ParamCount > 0)
                {
                    sb.Append("\tsignature: ");
                    var paramNames = command.ParameterSignature.Split(' ');
                    var paramTypes = command.ParamTypes.Select(x => x.Name).ToArray();
                    for (var i = 0; i < paramNames.Length; i++)
                    {
                        sb.Append($"<{paramTypes[i]}> {paramNames[i]}");
                        if (i < paramNames.Length - 1)
                        {
                            sb.Append($", ");
                        }
                    }

                    sb.AppendLine();
                }

                // Return Line
                try {
                    if (command.MethodData.ReturnType != typeof(void))
                    {
                        sb.Append("\treturns: ");
                        sb.Append($"<{command.MethodData.ReturnType.Name}>");
                        sb.AppendLine();
                    }
                } catch (NotImplementedException) {
                    // Ignore
                }

                sb.AppendLine();
            }

            return(sb.ToString());
        }
Example #7
0
 public static IEnumerable <CommandData> GetOrderedCommands() => QuantumConsoleProcessor.GetAllCommands().OrderBy(x => x.CommandName).ThenBy(x => x.ParamCount);