From dad3b75581e1d49a9e7f5c1468d9dff8aef73fba Mon Sep 17 00:00:00 2001 From: Nytra <14206961+Nytra@users.noreply.github.com> Date: Tue, 24 Dec 2024 03:56:41 +0000 Subject: [PATCH] Fix standalone facet nullables --- .../DataFeeds/Settings/ModSettingStandaloneFacet.cs | 4 ++-- MonkeyLoader.Resonite.Integration/FieldExtensions.cs | 4 ++-- .../UI/Tooltips/TooltipConfig.cs | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ModSettingStandaloneFacet.cs b/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ModSettingStandaloneFacet.cs index 9c714a6..2c2037f 100644 --- a/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ModSettingStandaloneFacet.cs +++ b/MonkeyLoader.Resonite.Integration/DataFeeds/Settings/ModSettingStandaloneFacet.cs @@ -92,9 +92,9 @@ internal sealed class ModSettingStandaloneFacet : ResoniteMonkey(IField field, IDefiningConfigKey key, string? eventLabel) where T : unmanaged + private static void SyncWithConfigKeyWrapper(IField field, IDefiningConfigKey key, string? eventLabel) { - if (typeof(T) == typeof(bool) && key.ValueType.IsNullable()) + if (typeof(T) == typeof(bool) && key.ValueType.IsNullable() && key.ValueType.GetGenericArguments()[0].IsEnum) { //((IField)field).SyncWithNullableConfigKeyHasValue((IDefiningConfigKey)key, eventLabel); var type = key.ValueType.GetGenericArguments()[0]; diff --git a/MonkeyLoader.Resonite.Integration/FieldExtensions.cs b/MonkeyLoader.Resonite.Integration/FieldExtensions.cs index 50d96a5..1e93812 100644 --- a/MonkeyLoader.Resonite.Integration/FieldExtensions.cs +++ b/MonkeyLoader.Resonite.Integration/FieldExtensions.cs @@ -121,7 +121,7 @@ void ConfigKeyChangedHandler(object sender, IConfigKeyChangedEventArgs args) /// public static Action SyncWithNullableConfigKeyHasValue(this IField field, IDefiningConfigKey configKey, string? eventLabel = null, bool allowWriteBack = true) - where T : unmanaged + where T : struct { configKey.FindNearestParent().Logger.Info(() => $"Syncing with nullable config key: {configKey.Id}"); @@ -144,7 +144,7 @@ void FieldChangedHandler(IChangeable _) { configKey.FindNearestParent().Logger.Info(() => $"Field changed: {configKey.Id} {field.Value} {configKey.GetValue().HasValue} {allowWriteBack}"); - T? newValue = field.Value ? default : null; + T? newValue = field.Value ? default(T) : null; if (field.Value != configKey.GetValue().HasValue && (!allowWriteBack || !configKey.TrySetValue(newValue, eventLabel))) field.World.RunSynchronously(() => field.Value = configKey.GetValue().HasValue); diff --git a/MonkeyLoader.Resonite.Integration/UI/Tooltips/TooltipConfig.cs b/MonkeyLoader.Resonite.Integration/UI/Tooltips/TooltipConfig.cs index d010a59..b8dee13 100644 --- a/MonkeyLoader.Resonite.Integration/UI/Tooltips/TooltipConfig.cs +++ b/MonkeyLoader.Resonite.Integration/UI/Tooltips/TooltipConfig.cs @@ -34,6 +34,7 @@ public sealed class TooltipConfig : SingletonConfigSection private static readonly DefiningConfigKey _testKey3 = new("testKey3", "Test key3.", () => MappingTarget.NONE); private static readonly DefiningConfigKey _testKey2 = new("testKey2", "Test key2.", () => null); private static readonly DefiningConfigKey _testKey4 = new("testKey4", "Test key4.", () => null); + private static readonly DefiningConfigKey _testKey5 = new("testKey5", "Test key5.", () => null); /// /// Gets the background color for tooltips.