Skip to content

Commit

Permalink
chore: cleanup ConfigFileExtensions
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Dec 28, 2024
1 parent bc53b34 commit 840bbc5
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions JotunnLib/Extensions/ConfigFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Jotunn.Extensions
{

/// <summary>
/// Extends ConfigFile with a convenience method to bind config entries with less boilerplate code
/// and explicitly expose commonly used configuration manager attributes.
Expand All @@ -12,7 +11,6 @@ public static class ConfigFileExtensions
{
internal static string GetExtendedDescription(string description, bool synchronizedSetting)
{
// these two hardcoded strings should probably be localized
return description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]");
}

Expand All @@ -23,9 +21,9 @@ internal static string GetExtendedDescription(string description, bool synchroni
/// <param name="configFile">Configuration file to bind the config entry to.</param>
/// <param name="section">Configuration file section to list the config entry in.</param>
/// <param name="name">Display name of the config entry.</param>
/// <param name="value">Default value of the config entry.</param>
/// <param name="defaultValue">Default value of the config entry.</param>
/// <param name="description">Plain text description of the config entry to display as hover text in configuration manager.</param>
/// <param name="acceptVals">Acceptable values for config entry as an AcceptableValueRange, AcceptableValueList, or custom subclass.</param>
/// <param name="acceptableValues">Acceptable values for config entry as an AcceptableValueRange, AcceptableValueList, or custom subclass.</param>
/// <param name="synced">Whether the config entry IsAdminOnly and should be synced with server.</param>
/// <param name="order">Order of the setting on the settings list relative to other settings in a category. 0 by default, higher number is higher on the list.</param>
/// <param name="drawer">Custom setting editor (OnGUI code that replaces the default editor provided by ConfigurationManager).</param>
Expand All @@ -35,9 +33,9 @@ public static ConfigEntry<T> BindConfig<T>(
this ConfigFile configFile,
string section,
string name,
T value,
T defaultValue,
string description,
AcceptableValueBase acceptVals = null,
AcceptableValueBase acceptableValues = null,
bool synced = true,
int order = 0,
Action<ConfigEntryBase> drawer = null,
Expand All @@ -46,9 +44,10 @@ public static ConfigEntry<T> BindConfig<T>(
{
string extendedDescription = GetExtendedDescription(description, synced);

configAttributes ??= new ConfigurationManagerAttributes();
configAttributes ??= new ConfigurationManagerAttributes();
configAttributes.IsAdminOnly = synced;
configAttributes.Order = order;

if (drawer != null)
{
configAttributes.CustomDrawer = drawer;
Expand All @@ -57,14 +56,14 @@ public static ConfigEntry<T> BindConfig<T>(
ConfigEntry<T> configEntry = configFile.Bind(
section,
name,
value,
defaultValue,
new ConfigDescription(
extendedDescription,
acceptVals,
acceptableValues,
configAttributes
)
);
return configEntry;
}
}
}
}

0 comments on commit 840bbc5

Please sign in to comment.