From fcde6dc2a87aa18347beeabf9870ec5c377c4efe Mon Sep 17 00:00:00 2001 From: Arne Kiesewetter Date: Fri, 20 Dec 2024 22:30:49 +0100 Subject: [PATCH] Move share component creation to method --- .../UI/DefaultInspectorHeaderConfig.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/MonkeyLoader.Resonite.Integration/UI/DefaultInspectorHeaderConfig.cs b/MonkeyLoader.Resonite.Integration/UI/DefaultInspectorHeaderConfig.cs index 53b0a67..6271d16 100644 --- a/MonkeyLoader.Resonite.Integration/UI/DefaultInspectorHeaderConfig.cs +++ b/MonkeyLoader.Resonite.Integration/UI/DefaultInspectorHeaderConfig.cs @@ -14,29 +14,29 @@ public sealed class DefaultInspectorHeaderConfig : SingletonConfigSection _destroyOffset = new("DestroyOffset", "The Order Offset of the Destroy button on Inspector Headers. Range: 0-16 - Higher is further right.", () => 12) { OffsetRange, - new ConfigKeySessionShare(IntToLong, LongToInt, 12) + MakeOffsetRangeShare(12) }; private readonly DefiningConfigKey _duplicateOffset = new("DuplicateOffset", "The Order Offset of the Duplicate button on Inspector Headers. Range: 0-16 - Higher is further right.", () => 11) { OffsetRange, - new ConfigKeySessionShare(IntToLong, LongToInt, 11) + MakeOffsetRangeShare(11) }; private readonly DefiningConfigKey _openContainerOffset = new("OpenContainerOffset", "The Order Offset of the Open Container button on Inspector Headers. Range: 0-16 - Higher is further right.", () => 4) { OffsetRange, - new ConfigKeySessionShare(IntToLong, LongToInt, 10) + MakeOffsetRangeShare(10) }; private readonly DefiningConfigKey _workerNameOffset = new("NameOffset", "The Order Offset of the Worker Name button on Inspector Headers. Range: 0-16 - Higher is further right.", () => 6) { OffsetRange, - new ConfigKeySessionShare(IntToLong, LongToInt, 6) + MakeOffsetRangeShare(6) }; /// - /// Gets the range component used for header items. + /// Gets the range component used for the offset of header items. /// public static ConfigKeyRange OffsetRange { get; } = new ConfigKeyRange(0, 16); @@ -69,6 +69,15 @@ public sealed class DefaultInspectorHeaderConfig : SingletonConfigSection public ConfigKeySessionShare WorkerNameOffset => _workerNameOffset.Components.Get>(); + /// + /// Makes a new session share component used for the offset of + /// header items, optionally using the given default. + /// + /// The default value for the shared config item for users that don't have it themselves. + /// The newly created share component with the optional default. + public static ConfigKeySessionShare MakeOffsetRangeShare(int defaultValue = default) + => new(IntToLong, LongToInt, defaultValue); + private static long IntToLong(int value) => value; private static int LongToInt(long value) => (int)value;