Added ConfigName property to IModdedOptionList to optionally rename the individual options

This commit is contained in:
David Higueros committed 2026-09-25 12:43:14 -06:00
1 parent ffe9194d54
commit 1b587547f7
3 files changed
+12 -1

No files matched your search

+6
View File
@@ -121,6 +121,12 @@ public interface IModdedOption
/// </summary>
public interface IModdedOptionList : IReadOnlyList<IModdedOption>
{
/// <summary>
/// Gets the function to name the keys of the individual options in the configuration file.
/// <para/>
/// Return <see langword="null"/> to use the default of the property's name with its index appended.
/// </summary>
Func<int, string>? ConfigName { get; init; }
}
/// <summary>
+3 -1
View File
@@ -198,9 +198,11 @@ public static class ModdedOptionsManager
return;
}
Func<int, string> configName = optionList.ConfigName ?? (i => property.Name + i);
for (int i = 0; i < optionList.Count; i++)
{
RegisterOption(optionList[i], group, property.Name + i, pluginInfo);
RegisterOption(optionList[i], group, configName(i), pluginInfo);
}
}
@@ -20,6 +20,9 @@ public class ModdedOptionList<T> : IModdedOptionList
/// </summary>
public IReadOnlyList<T> Options { get; }
/// <inheritdoc/>
public Func<int, string>? ConfigName { get; init; }
/// <summary>
/// Initializes a new instance of the <see cref="ModdedOptionList{T}"/> class.
/// </summary>