diff --git a/Source/Game/Cabrito/CommonCommands.cs b/Source/Game/Cabrito/CommonCommands.cs new file mode 100644 index 0000000..f74d70a --- /dev/null +++ b/Source/Game/Cabrito/CommonCommands.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Cabrito +{ + // Holds common miscellaneous Console variables and commands + public static class CommonCommands + { + [ConsoleCommand("")] + public static void NullCommand() + { + } + + [ConsoleCommand("echo")] + public static void EchoCommand() + { + Console.Print("nothing"); + } + + [ConsoleCommand("echo")] + public static void EchoCommand(string[] text) + { + Console.Print(string.Join(" ", text)); + } + + [ConsoleCommand("debugthrow")] + public static void DebugThrowCommand(string[] text) + { + throw new Exception(string.Join(" ", text)); + } + + [ConsoleVariable("developer")] + public static string Developer + { + get + { + return Console.DebugVerbosity.ToString(); + } + set + { + if (int.TryParse(value, out int intValue) && intValue >= 0) + Console.DebugVerbosity = intValue; + } + } + } +} \ No newline at end of file diff --git a/Source/Game/Cabrito/Console/Console.cs b/Source/Game/Cabrito/Console/Console.cs index b7f5ac4..88b0e94 100644 --- a/Source/Game/Cabrito/Console/Console.cs +++ b/Source/Game/Cabrito/Console/Console.cs @@ -29,6 +29,7 @@ namespace Cabrito { Destroy(); instance = new ConsoleInstance(); + instance.InitConsoleSubsystems(); } public static void Destroy() @@ -69,6 +70,12 @@ namespace Cabrito } public static bool ShowExecutedLines => instance.ShowExecutedLines; + public static int DebugVerbosity + { + get => instance.DebugVerbosity; + set => instance.DebugVerbosity = value; + } + public static string LinePrefix => instance.LinePrefix; public static IReadOnlyCollection Lines => instance.Lines; @@ -83,7 +90,10 @@ namespace Cabrito public static void PrintError(string text) => instance.PrintError(text); // Echoes developer/debug text to Console - public static void PrintDebug(string text) => instance.PrintDebug(text); + public static void PrintDebug(string text) => instance.PrintDebug(1, text); + + // Echoes developer/debug text to Console + public static void PrintDebug(int verbosity, string text) => instance.PrintDebug(verbosity, text); // Opens the Console public static void Open() => instance.Open(); @@ -115,6 +125,7 @@ namespace Cabrito public Action OnPrint; public bool ShowExecutedLines = true; + public int DebugVerbosity { get; set; } = 1; public string LinePrefix { get; internal set; } = "]"; //private static List consoleLines = new List(); @@ -122,8 +133,12 @@ namespace Cabrito private Dictionary consoleCommands = new Dictionary(); private Dictionary consoleVariables = new Dictionary(); + internal ConsoleInstance() + { + } + // Initializes the Console system. - public ConsoleInstance() + internal void InitConsoleSubsystems() { AppDomain currentDomain = AppDomain.CurrentDomain; Assembly[] assemblies = currentDomain.GetAssemblies(); @@ -149,6 +164,7 @@ namespace Cabrito { Dictionary cmdParsed = new Dictionary(); Dictionary> cmdMethods = new Dictionary>(); + MethodInfo cmdInitializer = null; foreach (MethodInfo method in type.GetMethods()) { @@ -192,6 +208,10 @@ namespace Cabrito aliasMethods.Add(method); } } + else if (attr is ConsoleSubsystemInitializer) + { + cmdInitializer = method; + } } } @@ -249,6 +269,12 @@ namespace Cabrito } } } + + if (cmdInitializer != null) + { + Console.PrintDebug(2, "Initializing " + type.Name); + cmdInitializer.Invoke(null, null); + } } } } @@ -265,7 +291,7 @@ namespace Cabrito // Echoes text to Console public void Print(string text) { - foreach (var line in text.Split(new []{'\n'})) + foreach (var line in text.Split(new[] { '\n' })) { ConsoleLine lineEntry = new ConsoleLine(line); consoleLines.Add(lineEntry); @@ -301,8 +327,11 @@ namespace Cabrito } // Echoes developer/debug text to Console - public void PrintDebug(string text) + public void PrintDebug(int verbosity, string text) { + if (DebugVerbosity < verbosity) + return; + foreach (var line in text.Split(new[] { '\n' })) { ConsoleLine lineEntry = new ConsoleLine(line); diff --git a/Source/Game/Cabrito/Console/ConsoleAttributes.cs b/Source/Game/Cabrito/Console/ConsoleAttributes.cs index 8b3fd01..c7516ea 100644 --- a/Source/Game/Cabrito/Console/ConsoleAttributes.cs +++ b/Source/Game/Cabrito/Console/ConsoleAttributes.cs @@ -56,4 +56,13 @@ namespace Cabrito { } } + + /// + /// Constructor for the subsystem, must be called first before registering console commands. + /// + [AttributeUsage(AttributeTargets.All)] + public class ConsoleSubsystemInitializer : Attribute + { + + } } \ No newline at end of file diff --git a/Source/Game/Cabrito/Console/ConsolePlugin.cs b/Source/Game/Cabrito/Console/ConsolePlugin.cs index 4041521..60646ba 100644 --- a/Source/Game/Cabrito/Console/ConsolePlugin.cs +++ b/Source/Game/Cabrito/Console/ConsolePlugin.cs @@ -11,8 +11,6 @@ namespace Game { Console.Init(); base.Initialize(); - - Console.Print("ConsolePlugin initialize"); } public override void Deinitialize() diff --git a/Source/Game/Cabrito/Console/ConsoleScript.cs b/Source/Game/Cabrito/Console/ConsoleScript.cs index c2ecf04..7a073f5 100644 --- a/Source/Game/Cabrito/Console/ConsoleScript.cs +++ b/Source/Game/Cabrito/Console/ConsoleScript.cs @@ -33,7 +33,6 @@ namespace Cabrito public override void OnStart() { - Console.Print("ConsoleScript OnStart"); consoleInputEvent = new InputEvent("Console"); consoleInputEvent.Triggered += OnConsoleInputEvent; diff --git a/Source/Game/Cabrito/SystemCommands.cs b/Source/Game/Cabrito/EngineSubsystem.cs similarity index 81% rename from Source/Game/Cabrito/SystemCommands.cs rename to Source/Game/Cabrito/EngineSubsystem.cs index d736dfb..4b58df4 100644 --- a/Source/Game/Cabrito/SystemCommands.cs +++ b/Source/Game/Cabrito/EngineSubsystem.cs @@ -7,12 +7,13 @@ using FlaxEngine; namespace Cabrito { - // Holds Consol§e variables and commands to control engine behaviour and other common - public static class SystemCommands + // Holds Console variables and commands to control engine behaviour + public static class EngineSubsystem { - [ConsoleCommand("")] - public static void NullCommand() + [ConsoleSubsystemInitializer] + public static void Initialize() { + Console.Print("Renderer: " + GPUDevice.Instance.RendererType); } [ConsoleCommand("quit", "exit")] @@ -21,30 +22,12 @@ namespace Cabrito Engine.RequestExit(); } - [ConsoleCommand("echo")] - public static void EchoCommand() - { - Console.Print("nothing"); - } - - [ConsoleCommand("echo")] - public static void EchoCommand(string[] text) - { - Console.Print(string.Join(" ", text)); - } - [ConsoleCommand("debuglog")] public static void DebugLogCommand(string[] text) { Debug.Log(string.Join(" ", text)); } - [ConsoleCommand("debugthrow")] - public static void DebugThrowCommand(string[] text) - { - throw new Exception(string.Join(" ", text)); - } - // TODO: this should manually set all postprocessing values to 0 or disabled /*[ConsoleVariable("r_postprocessing")] public static string PostProcessing