mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Direct databindings - Added a large amount of modifiers
Direct databindings - Allow modifiers to have a different input parameter Direct databindings - Categorised modifiers Direct databindings - Added descriptions to modifiers
This commit is contained in:
1 parent
a5455c26d6
commit
e2f2f7ca65
48 files changed
+658
-186
No files matched your search
@@ -6,6 +6,11 @@
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconditions_005Coperators/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cconverters/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Ccolors/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers_005Crounding/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers_005Ctrigonometric/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cdatabindings_005Cmodifiers_005Cnumbers_005Ctrigonometry/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=defaulttypes_005Cproperties/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events_005Cplugins/@EntryIndexedValue">True</s:Boolean>
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class SKColorBrightenModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)};
|
||||
public override Type ParameterType => typeof(float);
|
||||
|
||||
public override string Name => "Brighten by";
|
||||
public override string Icon => "CarLightHigh";
|
||||
public override string Description => "Brightens the color by the amount in percent";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
((SKColor) currentValue).ToHsl(out var h, out var s, out var l);
|
||||
l *= (Convert.ToSingle(parameterValue) + 100f) / 100f;
|
||||
|
||||
return SKColor.FromHsl(h, s, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class SKColorDarkenModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)};
|
||||
public override Type ParameterType => typeof(float);
|
||||
|
||||
public override string Name => "Darken by";
|
||||
public override string Icon => "CarLightDimmed";
|
||||
public override string Description => "Darkens the color by the amount in percent";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
((SKColor) currentValue).ToHsl(out var h, out var s, out var l);
|
||||
l *= (Convert.ToSingle(parameterValue) * -1 + 100f) / 100f;
|
||||
return SKColor.FromHsl(h, s, l);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -7,8 +7,10 @@ namespace Artemis.Core.DefaultTypes
|
||||
internal class SKColorSumModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(SKColor)};
|
||||
public override string Description => "Combine with";
|
||||
|
||||
public override string Name => "Combine with";
|
||||
public override string Icon => "FormatColorFill";
|
||||
public override string Description => "Adds the two colors together";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class AbsoluteModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Absolute";
|
||||
public override string Icon => "NumericPositive1";
|
||||
public override string Category => "Advanced";
|
||||
public override string Description => "Converts the input value to an absolute value";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Abs(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -5,14 +5,10 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class DivideModifierType : DataBindingModifierType
|
||||
{
|
||||
public DivideModifierType()
|
||||
{
|
||||
PreferredParameterType = typeof(float);
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override Type ParameterType => typeof(float);
|
||||
|
||||
public override string Description => "Divide by";
|
||||
public override string Name => "Divide by";
|
||||
public override string Icon => "Divide";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class MaxModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
public override string Name => "Max";
|
||||
public override string Icon => "ChevronUpBoxOutline";
|
||||
public override string Category => "Advanced";
|
||||
public override string Description => "Keeps only the largest of input value and parameter";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Max(Convert.ToSingle(currentValue), Convert.ToSingle(parameterValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class MinModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
public override string Name => "Min";
|
||||
public override string Icon => "ChevronDownBoxOutline";
|
||||
public override string Category => "Advanced";
|
||||
public override string Description => "Keeps only the smallest of input value and parameter";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Min(Convert.ToSingle(currentValue), Convert.ToSingle(parameterValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class ModuloModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
public override string Name => "Modulo";
|
||||
public override string Icon => "Stairs";
|
||||
public override string Category => "Advanced";
|
||||
public override string Description => "Calculates the remained of the division between the input value and the parameter";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Convert.ToSingle(currentValue) % Convert.ToSingle(parameterValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -5,14 +5,10 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class MultiplicationModifierType : DataBindingModifierType
|
||||
{
|
||||
public MultiplicationModifierType()
|
||||
{
|
||||
PreferredParameterType = typeof(float);
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override Type ParameterType => typeof(float);
|
||||
|
||||
public override string Description => "Multiply by";
|
||||
public override string Name => "Multiply by";
|
||||
public override string Icon => "Close";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
+3
-6
@@ -5,15 +5,12 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class PercentageOfModifierType : DataBindingModifierType
|
||||
{
|
||||
public PercentageOfModifierType()
|
||||
{
|
||||
PreferredParameterType = typeof(float);
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override Type ParameterType => typeof(float);
|
||||
|
||||
public override string Description => "Percentage of";
|
||||
public override string Name => "Percentage of";
|
||||
public override string Icon => "Percent";
|
||||
public override string Description => "Calculates how much percent the parameter value is of the current value";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class PowerModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
public override string Name => "Power";
|
||||
public override string Icon => "Exponent";
|
||||
public override string Category => "Advanced";
|
||||
public override string Description => "Raises the input value to the power of the parameter value";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Pow(Convert.ToSingle(currentValue), Convert.ToSingle(parameterValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class CeilingModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Round up";
|
||||
public override string Icon => "ArrowUp";
|
||||
public override string Category => "Rounding";
|
||||
public override string Description => "Ceils the input, rounding it up to the nearest whole number";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
var floatValue = Convert.ToSingle(currentValue);
|
||||
return Math.Ceiling(floatValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -5,15 +5,13 @@ namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class FloorModifierType : DataBindingModifierType
|
||||
{
|
||||
public FloorModifierType()
|
||||
{
|
||||
SupportsParameter = false;
|
||||
}
|
||||
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override string Description => "Floor";
|
||||
public override string Icon => "ArrowDownDropCircleOutline";
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Round down";
|
||||
public override string Icon => "ArrowDown";
|
||||
public override string Category => "Rounding";
|
||||
public override string Description => "Floors the input, rounding it down to the nearest whole number";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class RoundModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Round";
|
||||
public override string Icon => "ArrowCollapse";
|
||||
public override string Category => "Rounding";
|
||||
public override string Description => "Rounds the input to the nearest whole number";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
var floatValue = Convert.ToSingle(currentValue);
|
||||
return Math.Round(floatValue, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class SquareRootModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Square root";
|
||||
public override string Icon => "SquareRoot";
|
||||
public override string Category => "Advanced";
|
||||
public override string Description => "Calculates square root of the input value";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Sqrt(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class SubtractModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
public override string Name => "Subtract";
|
||||
public override string Icon => "Minus";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Convert.ToSingle(currentValue) - Convert.ToSingle(parameterValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class SumModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
|
||||
public override string Name => "Sum";
|
||||
public override string Icon => "Plus";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Convert.ToSingle(currentValue) + Convert.ToSingle(parameterValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class CosecantModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Cosecant";
|
||||
public override string Icon => null;
|
||||
public override string Category => "Trigonometry";
|
||||
public override string Description => "Treats the input as an angle and calculates the cosecant";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return 1f / Math.Sin(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class CosineModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Cosine";
|
||||
public override string Icon => "MathCos";
|
||||
public override string Category => "Trigonometry";
|
||||
public override string Description => "Treats the input as an angle and calculates the cosine";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Cos(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class CotangentModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Cotangent";
|
||||
public override string Icon => null;
|
||||
public override string Category => "Trigonometry";
|
||||
public override string Description => "Treats the input as an angle and calculates the cotangent";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return 1f / Math.Tan(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class SecantModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Secant";
|
||||
public override string Icon => null;
|
||||
public override string Category => "Trigonometry";
|
||||
public override string Description => "Treats the input as an angle and calculates the secant";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return 1f / Math.Cos(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class SineModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Sine";
|
||||
public override string Icon => "MathSin";
|
||||
public override string Category => "Trigonometry";
|
||||
public override string Description => "Treats the input as an angle and calculates the sine";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Sin(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.DefaultTypes
|
||||
{
|
||||
internal class TangentModifierType : DataBindingModifierType
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => Constants.NumberTypes;
|
||||
public override bool SupportsParameter => false;
|
||||
|
||||
public override string Name => "Tangent";
|
||||
public override string Icon => "MathTan";
|
||||
public override string Category => "Trigonometry";
|
||||
public override string Description => "Treats the input as an angle and calculates the tangent";
|
||||
|
||||
public override object Apply(object currentValue, object parameterValue)
|
||||
{
|
||||
return Math.Tan(Convert.ToSingle(currentValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.DataModelExpansions;
|
||||
using Artemis.Storage.Entities.Profile.DataBindings;
|
||||
@@ -227,16 +226,16 @@ namespace Artemis.Core
|
||||
ParameterDataModel = null;
|
||||
ParameterPropertyPath = null;
|
||||
|
||||
var targetType = DirectDataBinding.DataBinding.GetTargetType();
|
||||
var parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
|
||||
|
||||
// If not null ensure the types match and if not, convert it
|
||||
if (staticValue != null && staticValue.GetType() == targetType)
|
||||
if (staticValue != null && staticValue.GetType() == parameterType)
|
||||
ParameterStaticValue = staticValue;
|
||||
else if (staticValue != null)
|
||||
ParameterStaticValue = Convert.ChangeType(staticValue, targetType);
|
||||
ParameterStaticValue = Convert.ChangeType(staticValue, parameterType);
|
||||
// If null create a default instance for value types or simply make it null for reference types
|
||||
else if (targetType.IsValueType)
|
||||
ParameterStaticValue = Activator.CreateInstance(targetType);
|
||||
else if (parameterType.IsValueType)
|
||||
ParameterStaticValue = Activator.CreateInstance(parameterType);
|
||||
else
|
||||
ParameterStaticValue = null;
|
||||
|
||||
@@ -269,18 +268,18 @@ namespace Artemis.Core
|
||||
else if (ParameterType == ProfileRightSideType.Static && Entity.ParameterStaticValue != null && ParameterStaticValue == null)
|
||||
{
|
||||
// Use the target type so JSON.NET has a better idea what to do
|
||||
var targetType = DirectDataBinding.DataBinding.GetTargetType();
|
||||
var parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
|
||||
object staticValue;
|
||||
|
||||
try
|
||||
{
|
||||
staticValue = JsonConvert.DeserializeObject(Entity.ParameterStaticValue, targetType);
|
||||
staticValue = JsonConvert.DeserializeObject(Entity.ParameterStaticValue, parameterType);
|
||||
}
|
||||
// If deserialization fails, use the type's default
|
||||
catch (JsonSerializationException e)
|
||||
{
|
||||
DeserializationLogger.LogModifierDeserializationFailure(GetType().Name, e);
|
||||
staticValue = Activator.CreateInstance(targetType);
|
||||
staticValue = Activator.CreateInstance(parameterType);
|
||||
}
|
||||
|
||||
UpdateParameter(staticValue);
|
||||
@@ -307,7 +306,7 @@ namespace Artemis.Core
|
||||
CompiledParameterAccessor = lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void DataBindingModifierTypeStoreOnDataBindingModifierAdded(object sender, DataBindingModifierTypeStoreEvent e)
|
||||
|
||||
@@ -21,9 +21,20 @@ namespace Artemis.Core
|
||||
public abstract IReadOnlyCollection<Type> CompatibleTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description of this modifier
|
||||
/// Gets the supported parameter type
|
||||
/// <para>If <c>null</c>, the parameter type will match the source property</para>
|
||||
/// </summary>
|
||||
public abstract string Description { get; }
|
||||
public virtual Type ParameterType => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this modifier supports a parameter, defaults to <c>true</c>
|
||||
/// </summary>
|
||||
public virtual bool SupportsParameter => true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of this modifier
|
||||
/// </summary>
|
||||
public abstract string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the icon of this modifier
|
||||
@@ -31,16 +42,15 @@ namespace Artemis.Core
|
||||
public abstract string Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether this modifier supports a parameter, defaults to <c>true</c>
|
||||
/// Gets the description of this modifier
|
||||
/// </summary>
|
||||
public bool SupportsParameter { get; protected set; } = true;
|
||||
public virtual string Description => null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the preferred parameter type
|
||||
/// <para>If <c>null</c>, the parameter type will match the source property</para>
|
||||
/// Gets the category of this modifier
|
||||
/// </summary>
|
||||
public Type PreferredParameterType { get; protected set; } = null;
|
||||
|
||||
public virtual string Category => null;
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the given type is supported by the modifier
|
||||
/// </summary>
|
||||
|
||||
@@ -42,11 +42,38 @@ namespace Artemis.Core.Services
|
||||
|
||||
private void RegisterBuiltInModifiers()
|
||||
{
|
||||
// Numbers - General
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SumModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SubtractModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new PercentageOfModifierType());
|
||||
|
||||
// Numbers - Advanced
|
||||
RegisterModifierType(Constants.CorePluginInfo, new MaxModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new MinModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new ModuloModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new AbsoluteModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new PowerModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SquareRootModifierType());
|
||||
|
||||
// Numbers - Rounding
|
||||
RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new RoundModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new CeilingModifierType());
|
||||
|
||||
// Numbers - Trigonometric
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SineModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new CosineModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new TangentModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new CotangentModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SecantModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new CosecantModifierType());
|
||||
|
||||
// Colors
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SKColorSumModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SKColorBrightenModifierType());
|
||||
RegisterModifierType(Constants.CorePluginInfo, new SKColorDarkenModifierType());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace Artemis.Core
|
||||
lock (Registrations)
|
||||
{
|
||||
if (Registrations.Any(r => r.DataBindingModifierType == modifierType))
|
||||
throw new ArtemisCoreException($"Data binding modifier type store already contains modifier '{modifierType.Description}'");
|
||||
throw new ArtemisCoreException($"Data binding modifier type store already contains modifier '{modifierType.Name}'");
|
||||
|
||||
typeRegistration = new DataBindingModifierTypeRegistration(modifierType, modifierType.PluginInfo.Instance) { IsInStore = true };
|
||||
Registrations.Add(typeRegistration);
|
||||
@@ -29,7 +29,7 @@ namespace Artemis.Core
|
||||
lock (Registrations)
|
||||
{
|
||||
if (!Registrations.Contains(typeRegistration))
|
||||
throw new ArtemisCoreException($"Data binding modifier type store does not contain modifier type '{typeRegistration.DataBindingModifierType.Description}'");
|
||||
throw new ArtemisCoreException($"Data binding modifier type store does not contain modifier type '{typeRegistration.DataBindingModifierType.Name}'");
|
||||
|
||||
Registrations.Remove(typeRegistration);
|
||||
typeRegistration.IsInStore = false;
|
||||
@@ -56,7 +56,7 @@ namespace Artemis.Core
|
||||
var candidates = Registrations.Where(r => r.DataBindingModifierType.CompatibleTypes.Any(t => t == type)).ToList();
|
||||
|
||||
// If there are multiple operators with the same description, use the closest match
|
||||
foreach (var displayDataBindingModifiers in candidates.GroupBy(r => r.DataBindingModifierType.Description).Where(g => g.Count() > 1).ToList())
|
||||
foreach (var displayDataBindingModifiers in candidates.GroupBy(r => r.DataBindingModifierType.Name).Where(g => g.Count() > 1).ToList())
|
||||
{
|
||||
var closest = displayDataBindingModifiers.OrderByDescending(r => r.DataBindingModifierType.CompatibleTypes.Contains(type)).FirstOrDefault();
|
||||
foreach (var displayDataBindingModifier in displayDataBindingModifiers)
|
||||
|
||||
Reference in new issue
Block a user