mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 12:23:39 +01:00
Merge pull request #1307 from Caraxi/gameConfigImprovements
`GameConfig` Improvements
This commit is contained in:
commit
c453c63796
4 changed files with 206 additions and 9 deletions
|
|
@ -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);
|
||||||
|
|
||||||
|
|
@ -77,7 +86,16 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable
|
||||||
public bool TryGet(UiConfigOption option, out float value) => this.UiConfig.TryGet(option.GetName(), out value);
|
public bool TryGet(UiConfigOption option, out float value) => this.UiConfig.TryGet(option.GetName(), out value);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool TryGet(UiConfigOption option, out string value) => this.UiControl.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);
|
||||||
|
|
@ -89,7 +107,16 @@ public sealed class GameConfig : IServiceType, IGameConfig, IDisposable
|
||||||
public bool TryGet(UiControlOption option, out float value) => this.UiControl.TryGet(option.GetName(), out value);
|
public bool TryGet(UiControlOption option, out float value) => this.UiControl.TryGet(option.GetName(), out value);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public bool TryGet(UiControlOption option, out string value) => this.System.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);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using Dalamud.Memory;
|
using Dalamud.Memory;
|
||||||
|
|
@ -15,9 +15,8 @@ namespace Dalamud.Game.Config;
|
||||||
public class GameConfigSection
|
public class GameConfigSection
|
||||||
{
|
{
|
||||||
private readonly Framework framework;
|
private readonly Framework framework;
|
||||||
private readonly Dictionary<string, uint> indexMap = new();
|
private readonly ConcurrentDictionary<string, uint> indexMap = new();
|
||||||
private readonly Dictionary<uint, string> nameMap = new();
|
private readonly ConcurrentDictionary<uint, object> enumMap = new();
|
||||||
private readonly Dictionary<uint, object> enumMap = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event which is fired when a game config option is changed within the section.
|
/// Event which is fired when a game config option is changed within the section.
|
||||||
|
|
@ -390,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>
|
||||||
|
|
@ -404,12 +496,12 @@ public class GameConfigSection
|
||||||
var name = MemoryHelper.ReadStringNullTerminated(new IntPtr(entry->Name));
|
var name = MemoryHelper.ReadStringNullTerminated(new IntPtr(entry->Name));
|
||||||
if (Enum.TryParse(typeof(TEnum), name, out enumObject))
|
if (Enum.TryParse(typeof(TEnum), name, out enumObject))
|
||||||
{
|
{
|
||||||
this.enumMap.Add(entry->Index, enumObject);
|
this.enumMap.TryAdd(entry->Index, enumObject);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
enumObject = null;
|
enumObject = null;
|
||||||
this.enumMap.Add(entry->Index, null);
|
this.enumMap.TryAdd(entry->Index, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -439,7 +531,6 @@ public class GameConfigSection
|
||||||
if (eName.Equals(name))
|
if (eName.Equals(name))
|
||||||
{
|
{
|
||||||
this.indexMap.TryAdd(name, i);
|
this.indexMap.TryAdd(name, i);
|
||||||
this.nameMap.TryAdd(i, name);
|
|
||||||
index = i;
|
index = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
Dalamud/Game/Config/Properties.cs
Normal file
7
Dalamud/Game/Config/Properties.cs
Normal 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);
|
||||||
|
|
@ -63,6 +63,30 @@ public interface IGameConfig
|
||||||
/// <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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue