diff --git a/src/Artemis.Core/DefaultTypes/DataBindings/Modifiers/Colors/SKColorDesaturateModifierType.cs b/src/Artemis.Core/DefaultTypes/DataBindings/Modifiers/Colors/SKColorDesaturateModifierType.cs new file mode 100644 index 000000000..2c27d58d1 --- /dev/null +++ b/src/Artemis.Core/DefaultTypes/DataBindings/Modifiers/Colors/SKColorDesaturateModifierType.cs @@ -0,0 +1,19 @@ +using SkiaSharp; + +namespace Artemis.Core.DefaultTypes +{ + internal class SKColorDesaturateModifierType : DataBindingModifierType + { + public override string Name => "Desaturate"; + public override string Icon => "ImageMinus"; + public override string Description => "Desaturates the color by the amount in percent"; + + public override SKColor Apply(SKColor currentValue, float parameterValue) + { + // TODO: Not so straightforward ^^ + currentValue.ToHsl(out float h, out float s, out float l); + s *= (parameterValue * -1 + 100f) / 100f; + return SKColor.FromHsl(h, s, l); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/DefaultTypes/DataBindings/Modifiers/Colors/SKColorSaturateModifierType.cs b/src/Artemis.Core/DefaultTypes/DataBindings/Modifiers/Colors/SKColorSaturateModifierType.cs new file mode 100644 index 000000000..daa5b0fc7 --- /dev/null +++ b/src/Artemis.Core/DefaultTypes/DataBindings/Modifiers/Colors/SKColorSaturateModifierType.cs @@ -0,0 +1,18 @@ +using SkiaSharp; + +namespace Artemis.Core.DefaultTypes +{ + internal class SKColorSaturateModifierType : DataBindingModifierType + { + public override string Name => "Saturate"; + public override string Icon => "ImagePlus"; + public override string Description => "Saturates the color by the amount in percent"; + + public override SKColor Apply(SKColor currentValue, float parameterValue) + { + // TODO: Not so straightforward ^^ + currentValue.ToHsl(out float h, out float s, out float l); + return SKColor.FromHsl(h, parameterValue, l); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Models/Profile/DataBindings/Modes/Direct/DataBindingModifier.cs b/src/Artemis.Core/Models/Profile/DataBindings/Modes/Direct/DataBindingModifier.cs index 1883517c7..10732dfd3 100644 --- a/src/Artemis.Core/Models/Profile/DataBindings/Modes/Direct/DataBindingModifier.cs +++ b/src/Artemis.Core/Models/Profile/DataBindings/Modes/Direct/DataBindingModifier.cs @@ -109,14 +109,6 @@ namespace Artemis.Core $"it does not support this data binding's type {targetType.Name}"); ModifierType = modifierType; - - // Ensure the right parameter static value is never null when the parameter type is a value type - if (ParameterType == ProfileRightSideType.Static && modifierType.ParameterType != null) - { - if (modifierType.ParameterType.IsValueType && ParameterStaticValue == null) - UpdateParameterStatic(modifierType.ParameterType.GetDefault()); - } - ValidateParameter(); } @@ -225,14 +217,7 @@ namespace Artemis.Core staticValue = Activator.CreateInstance(parameterType); } - try - { - UpdateParameterStatic(staticValue); - } - catch (Exception e) - { - DeserializationLogger.LogModifierDeserializationFailure(GetType().Name, new JsonSerializationException("The JSON deserialized into a mismatching type", e)); - } + UpdateParameterStatic(staticValue); } } diff --git a/src/Artemis.Core/Services/Registration/DataBindingService.cs b/src/Artemis.Core/Services/Registration/DataBindingService.cs index 28218cf65..96dedfe50 100644 --- a/src/Artemis.Core/Services/Registration/DataBindingService.cs +++ b/src/Artemis.Core/Services/Registration/DataBindingService.cs @@ -72,6 +72,8 @@ namespace Artemis.Core.Services // Colors RegisterModifierType(Constants.CorePluginInfo, new SKColorSumModifierType()); + RegisterModifierType(Constants.CorePluginInfo, new SKColorSaturateModifierType()); + RegisterModifierType(Constants.CorePluginInfo, new SKColorDesaturateModifierType()); RegisterModifierType(Constants.CorePluginInfo, new SKColorBrightenModifierType()); RegisterModifierType(Constants.CorePluginInfo, new SKColorDarkenModifierType()); RegisterModifierType(Constants.CorePluginInfo, new SKColorRotateHueModifierType()); diff --git a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DirectDataBinding/DataBindingModifierViewModel.cs b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DirectDataBinding/DataBindingModifierViewModel.cs index a77871291..65620f0e5 100644 --- a/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DirectDataBinding/DataBindingModifierViewModel.cs +++ b/src/Artemis.UI/Screens/ProfileEditor/LayerProperties/DataBindings/DirectDataBinding/DataBindingModifierViewModel.cs @@ -140,7 +140,12 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.DataBindings.DirectDa if (DynamicSelectionViewModel != null) DynamicSelectionViewModel.ChangeDataModelPath(Modifier.ParameterPath); else if (StaticInputViewModel != null) + { + // Ensure the right static value is never null when the preferred type is a value type StaticInputViewModel.Value = Modifier.ParameterStaticValue; + if (SelectedModifierType.ParameterType.IsValueType && StaticInputViewModel.Value == null) + StaticInputViewModel.Value = SelectedModifierType.ParameterType.GetDefault(); + } } private void ExecuteSelectModifierTypeCommand(object context)