GameConfig - add methods to get properties

This commit is contained in:
Caraxi 2023-07-11 17:03:41 +09:30
parent c4f8a09530
commit 4befb44c90
4 changed files with 199 additions and 0 deletions

View file

@ -67,6 +67,15 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out string value) => this.System.TryGet(option.GetName(), out value); public bool TryGet(SystemConfigOption option, out string value) => this.System.TryGet(option.GetName(), out value);
/// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out UIntConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out FloatConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out StringConfigProperties? properties) => this.System.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGet(UiConfigOption option, out bool value) => this.UiConfig.TryGet(option.GetName(), out value); 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
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGet(UiConfigOption option, out string value) => this.UiConfig.TryGet(option.GetName(), out value); public bool TryGet(UiConfigOption option, out string value) => this.UiConfig.TryGet(option.GetName(), out value);
/// <inheritdoc/>
public bool TryGet(UiConfigOption option, out UIntConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/>
public bool TryGet(UiConfigOption option, out FloatConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/>
public bool TryGet(UiConfigOption option, out StringConfigProperties properties) => this.UiConfig.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGet(UiControlOption option, out bool value) => this.UiControl.TryGet(option.GetName(), out value); 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
/// <inheritdoc/> /// <inheritdoc/>
public bool TryGet(UiControlOption option, out string value) => this.UiControl.TryGet(option.GetName(), out value); public bool TryGet(UiControlOption option, out string value) => this.UiControl.TryGet(option.GetName(), out value);
/// <inheritdoc/>
public bool TryGet(UiControlOption option, out UIntConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/>
public bool TryGet(UiControlOption option, out FloatConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/>
public bool TryGet(UiControlOption option, out StringConfigProperties properties) => this.UiControl.TryGetProperties(option.GetName(), out properties);
/// <inheritdoc/> /// <inheritdoc/>
public void Set(SystemConfigOption option, bool value) => this.System.Set(option.GetName(), value); public void Set(SystemConfigOption option, bool value) => this.System.Set(option.GetName(), value);

View file

@ -389,6 +389,99 @@ public class GameConfigSection
}); });
} }
/// <summary>
/// Attempts to get the properties of a UInt option from the config section.
/// </summary>
/// <param name="name">Name of the option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
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;
}
/// <summary>
/// Attempts to get the properties of a Float option from the config section.
/// </summary>
/// <param name="name">Name of the option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
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;
}
/// <summary>
/// Attempts to get the properties of a String option from the config section.
/// </summary>
/// <param name="name">Name of the option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
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;
}
/// <summary> /// <summary>
/// Invokes a change event within the config section. /// Invokes a change event within the config section.
/// </summary> /// </summary>

View file

@ -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);

View file

@ -62,6 +62,30 @@ public interface IGameConfig
/// <param name="value">The returned value of the config option.</param> /// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns> /// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out string value); public bool TryGet(SystemConfigOption option, out string value);
/// <summary>
/// Attempts to get the properties of a UInt option from the System section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out UIntConfigProperties? properties);
/// <summary>
/// Attempts to get the properties of a Float option from the System section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out FloatConfigProperties? properties);
/// <summary>
/// Attempts to get the properties of a String option from the System section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Default Value</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out StringConfigProperties? properties);
/// <summary> /// <summary>
/// Attempts to get a boolean config value from the UiConfig section. /// Attempts to get a boolean config value from the UiConfig section.
@ -95,6 +119,30 @@ public interface IGameConfig
/// <returns>A value representing the success.</returns> /// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out string value); public bool TryGet(UiConfigOption option, out string value);
/// <summary>
/// Attempts to get the properties of a UInt option from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out UIntConfigProperties? properties);
/// <summary>
/// Attempts to get the properties of a Float option from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out FloatConfigProperties? properties);
/// <summary>
/// Attempts to get the properties of a String option from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Default Value</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out StringConfigProperties? properties);
/// <summary> /// <summary>
/// Attempts to get a boolean config value from the UiControl section. /// Attempts to get a boolean config value from the UiControl section.
/// </summary> /// </summary>
@ -127,6 +175,30 @@ public interface IGameConfig
/// <returns>A value representing the success.</returns> /// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out string value); public bool TryGet(UiControlOption option, out string value);
/// <summary>
/// Attempts to get the properties of a UInt option from the UiControl section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out UIntConfigProperties? properties);
/// <summary>
/// Attempts to get the properties of a Float option from the UiControl section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Minimum, Maximum, and Default values.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out FloatConfigProperties? properties);
/// <summary>
/// Attempts to get the properties of a String option from the UiControl section.
/// </summary>
/// <param name="option">Option to get the properties of.</param>
/// <param name="properties">Details of the option: Default Value</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out StringConfigProperties? properties);
/// <summary> /// <summary>
/// Set a boolean config option in the System config section. /// Set a boolean config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game. /// Note: Not all config options will be be immediately reflected in the game.