From 2d5c4ed7dc9bf99abdc245a55d6fdeb2512ab9dc Mon Sep 17 00:00:00 2001 From: goat Date: Sun, 9 Jun 2024 21:32:23 +0200 Subject: [PATCH] console: print variable contents, flip bools, print command on enter --- Dalamud/Console/ConsoleManager.cs | 26 ++++++++++++++----- .../Internal/Windows/ConsoleWindow.cs | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Dalamud/Console/ConsoleManager.cs b/Dalamud/Console/ConsoleManager.cs index 6600069c2..4112cde2a 100644 --- a/Dalamud/Console/ConsoleManager.cs +++ b/Dalamud/Console/ConsoleManager.cs @@ -270,7 +270,9 @@ internal partial class ConsoleManager : IServiceType for (var i = parsedArguments.Count; i < entry.ValidArguments.Count; i++) { var argument = entry.ValidArguments[i]; - if (argument.DefaultValue == null) + + // If the default value is DBNull, we need to error out as that means it was not specified + if (argument.DefaultValue == DBNull.Value) { Log.Error("Not enough arguments for command {CommandName}", entryName); PrintUsage(entry); @@ -382,11 +384,8 @@ internal partial class ConsoleManager : IServiceType /// The default value to use if none is specified. /// An instance. /// Thrown if the given type cannot be handled by the console system. - protected static ArgumentInfo TypeToArgument(Type type, object? defaultValue = null) + protected static ArgumentInfo TypeToArgument(Type type, object? defaultValue) { - // If the default value is DBNull, we want to treat it as null - defaultValue = defaultValue == DBNull.Value ? null : defaultValue; - if (type == typeof(string)) return new ArgumentInfo(ConsoleArgumentType.String, defaultValue); @@ -490,7 +489,7 @@ internal partial class ConsoleManager : IServiceType public ConsoleVariable(string name, string description) : base(name, description) { - this.ValidArguments = new List { TypeToArgument(typeof(T)) }; + this.ValidArguments = new List { TypeToArgument(typeof(T), null) }; } /// @@ -500,7 +499,20 @@ internal partial class ConsoleManager : IServiceType public override bool Invoke(IEnumerable arguments) { var first = arguments.FirstOrDefault(); - if (first == null || first.GetType() != typeof(T)) + + if (first == null) + { + // Invert the value if it's a boolean + if (this.Value is bool boolValue) + { + this.Value = (T)(object)!boolValue; + } + + Log.WriteLog(LogEventLevel.Information, "{VariableName} = {VariableValue}", null, this.Name, this.Value); + return true; + } + + if (first.GetType() != typeof(T)) throw new ArgumentException($"Console variable must be set with an argument of type {typeof(T).Name}."); this.Value = (T)first; diff --git a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs index e6d7abd9c..85c7a7380 100644 --- a/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ConsoleWindow.cs @@ -321,6 +321,7 @@ internal class ConsoleWindow : Window, IDisposable ImGuiInputTextFlags.CallbackHistory | ImGuiInputTextFlags.CallbackEdit, this.CommandInputCallback)) { + this.newLogEntries.Enqueue((this.commandText, new LogEvent(DateTimeOffset.Now, LogEventLevel.Information, null, new MessageTemplate(string.Empty, []), []))); this.ProcessCommand(); getFocus = true; }