/// <summary> /// Unregisters a console command to the console. /// </summary> /// <param name="command">Command to unregister.</param> public static void DeregisterCommand(ConsoleCommand command) { _commands.Remove(command); }
/// <summary> /// Registers a console command to the console. /// </summary> /// <param name="command">Command to register.</param> public static void RegisterCommand(ConsoleCommand command) { _commands.Add(command); }
/// <summary> /// Initializes a new instance of thsi class. /// </summary> /// <param name="symbol">Function symbol describing the function to call.</param> /// <param name="thread">Script thread that function is embedded in.</param> public ScriptConsoleCommand(FunctionSymbol symbol, ScriptThread thread) { _thread = thread; _functionSymbol = symbol; ConsoleValueType[] parameters = new ConsoleValueType[symbol.ParameterCount]; for (int i = 0; i < parameters.Length; i++) { switch (((VariableSymbol)symbol.Symbols[i]).DataType.DataType) { case DataType.Bool: parameters[i] = ConsoleValueType.Bool; break; case DataType.Float: parameters[i] = ConsoleValueType.Float; break; case DataType.Int: parameters[i] = ConsoleValueType.Int; break; case DataType.String: parameters[i] = ConsoleValueType.String; break; } } _command = new ConsoleCommand(symbol.Identifier, new CommandDelegate(InvokeCommand), parameters); Console.Console.RegisterCommand(_command); }
/// <summary> /// Parses through this class to find any methods that can be used as console commands. /// </summary> public void PrepareSet() { if (_prepared == true) return; _prepared = true; _globalCommandSets.Add(this); Type type = this.GetType(); MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); foreach (MethodInfo method in methods) { // Go through attributes until we find a NativeFunctionInfo attribute // if we don't find one then ignore this function. ConsoleCommandInfo infoAttribute = method.GetCustomAttributes(typeof(ConsoleCommandInfo), true)[0] as ConsoleCommandInfo; if (infoAttribute == null) continue; // Create a native function delegate for this method. ConsoleCommand command = new ConsoleCommand(infoAttribute.Identifier, (CommandDelegate)CommandDelegate.CreateDelegate(typeof(CommandDelegate), this, method), infoAttribute.ParameterTypes); _consoleCommands.Add(command); } #endregion }