/// <summary>Executes the command.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">Entry to be executed.</param> public static void Execute(CommandQueue queue, CommandEntry entry) { string configName = entry.GetArgument(queue, 0).ToLowerFast(); AutoConfiguration config = queue.Engine.Context.GetConfig(configName); if (config is null) { queue.HandleError(entry, $"Invalid config name '{TextStyle.SeparateVal(configName)}' - are you sure you typed it correctly?"); return; } string configKey = entry.GetArgument(queue, 1); AutoConfiguration.Internal.SingleFieldData field = config.TryGetFieldInternalData(configKey, out AutoConfiguration section, true); if (field is null) { queue.HandleError(entry, $"Invalid config setting key '{TextStyle.SeparateVal(configKey)}' - are you sure you typed it correctly?"); return; } if (field.Field.FieldType != typeof(bool)) { queue.HandleError(entry, $"Invalid config setting key '{TextStyle.SeparateVal(configKey)}' - not a bool. Cannot be toggled."); return; } bool currentValue = (bool)field.GetValue(section); field.SetValue(section, !currentValue); field.OnChanged?.Invoke(); if (queue.ShouldShowGood()) { queue.GoodOutput($"For config '{TextStyle.SeparateVal(configName)}', toggled '{TextStyle.SeparateVal(configKey)}' to '{TextStyle.SeparateVal(!currentValue)}'"); } }
/// <summary>Executes the command.</summary> /// <param name="queue">The command queue involved.</param> /// <param name="entry">Entry to be executed.</param> public static void Execute(CommandQueue queue, CommandEntry entry) { string configName = entry.GetArgument(queue, 0).ToLowerFast(); AutoConfiguration config = queue.Engine.Context.GetConfig(configName); if (config is null) { queue.HandleError(entry, $"Invalid config name '{TextStyle.SeparateVal(configName)}' - are you sure you typed it correctly?"); return; } string configKey = entry.GetArgument(queue, 1); AutoConfiguration.Internal.SingleFieldData field = config.TryGetFieldInternalData(configKey, out AutoConfiguration section, true); if (field is null) { queue.HandleError(entry, $"Invalid config setting key '{TextStyle.SeparateVal(configKey)}' - are you sure you typed it correctly?"); return; } TemplateObject newValue = entry.GetArgumentObject(queue, 2); object rawValue = ConvertForType(field.Field.FieldType, newValue, queue); field.SetValue(section, rawValue); field.OnChanged?.Invoke(); if (queue.ShouldShowGood()) { queue.GoodOutput($"For config '{TextStyle.SeparateVal(configName)}', set '{TextStyle.SeparateVal(configKey)}' to '{TextStyle.SeparateVal(rawValue)}'"); } }