From 4befb44c907f683c911b93df6141aade0354ea22 Mon Sep 17 00:00:00 2001 From: Caraxi Date: Tue, 11 Jul 2023 17:03:41 +0930 Subject: [PATCH] GameConfig - add methods to get properties --- Dalamud/Game/Config/GameConfig.cs | 27 +++++++ Dalamud/Game/Config/GameConfigSection.cs | 93 ++++++++++++++++++++++++ Dalamud/Game/Config/Properties.cs | 7 ++ Dalamud/Plugin/Services/IGameConfig.cs | 72 ++++++++++++++++++ 4 files changed, 199 insertions(+) create mode 100644 Dalamud/Game/Config/Properties.cs diff --git a/Dalamud/Game/Config/GameConfig.cs b/Dalamud/Game/Config/GameConfig.cs index db3163a19..dfdb8b5d2 100644 --- a/Dalamud/Game/Config/GameConfig.cs +++ b/Dalamud/Game/Config/GameConfig.cs @@ -67,6 +67,15 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable /// public bool TryGet(SystemConfigOption option, out string value) => this.System.TryGet(option.GetName(), out value); + /// + public bool TryGet(SystemConfigOption option, out UIntConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(SystemConfigOption option, out FloatConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(SystemConfigOption option, out StringConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties); + /// public bool TryGet(UiConfigOption option, out bool value) => this.UiConfig.TryGet(option.GetName(), out value); @@ -78,6 +87,15 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable /// public bool TryGet(UiConfigOption option, out string value) => this.UiConfig.TryGet(option.GetName(), out value); + + /// + public bool TryGet(UiConfigOption option, out UIntConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(UiConfigOption option, out FloatConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(UiConfigOption option, out StringConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties); /// public bool TryGet(UiControlOption option, out bool value) => this.UiControl.TryGet(option.GetName(), out value); @@ -90,7 +108,16 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable /// public bool TryGet(UiControlOption option, out string value) => this.UiControl.TryGet(option.GetName(), out value); + + /// + public bool TryGet(UiControlOption option, out UIntConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties); + /// + public bool TryGet(UiControlOption option, out FloatConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties); + + /// + public bool TryGet(UiControlOption option, out StringConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties); + /// public void Set(SystemConfigOption option, bool value) => this.System.Set(option.GetName(), value); diff --git a/Dalamud/Game/Config/GameConfigSection.cs b/Dalamud/Game/Config/GameConfigSection.cs index a3542ba3e..6c87ad3cf 100644 --- a/Dalamud/Game/Config/GameConfigSection.cs +++ b/Dalamud/Game/Config/GameConfigSection.cs @@ -389,6 +389,99 @@ public class GameConfigSection }); } + /// + /// Attempts to get the properties of a UInt option from the config section. + /// + /// Name of the option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public unsafe bool TryGetProperties(string name, out UIntConfigProperties? properties) + { + if (!this.TryGetIndex(name, out var index)) + { + properties = null; + return false; + } + + if (!this.TryGetEntry(index, out var entry)) + { + properties = null; + return false; + } + + if ((ConfigType)entry->Type != ConfigType.UInt) + { + properties = null; + return false; + } + + var prop = &entry->Properties.UInt; + properties = new UIntConfigProperties(prop->DefaultValue, prop->MinValue, prop->MaxValue); + return true; + } + + /// + /// Attempts to get the properties of a Float option from the config section. + /// + /// Name of the option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public unsafe bool TryGetProperties(string name, out FloatConfigProperties? properties) + { + if (!this.TryGetIndex(name, out var index)) + { + properties = null; + return false; + } + + if (!this.TryGetEntry(index, out var entry)) + { + properties = null; + return false; + } + + if ((ConfigType)entry->Type != ConfigType.Float) + { + properties = null; + return false; + } + + var prop = &entry->Properties.Float; + properties = new FloatConfigProperties(prop->DefaultValue, prop->MinValue, prop->MaxValue); + return true; + } + + /// + /// Attempts to get the properties of a String option from the config section. + /// + /// Name of the option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public unsafe bool TryGetProperties(string name, out StringConfigProperties? properties) + { + if (!this.TryGetIndex(name, out var index)) + { + properties = null; + return false; + } + + if (!this.TryGetEntry(index, out var entry)) + { + properties = null; + return false; + } + + if ((ConfigType)entry->Type != ConfigType.String) + { + properties = null; + return false; + } + + var prop = entry->Properties.String; + properties = new StringConfigProperties(prop.DefaultValue == null ? null : MemoryHelper.ReadSeString(prop.DefaultValue)); + return true; + } + /// /// Invokes a change event within the config section. /// diff --git a/Dalamud/Game/Config/Properties.cs b/Dalamud/Game/Config/Properties.cs new file mode 100644 index 000000000..b43a44a47 --- /dev/null +++ b/Dalamud/Game/Config/Properties.cs @@ -0,0 +1,7 @@ +using Dalamud.Game.Text.SeStringHandling; + +namespace Dalamud.Game.Config; + +public record StringConfigProperties(SeString? Default); +public record UIntConfigProperties(uint Default, uint Minimum, uint Maximum); +public record FloatConfigProperties(float Default, float Minimum, float Maximum); diff --git a/Dalamud/Plugin/Services/IGameConfig.cs b/Dalamud/Plugin/Services/IGameConfig.cs index f0607c39e..98f6160cc 100644 --- a/Dalamud/Plugin/Services/IGameConfig.cs +++ b/Dalamud/Plugin/Services/IGameConfig.cs @@ -62,6 +62,30 @@ public interface IGameConfig /// The returned value of the config option. /// A value representing the success. public bool TryGet(SystemConfigOption option, out string value); + + /// + /// Attempts to get the properties of a UInt option from the System section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out UIntConfigProperties? properties); + + /// + /// Attempts to get the properties of a Float option from the System section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out FloatConfigProperties? properties); + + /// + /// Attempts to get the properties of a String option from the System section. + /// + /// Option to get the properties of. + /// Details of the option: Default Value + /// A value representing the success. + public bool TryGet(SystemConfigOption option, out StringConfigProperties? properties); /// /// Attempts to get a boolean config value from the UiConfig section. @@ -95,6 +119,30 @@ public interface IGameConfig /// A value representing the success. public bool TryGet(UiConfigOption option, out string value); + /// + /// Attempts to get the properties of a UInt option from the UiConfig section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out UIntConfigProperties? properties); + + /// + /// Attempts to get the properties of a Float option from the UiConfig section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiConfigOption option, out FloatConfigProperties? properties); + + /// + /// Attempts to get the properties of a String option from the UiConfig section. + /// + /// Option to get the properties of. + /// Details of the option: Default Value + /// A value representing the success. + public bool TryGet(UiConfigOption option, out StringConfigProperties? properties); + /// /// Attempts to get a boolean config value from the UiControl section. /// @@ -127,6 +175,30 @@ public interface IGameConfig /// A value representing the success. public bool TryGet(UiControlOption option, out string value); + /// + /// Attempts to get the properties of a UInt option from the UiControl section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiControlOption option, out UIntConfigProperties? properties); + + /// + /// Attempts to get the properties of a Float option from the UiControl section. + /// + /// Option to get the properties of. + /// Details of the option: Minimum, Maximum, and Default values. + /// A value representing the success. + public bool TryGet(UiControlOption option, out FloatConfigProperties? properties); + + /// + /// Attempts to get the properties of a String option from the UiControl section. + /// + /// Option to get the properties of. + /// Details of the option: Default Value + /// A value representing the success. + public bool TryGet(UiControlOption option, out StringConfigProperties? properties); + /// /// Set a boolean config option in the System config section. /// Note: Not all config options will be be immediately reflected in the game.