From f6a4861a06030e57cfbfea56fefc5b9e699762eb Mon Sep 17 00:00:00 2001 From: alterNERDtive Date: Mon, 7 Dec 2020 16:29:07 +0100 Subject: [PATCH] alterNERDtive-base: added `config.dump` plugin context Dumps a list of all configuration options + their current value to the VoiceAttack log. Will also mention if they are set to the default. --- plugins/VoiceAttack-base/base.cs | 12 ++++++-- plugins/VoiceAttack-base/util.cs | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/plugins/VoiceAttack-base/base.cs b/plugins/VoiceAttack-base/base.cs index 92e8b26..728da08 100644 --- a/plugins/VoiceAttack-base/base.cs +++ b/plugins/VoiceAttack-base/base.cs @@ -46,6 +46,11 @@ namespace alterNERDtive | plugin contexts | \================*/ + private static void Context_Config_Dump(dynamic vaProxy) + { + Config.DumpConfig(); + } + private static void Context_Config_Setup(dynamic vaProxy) { Log.Debug("Loading default configuration …"); @@ -282,12 +287,15 @@ namespace alterNERDtive Context_Startup(vaProxy); break; // config - case "config.setup": - Context_Config_Setup(vaProxy); + case "config.dump": + Context_Config_Dump(vaProxy); break; case "config.getvariables": Context_Config_SetVariables(vaProxy); break; + case "config.setup": + Context_Config_Setup(vaProxy); + break; case "config.versionmigration": Context_Config_VersionMigration(vaProxy); break; diff --git a/plugins/VoiceAttack-base/util.cs b/plugins/VoiceAttack-base/util.cs index 0a50a6f..43b8f25 100644 --- a/plugins/VoiceAttack-base/util.cs +++ b/plugins/VoiceAttack-base/util.cs @@ -270,6 +270,58 @@ namespace alterNERDtive.util ApplyDefault(id, key); } } + + public void DumpConfig() + { + foreach (string id in Defaults.Keys) + { + DumpConfig(id); + } + } + public void DumpConfig(string id) + { + Log.Notice($"===== {id} configuration: ====="); + foreach (string name in Defaults[id].Keys) + { + DumpConfig(id, name); + } + } + public void DumpConfig(string id, string name) + { + Option option = Defaults[id][name]; + string variable = $"{id}.{option.Name}#"; + dynamic defaultValue = option.DefaultValue; + dynamic value; + if (defaultValue is bool) + { + value = VA.GetBoolean(variable); + } + else if (defaultValue is DateTime) + { + value = VA.GetDate(variable); + } + else if (defaultValue is decimal) + { + value = VA.GetDecimal(variable); + } + else if (defaultValue is int) + { + value = VA.GetInt(variable); + } + else if (defaultValue is short) + { + value = VA.GetSmallInt(variable); + } + else if (defaultValue is string) + { + value = VA.GetText(variable); + } + else + { + throw new InvalidDataException($"Invalid data type for option '{id}.{name}': '{defaultValue}'"); + } + Log.Notice($"{variable} = {value}{(value == defaultValue? " (default)" : "")}"); + } } public class PythonProxy