Skip to content

Commit

Permalink
Fix standalone facet nullables
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytra committed Dec 24, 2024
1 parent 50e383e commit dad3b75
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ internal sealed class ModSettingStandaloneFacet : ResoniteMonkey<ModSettingStand
return null;
}

private static void SyncWithConfigKeyWrapper<T>(IField field, IDefiningConfigKey key, string? eventLabel) where T : unmanaged
private static void SyncWithConfigKeyWrapper<T>(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<bool>)field).SyncWithNullableConfigKeyHasValue((IDefiningConfigKey<T>)key, eventLabel);
var type = key.ValueType.GetGenericArguments()[0];
Expand Down
4 changes: 2 additions & 2 deletions MonkeyLoader.Resonite.Integration/FieldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void ConfigKeyChangedHandler(object sender, IConfigKeyChangedEventArgs args)
/// <inheritdoc cref="SyncWithConfigKey{T}(IField{T}, IDefiningConfigKey{T}, string?, bool)"/>
public static Action<IChangeable> SyncWithNullableConfigKeyHasValue<T>(this IField<bool> field,
IDefiningConfigKey<T?> configKey, string? eventLabel = null, bool allowWriteBack = true)
where T : unmanaged
where T : struct
{
configKey.FindNearestParent<Mod>().Logger.Info(() => $"Syncing with nullable config key: {configKey.Id}");

Expand All @@ -144,7 +144,7 @@ void FieldChangedHandler(IChangeable _)
{
configKey.FindNearestParent<Mod>().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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public sealed class TooltipConfig : SingletonConfigSection<TooltipConfig>
private static readonly DefiningConfigKey<MappingTarget> _testKey3 = new("testKey3", "Test key3.", () => MappingTarget.NONE);
private static readonly DefiningConfigKey<MappingTarget?> _testKey2 = new("testKey2", "Test key2.", () => null);
private static readonly DefiningConfigKey<float?> _testKey4 = new("testKey4", "Test key4.", () => null);
private static readonly DefiningConfigKey<bool?> _testKey5 = new("testKey5", "Test key5.", () => null);

/// <summary>
/// Gets the background color for tooltips.
Expand Down

0 comments on commit dad3b75

Please sign in to comment.