Add IGameConfig (#1274)

This commit is contained in:
MidoriKami 2023-06-24 21:03:25 -07:00 committed by GitHub
parent 6792fb4de5
commit 7ab20e9125
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 282 additions and 188 deletions

View file

@ -1,7 +1,6 @@
using System.Diagnostics;
using Dalamud.IoC;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services;
using Serilog;
namespace Dalamud.Game.Config;
@ -12,14 +11,17 @@ namespace Dalamud.Game.Config;
[InterfaceVersion("1.0")]
[PluginInterface]
[ServiceManager.EarlyLoadedService]
public sealed class GameConfig : IServiceType
#pragma warning disable SA1015
[ResolveVia<IGameConfig>]
#pragma warning restore SA1015
public sealed class GameConfig : IServiceType, IGameConfig
{
[ServiceManager.ServiceConstructor]
private unsafe GameConfig(Framework framework)
{
framework.RunOnTick(() =>
{
Log.Verbose("[GameConfig] Initalizing");
Log.Verbose("[GameConfig] Initializing");
var csFramework = FFXIVClientStructs.FFXIV.Client.System.Framework.Framework.Instance();
var commonConfig = &csFramework->SystemConfig.CommonSystemConfig;
this.System = new GameConfigSection("System", framework, &commonConfig->ConfigBase);
@ -28,234 +30,84 @@ public sealed class GameConfig : IServiceType
});
}
/// <summary>
/// Gets the collection of config options that persist between characters.
/// </summary>
/// <inheritdoc/>
public GameConfigSection System { get; private set; }
/// <summary>
/// Gets the collection of config options that are character specific.
/// </summary>
/// <inheritdoc/>
public GameConfigSection UiConfig { get; private set; }
/// <summary>
/// Gets the collection of config options that are control mode specific. (Mouse and Keyboard / Gamepad).
/// </summary>
/// <inheritdoc/>
public GameConfigSection UiControl { get; private set; }
/// <summary>
/// Attempts to get a boolean config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out bool value) => this.System.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a uint config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out uint value) => this.System.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a float config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out float value) => this.System.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a string config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(SystemConfigOption option, out string value) => this.System.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a boolean config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiConfigOption option, out bool value) => this.UiConfig.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a uint config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiConfigOption option, out uint value) => this.UiConfig.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a float config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiConfigOption option, out float value) => this.UiConfig.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a string config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiConfigOption option, out string value) => this.UiControl.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a boolean config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiControlOption option, out bool value) => this.UiControl.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a uint config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiControlOption option, out uint value) => this.UiControl.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a float config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiControlOption option, out float value) => this.UiControl.TryGet(option.GetName(), out value);
/// <summary>
/// Attempts to get a string config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
/// <inheritdoc/>
public bool TryGet(UiControlOption option, out string value) => this.System.TryGet(option.GetName(), out value);
/// <summary>
/// Set a boolean config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(SystemConfigOption option, bool value) => this.System.Set(option.GetName(), value);
/// <summary>
/// Set a unsigned integer config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(SystemConfigOption option, uint value) => this.System.Set(option.GetName(), value);
/// <summary>
/// Set a float config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(SystemConfigOption option, float value) => this.System.Set(option.GetName(), value);
/// <summary>
/// Set a string config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(SystemConfigOption option, string value) => this.System.Set(option.GetName(), value);
/// <summary>
/// Set a boolean config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiConfigOption option, bool value) => this.UiConfig.Set(option.GetName(), value);
/// <summary>
/// Set a unsigned integer config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiConfigOption option, uint value) => this.UiConfig.Set(option.GetName(), value);
/// <summary>
/// Set a float config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiConfigOption option, float value) => this.UiConfig.Set(option.GetName(), value);
/// <summary>
/// Set a string config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiConfigOption option, string value) => this.UiConfig.Set(option.GetName(), value);
/// <summary>
/// Set a boolean config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiControlOption option, bool value) => this.UiControl.Set(option.GetName(), value);
/// <summary>
/// Set a uint config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiControlOption option, uint value) => this.UiControl.Set(option.GetName(), value);
/// <summary>
/// Set a float config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiControlOption option, float value) => this.UiControl.Set(option.GetName(), value);
/// <summary>
/// Set a string config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
/// <inheritdoc/>
public void Set(UiControlOption option, string value) => this.UiControl.Set(option.GetName(), value);
}

View file

@ -0,0 +1,242 @@
using System.Diagnostics;
using Dalamud.Game.Config;
namespace Dalamud.Plugin.Services;
/// <summary>
/// This class represents the game's configuration.
/// </summary>
public interface IGameConfig
{
/// <summary>
/// Gets the collection of config options that persist between characters.
/// </summary>
public GameConfigSection System { get; }
/// <summary>
/// Gets the collection of config options that are character specific.
/// </summary>
public GameConfigSection UiConfig { get; }
/// <summary>
/// Gets the collection of config options that are control mode specific. (Mouse and Keyboard / Gamepad).
/// </summary>
public GameConfigSection UiControl { get; }
/// <summary>
/// Attempts to get a boolean config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out bool value);
/// <summary>
/// Attempts to get a uint config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out uint value);
/// <summary>
/// Attempts to get a float config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out float value);
/// <summary>
/// Attempts to get a string config value from the System section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(SystemConfigOption option, out string value);
/// <summary>
/// Attempts to get a boolean config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out bool value);
/// <summary>
/// Attempts to get a uint config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out uint value);
/// <summary>
/// Attempts to get a float config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out float value);
/// <summary>
/// Attempts to get a string config value from the UiConfig section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiConfigOption option, out string value);
/// <summary>
/// Attempts to get a boolean config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out bool value);
/// <summary>
/// Attempts to get a uint config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out uint value);
/// <summary>
/// Attempts to get a float config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out float value);
/// <summary>
/// Attempts to get a string config value from the UiControl section.
/// </summary>
/// <param name="option">Option to get the value of.</param>
/// <param name="value">The returned value of the config option.</param>
/// <returns>A value representing the success.</returns>
public bool TryGet(UiControlOption option, out string value);
/// <summary>
/// Set a boolean config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(SystemConfigOption option, bool value);
/// <summary>
/// Set a unsigned integer config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(SystemConfigOption option, uint value);
/// <summary>
/// Set a float config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(SystemConfigOption option, float value);
/// <summary>
/// Set a string config option in the System config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(SystemConfigOption option, string value);
/// <summary>
/// Set a boolean config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiConfigOption option, bool value);
/// <summary>
/// Set a unsigned integer config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiConfigOption option, uint value);
/// <summary>
/// Set a float config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiConfigOption option, float value);
/// <summary>
/// Set a string config option in the UiConfig section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiConfigOption option, string value);
/// <summary>
/// Set a boolean config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiControlOption option, bool value);
/// <summary>
/// Set a uint config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiControlOption option, uint value);
/// <summary>
/// Set a float config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiControlOption option, float value);
/// <summary>
/// Set a string config option in the UiControl config section.
/// Note: Not all config options will be be immediately reflected in the game.
/// </summary>
/// <param name="option">Name of the config option.</param>
/// <param name="value">New value of the config option.</param>
/// <exception cref="ConfigOptionNotFoundException">Throw if the config option is not found.</exception>
/// <exception cref="UnreachableException">Thrown if the name of the config option is found, but the struct was not.</exception>
public void Set(UiControlOption option, string value);
}