Darthified code

This commit is contained in:
SpoinkyNL committed 2020-10-05 22:50:29 +02:00
1 parent 5b80c1e4fe
commit ae64db8a13
198 files changed
+1339 -1305

No files matched your search

@@ -37,10 +37,10 @@ namespace Artemis.Core
if (timesToRepeat == 0)
return Stops.OrderBy(c => c.Position).Select(c => c.Color).ToArray();
var colors = Stops.OrderBy(c => c.Position).Select(c => c.Color).ToList();
var result = new List<SKColor>();
List<SKColor> colors = Stops.OrderBy(c => c.Position).Select(c => c.Color).ToList();
List<SKColor> result = new List<SKColor>();
for (var i = 0; i <= timesToRepeat; i++)
for (int i = 0; i <= timesToRepeat; i++)
result.AddRange(colors);
return result.ToArray();
@@ -60,13 +60,13 @@ namespace Artemis.Core
return Stops.OrderBy(c => c.Position).Select(c => c.Position).ToArray();
// Create stops and a list of divided stops
var stops = Stops.OrderBy(c => c.Position).Select(c => c.Position / (timesToRepeat + 1)).ToList();
var result = new List<float>();
List<float> stops = Stops.OrderBy(c => c.Position).Select(c => c.Position / (timesToRepeat + 1)).ToList();
List<float> result = new List<float>();
// For each repeat cycle, add the base stops to the end result
for (var i = 0; i <= timesToRepeat; i++)
for (int i = 0; i <= timesToRepeat; i++)
{
var localStops = stops.Select(s => s + result.LastOrDefault()).ToList();
List<float> localStops = stops.Select(s => s + result.LastOrDefault()).ToList();
result.AddRange(localStops);
}
@@ -90,11 +90,11 @@ namespace Artemis.Core
if (!Stops.Any())
return SKColor.Empty;
var stops = Stops.OrderBy(x => x.Position).ToArray();
ColorGradientStop[] stops = Stops.OrderBy(x => x.Position).ToArray();
if (position <= 0) return stops[0].Color;
if (position >= 1) return stops[^1].Color;
ColorGradientStop left = stops[0], right = null;
foreach (var stop in stops)
foreach (ColorGradientStop stop in stops)
{
if (stop.Position >= position)
{
@@ -109,10 +109,10 @@ namespace Artemis.Core
return left.Color;
position = (float) Math.Round((position - left.Position) / (right.Position - left.Position), 2);
var a = (byte) ((right.Color.Alpha - left.Color.Alpha) * position + left.Color.Alpha);
var r = (byte) ((right.Color.Red - left.Color.Red) * position + left.Color.Red);
var g = (byte) ((right.Color.Green - left.Color.Green) * position + left.Color.Green);
var b = (byte) ((right.Color.Blue - left.Color.Blue) * position + left.Color.Blue);
byte a = (byte) ((right.Color.Alpha - left.Color.Alpha) * position + left.Color.Alpha);
byte r = (byte) ((right.Color.Red - left.Color.Red) * position + left.Color.Red);
byte g = (byte) ((right.Color.Green - left.Color.Green) * position + left.Color.Green);
byte b = (byte) ((right.Color.Blue - left.Color.Blue) * position + left.Color.Blue);
return new SKColor(r, g, b, a);
}
@@ -122,10 +122,10 @@ namespace Artemis.Core
/// <returns></returns>
public static ColorGradient GetUnicornBarf()
{
var gradient = new ColorGradient();
for (var i = 0; i < 9; i++)
ColorGradient gradient = new ColorGradient();
for (int i = 0; i < 9; i++)
{
var color = i != 8 ? SKColor.FromHsv(i * 32, 100, 100) : SKColor.FromHsv(0, 100, 100);
SKColor color = i != 8 ? SKColor.FromHsv(i * 32, 100, 100) : SKColor.FromHsv(0, 100, 100);
gradient.Stops.Add(new ColorGradientStop(color, 0.125f * i));
}
@@ -34,7 +34,7 @@ namespace Artemis.Core
Entity = entity;
BooleanOperator = (BooleanOperator) Entity.BooleanOperator;
foreach (var childEntity in Entity.Children)
foreach (DataModelConditionPartEntity childEntity in Entity.Children)
{
if (childEntity is DataModelConditionGroupEntity groupEntity)
AddChild(new DataModelConditionGroup(this, groupEntity));
@@ -88,7 +88,7 @@ namespace Artemis.Core
protected override void Dispose(bool disposing)
{
_disposed = true;
foreach (var child in Children)
foreach (DataModelConditionPart child in Children)
child.Dispose();
base.Dispose(disposing);
@@ -125,7 +125,7 @@ namespace Artemis.Core
Entity.Children.Clear();
Entity.Children.AddRange(Children.Select(c => c.GetEntity()));
foreach (var child in Children)
foreach (DataModelConditionPart child in Children)
child.Save();
}
@@ -1,5 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Artemis.Core.DataModelExpansions;
@@ -97,7 +98,7 @@ namespace Artemis.Core
if (dataModel != null)
{
var listType = dataModel.GetListTypeAtPath(path);
Type listType = dataModel.GetListTypeAtPath(path);
if (listType == null)
throw new ArtemisCoreException($"Data model of type {dataModel.GetType().Name} does not contain a list at path '{path}'");
@@ -130,7 +131,7 @@ namespace Artemis.Core
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var child in Children)
foreach (DataModelConditionPart child in Children)
child.Dispose();
base.Dispose(disposing);
@@ -148,7 +149,7 @@ namespace Artemis.Core
if (!(target is IList list))
return false;
var objectList = list.Cast<object>();
IEnumerable<object> objectList = list.Cast<object>();
return ListOperator switch
{
ListOperator.Any => objectList.Any(o => Children[0].EvaluateObject(o)),
@@ -174,7 +175,7 @@ namespace Artemis.Core
// Children
Entity.Children.Clear();
Entity.Children.AddRange(Children.Select(c => c.GetEntity()));
foreach (var child in Children)
foreach (DataModelConditionPart child in Children)
child.Save();
}
@@ -191,11 +192,11 @@ namespace Artemis.Core
return;
// Get the data model ...
var dataModel = DataModelStore.Get(Entity.ListDataModelGuid.Value)?.DataModel;
DataModel dataModel = DataModelStore.Get(Entity.ListDataModelGuid.Value)?.DataModel;
if (dataModel == null)
return;
// ... and ensure the path is valid
var listType = dataModel.GetListTypeAtPath(Entity.ListPropertyPath);
Type listType = dataModel.GetListTypeAtPath(Entity.ListPropertyPath);
if (listType == null)
return;
@@ -224,14 +225,14 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("DataModelConditionList");
var parameter = Expression.Parameter(typeof(object), "listDataModel");
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
ParameterExpression parameter = Expression.Parameter(typeof(object), "listDataModel");
Expression accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
Expression.Convert(parameter, ListDataModel.GetType()),
Expression.Property
);
accessor = Expression.Convert(accessor, typeof(IList));
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
Expression<Func<object, IList>> lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
CompiledListAccessor = lambda.Compile();
}
@@ -240,7 +241,7 @@ namespace Artemis.Core
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
{
var dataModel = e.Registration.DataModel;
DataModel dataModel = e.Registration.DataModel;
if (dataModel.PluginInfo.Guid == Entity.ListDataModelGuid && dataModel.ContainsPath(Entity.ListPropertyPath))
{
ListDataModel = dataModel;
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Artemis.Core.DataModelExpansions;
using Artemis.Storage.Entities.Profile.Abstract;
using Artemis.Storage.Entities.Profile.Conditions;
@@ -171,7 +172,7 @@ namespace Artemis.Core
return;
}
var leftType = GetTypeAtInnerPath(LeftPropertyPath);
Type leftType = GetTypeAtInnerPath(LeftPropertyPath);
if (conditionOperator.SupportsType(leftType))
Operator = conditionOperator;
@@ -195,11 +196,11 @@ namespace Artemis.Core
if (DataModelConditionList.ListType == null)
return false;
var parts = path.Split('.');
var current = DataModelConditionList.ListType;
foreach (var part in parts)
string[] parts = path.Split('.');
Type current = DataModelConditionList.ListType;
foreach (string part in parts)
{
var property = current.GetProperty(part);
PropertyInfo? property = current.GetProperty(part);
current = property?.PropertyType;
if (property == null)
@@ -237,13 +238,13 @@ namespace Artemis.Core
if (!ListContainsInnerPath(path))
return null;
var parts = path.Split('.');
var current = DataModelConditionList.ListType;
string[] parts = path.Split('.');
Type current = DataModelConditionList.ListType;
Type result = null;
foreach (var part in parts)
foreach (string part in parts)
{
var property = current.GetProperty(part);
PropertyInfo? property = current.GetProperty(part);
current = property.PropertyType;
result = property.PropertyType;
}
@@ -274,7 +275,7 @@ namespace Artemis.Core
private void ApplyParentList()
{
var current = Parent;
DataModelConditionPart current = Parent;
while (current != null)
{
@@ -311,7 +312,7 @@ namespace Artemis.Core
// Operator
if (Entity.OperatorPluginGuid != null)
{
var conditionOperator = ConditionOperatorStore.Get(Entity.OperatorPluginGuid.Value, Entity.OperatorType)?.ConditionOperator;
ConditionOperator conditionOperator = ConditionOperatorStore.Get(Entity.OperatorPluginGuid.Value, Entity.OperatorType)?.ConditionOperator;
if (conditionOperator != null)
UpdateOperator(conditionOperator);
}
@@ -319,7 +320,7 @@ namespace Artemis.Core
// Right side dynamic
if (PredicateType == ListRightSideType.Dynamic && Entity.RightDataModelGuid != null && Entity.RightPropertyPath != null)
{
var dataModel = DataModelStore.Get(Entity.RightDataModelGuid.Value)?.DataModel;
DataModel dataModel = DataModelStore.Get(Entity.RightDataModelGuid.Value)?.DataModel;
if (dataModel != null && dataModel.ContainsPath(Entity.RightPropertyPath))
UpdateRightSideDynamic(dataModel, Entity.RightPropertyPath);
}
@@ -337,7 +338,7 @@ namespace Artemis.Core
if (LeftPropertyPath != null)
{
// Use the left side type so JSON.NET has a better idea what to do
var leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
Type leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
object rightSideValue;
try
@@ -385,20 +386,20 @@ namespace Artemis.Core
if (LeftPropertyPath == null || Operator == null)
return;
var leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
Type leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
if (!Operator.SupportsType(leftSideType))
Operator = null;
}
private void ValidateRightSide()
{
var leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
Type leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
if (PredicateType == ListRightSideType.Dynamic)
{
if (RightDataModel == null)
return;
var rightSideType = RightDataModel.GetTypeAtPath(RightPropertyPath);
Type rightSideType = RightDataModel.GetTypeAtPath(RightPropertyPath);
if (!leftSideType.IsCastableFrom(rightSideType))
UpdateRightSideDynamic(null, null);
}
@@ -407,7 +408,7 @@ namespace Artemis.Core
if (RightPropertyPath == null)
return;
var rightSideType = GetTypeAtInnerPath(RightPropertyPath);
Type rightSideType = GetTypeAtInnerPath(RightPropertyPath);
if (!leftSideType.IsCastableFrom(rightSideType))
UpdateRightSideDynamic(null);
}
@@ -429,7 +430,7 @@ namespace Artemis.Core
return;
}
var leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
Type leftSideType = GetTypeAtInnerPath(LeftPropertyPath);
// If not null ensure the types match and if not, convert it
if (staticValue != null && staticValue.GetType() == leftSideType)
@@ -449,9 +450,9 @@ namespace Artemis.Core
return;
// List accessors share the same parameter because a list always contains one item per entry
var leftSideParameter = Expression.Parameter(typeof(object), "listItem");
var leftSideAccessor = CreateListAccessor(LeftPropertyPath, leftSideParameter);
var rightSideAccessor = CreateListAccessor(RightPropertyPath, leftSideParameter);
ParameterExpression leftSideParameter = Expression.Parameter(typeof(object), "listItem");
Expression leftSideAccessor = CreateListAccessor(LeftPropertyPath, leftSideParameter);
Expression rightSideAccessor = CreateListAccessor(RightPropertyPath, leftSideParameter);
// A conversion may be required if the types differ
// This can cause issues if the DataModelConditionOperator wasn't accurate in it's supported types but that is not a concern here
@@ -468,9 +469,9 @@ namespace Artemis.Core
return;
// List accessors share the same parameter because a list always contains one item per entry
var leftSideParameter = Expression.Parameter(typeof(object), "listItem");
var leftSideAccessor = CreateListAccessor(LeftPropertyPath, leftSideParameter);
var rightSideAccessor = ExpressionUtilities.CreateDataModelAccessor(RightDataModel, RightPropertyPath, "right", out var rightSideParameter);
ParameterExpression leftSideParameter = Expression.Parameter(typeof(object), "listItem");
Expression leftSideAccessor = CreateListAccessor(LeftPropertyPath, leftSideParameter);
Expression rightSideAccessor = ExpressionUtilities.CreateDataModelAccessor(RightDataModel, RightPropertyPath, "right", out ParameterExpression rightSideParameter);
// A conversion may be required if the types differ
// This can cause issues if the DataModelConditionOperator wasn't accurate in it's supported types but that is not a concern here
@@ -487,8 +488,8 @@ namespace Artemis.Core
return;
// List accessors share the same parameter because a list always contains one item per entry
var leftSideParameter = Expression.Parameter(typeof(object), "listItem");
var leftSideAccessor = DataModelConditionList.IsPrimitiveList
ParameterExpression leftSideParameter = Expression.Parameter(typeof(object), "listItem");
Expression leftSideAccessor = DataModelConditionList.IsPrimitiveList
? Expression.Convert(leftSideParameter, DataModelConditionList.ListType)
: CreateListAccessor(LeftPropertyPath, leftSideParameter);
@@ -523,7 +524,7 @@ namespace Artemis.Core
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
{
var dataModel = e.Registration.DataModel;
DataModel dataModel = e.Registration.DataModel;
if (dataModel.PluginInfo.Guid == Entity.RightDataModelGuid && dataModel.ContainsPath(Entity.RightPropertyPath))
UpdateRightSideDynamic(dataModel, Entity.RightPropertyPath);
}
@@ -539,7 +540,7 @@ namespace Artemis.Core
private void ConditionOperatorStoreOnConditionOperatorAdded(object sender, ConditionOperatorStoreEvent e)
{
var conditionOperator = e.Registration.ConditionOperator;
ConditionOperator conditionOperator = e.Registration.ConditionOperator;
if (Entity.OperatorPluginGuid == conditionOperator.PluginInfo.Guid && Entity.OperatorType == conditionOperator.GetType().Name)
UpdateOperator(conditionOperator);
}
@@ -147,7 +147,7 @@ namespace Artemis.Core
return;
}
var leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
Type leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
// If not null ensure the types match and if not, convert it
if (staticValue != null && staticValue.GetType() == leftSideType)
@@ -184,7 +184,7 @@ namespace Artemis.Core
return;
}
var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
Type leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
if (!conditionOperator.SupportsType(leftType))
{
throw new ArtemisCoreException($"Cannot apply operator {conditionOperator.GetType().Name} to this predicate because " +
@@ -204,7 +204,7 @@ namespace Artemis.Core
// Compare with a static value
if (PredicateType == ProfileRightSideType.Static)
{
var leftSideValue = LeftSideAccessor(LeftDataModel);
object leftSideValue = LeftSideAccessor(LeftDataModel);
if (leftSideValue.GetType().IsValueType && RightStaticValue == null)
return false;
@@ -256,7 +256,7 @@ namespace Artemis.Core
// Left side
if (Entity.LeftDataModelGuid != null)
{
var dataModel = DataModelStore.Get(Entity.LeftDataModelGuid.Value)?.DataModel;
DataModel dataModel = DataModelStore.Get(Entity.LeftDataModelGuid.Value)?.DataModel;
if (dataModel != null && dataModel.ContainsPath(Entity.LeftPropertyPath))
UpdateLeftSide(dataModel, Entity.LeftPropertyPath);
}
@@ -264,7 +264,7 @@ namespace Artemis.Core
// Operator
if (Entity.OperatorPluginGuid != null)
{
var conditionOperator = ConditionOperatorStore.Get(Entity.OperatorPluginGuid.Value, Entity.OperatorType)?.ConditionOperator;
ConditionOperator conditionOperator = ConditionOperatorStore.Get(Entity.OperatorPluginGuid.Value, Entity.OperatorType)?.ConditionOperator;
if (conditionOperator != null)
UpdateOperator(conditionOperator);
}
@@ -272,7 +272,7 @@ namespace Artemis.Core
// Right side dynamic
if (PredicateType == ProfileRightSideType.Dynamic && Entity.RightDataModelGuid != null)
{
var dataModel = DataModelStore.Get(Entity.RightDataModelGuid.Value)?.DataModel;
DataModel dataModel = DataModelStore.Get(Entity.RightDataModelGuid.Value)?.DataModel;
if (dataModel != null && dataModel.ContainsPath(Entity.RightPropertyPath))
UpdateRightSide(dataModel, Entity.RightPropertyPath);
}
@@ -284,7 +284,7 @@ namespace Artemis.Core
if (LeftDataModel != null)
{
// Use the left side type so JSON.NET has a better idea what to do
var leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
Type leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
object rightSideValue;
try
@@ -336,20 +336,20 @@ namespace Artemis.Core
if (LeftDataModel == null || Operator == null)
return;
var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
Type leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
if (!Operator.SupportsType(leftType))
Operator = null;
}
private void ValidateRightSide()
{
var leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
Type leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
if (PredicateType == ProfileRightSideType.Dynamic)
{
if (RightDataModel == null)
return;
var rightSideType = RightDataModel.GetTypeAtPath(RightPropertyPath);
Type rightSideType = RightDataModel.GetTypeAtPath(RightPropertyPath);
if (!leftSideType.IsCastableFrom(rightSideType))
UpdateRightSide(null, null);
}
@@ -367,8 +367,8 @@ namespace Artemis.Core
if (LeftDataModel == null || RightDataModel == null || Operator == null)
return;
var leftSideAccessor = ExpressionUtilities.CreateDataModelAccessor(LeftDataModel, LeftPropertyPath, "left", out var leftSideParameter);
var rightSideAccessor = ExpressionUtilities.CreateDataModelAccessor(RightDataModel, RightPropertyPath, "right", out var rightSideParameter);
Expression leftSideAccessor = ExpressionUtilities.CreateDataModelAccessor(LeftDataModel, LeftPropertyPath, "left", out ParameterExpression leftSideParameter);
Expression rightSideAccessor = ExpressionUtilities.CreateDataModelAccessor(RightDataModel, RightPropertyPath, "right", out ParameterExpression rightSideParameter);
// A conversion may be required if the types differ
// This can cause issues if the DataModelConditionOperator wasn't accurate in it's supported types but that is not a concern here
@@ -384,8 +384,8 @@ namespace Artemis.Core
if (LeftDataModel == null || Operator == null)
return;
var leftSideAccessor = Expression.Convert(
ExpressionUtilities.CreateDataModelAccessor(LeftDataModel, LeftPropertyPath, "left", out var leftSideParameter),
UnaryExpression leftSideAccessor = Expression.Convert(
ExpressionUtilities.CreateDataModelAccessor(LeftDataModel, LeftPropertyPath, "left", out ParameterExpression leftSideParameter),
typeof(object)
);
@@ -402,7 +402,7 @@ namespace Artemis.Core
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
{
var dataModel = e.Registration.DataModel;
DataModel dataModel = e.Registration.DataModel;
if (dataModel.PluginInfo.Guid == Entity.LeftDataModelGuid && dataModel.ContainsPath(Entity.LeftPropertyPath))
UpdateLeftSide(dataModel, Entity.LeftPropertyPath);
if (dataModel.PluginInfo.Guid == Entity.RightDataModelGuid && dataModel.ContainsPath(Entity.RightPropertyPath))
@@ -426,7 +426,7 @@ namespace Artemis.Core
private void ConditionOperatorStoreOnConditionOperatorAdded(object sender, ConditionOperatorStoreEvent e)
{
var conditionOperator = e.Registration.ConditionOperator;
ConditionOperator conditionOperator = e.Registration.ConditionOperator;
if (Entity.OperatorPluginGuid == conditionOperator.PluginInfo.Guid && Entity.OperatorType == conditionOperator.GetType().Name)
UpdateOperator(conditionOperator);
}
@@ -93,8 +93,8 @@ namespace Artemis.Core
if (Converter == null)
return;
var converterValue = Converter.GetValue();
var value = GetValue(converterValue);
TProperty converterValue = Converter.GetValue();
TProperty value = GetValue(converterValue);
Converter.ApplyValue(value);
}
@@ -121,7 +121,7 @@ namespace Artemis.Core
if (Converter == null || DataBindingMode == null)
return baseValue;
var value = DataBindingMode.GetValue(baseValue);
TProperty value = DataBindingMode.GetValue(baseValue);
// If no easing is to be applied simple return whatever the current value is
if (EasingTime == TimeSpan.Zero || !Converter.SupportsInterpolate)
@@ -175,7 +175,7 @@ namespace Artemis.Core
if (_easingProgress == EasingTime || !Converter.SupportsInterpolate)
return _currentValue;
var easingAmount = _easingProgress.TotalSeconds / EasingTime.TotalSeconds;
double easingAmount = _easingProgress.TotalSeconds / EasingTime.TotalSeconds;
return Converter.Interpolate(_previousValue, _currentValue, Easings.Interpolate(easingAmount, EasingFunction));
}
@@ -229,7 +229,7 @@ namespace Artemis.Core
throw new ObjectDisposedException("DataBinding");
// General
var registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
DataBindingRegistration<TLayerProperty, TProperty> registration = LayerProperty.GetDataBindingRegistration<TProperty>(Entity.TargetExpression);
if (registration != null)
ApplyRegistration(registration);
@@ -130,43 +130,43 @@ namespace Artemis.Core
private void CreateSetReferenceTypeExpression()
{
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
var parameter = Expression.Parameter(typeof(TLayerProperty), "currentValue");
var memberAccess = Expression.MakeMemberAccess(parameter, DataBinding.Registration.Member);
var assignment = Expression.Assign(memberAccess, propertyValue);
var referenceTypeLambda = Expression.Lambda<Action<TLayerProperty, TProperty>>(assignment, parameter, propertyValue);
ParameterExpression propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
ParameterExpression parameter = Expression.Parameter(typeof(TLayerProperty), "currentValue");
MemberExpression memberAccess = Expression.MakeMemberAccess(parameter, DataBinding.Registration.Member);
BinaryExpression assignment = Expression.Assign(memberAccess, propertyValue);
Expression<Action<TLayerProperty, TProperty>> referenceTypeLambda = Expression.Lambda<Action<TLayerProperty, TProperty>>(assignment, parameter, propertyValue);
ReferenceTypeSetExpression = referenceTypeLambda.Compile();
}
private void CreateSetValueTypeExpression()
{
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
var variableCurrent = Expression.Variable(typeof(TLayerProperty), "current");
var layerProperty = Expression.Constant(DataBinding.LayerProperty);
var layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
ParameterExpression propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
ParameterExpression variableCurrent = Expression.Variable(typeof(TLayerProperty), "current");
ConstantExpression layerProperty = Expression.Constant(DataBinding.LayerProperty);
MemberExpression layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
DataBinding.LayerProperty.GetType().GetMember(nameof(DataBinding.LayerProperty.CurrentValue))[0]);
var body = Expression.Block(
BlockExpression body = Expression.Block(
new[] {variableCurrent},
Expression.Assign(variableCurrent, layerPropertyMemberAccess),
Expression.Assign(Expression.MakeMemberAccess(variableCurrent, DataBinding.Registration.Member), propertyValue),
Expression.Assign(layerPropertyMemberAccess, variableCurrent)
);
var valueTypeLambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
Expression<Action<TProperty>> valueTypeLambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
ValueTypeSetExpression = valueTypeLambda.Compile();
}
private void CreateSetCurrentValueExpression()
{
var propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
var layerProperty = Expression.Constant(DataBinding.LayerProperty);
var layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
ParameterExpression propertyValue = Expression.Parameter(typeof(TProperty), "propertyValue");
ConstantExpression layerProperty = Expression.Constant(DataBinding.LayerProperty);
MemberExpression layerPropertyMemberAccess = Expression.MakeMemberAccess(layerProperty,
DataBinding.LayerProperty.GetType().GetMember(nameof(DataBinding.LayerProperty.CurrentValue))[0]);
var body = Expression.Assign(layerPropertyMemberAccess, propertyValue);
var lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
BinaryExpression body = Expression.Assign(layerPropertyMemberAccess, propertyValue);
Expression<Action<TProperty>> lambda = Expression.Lambda<Action<TProperty>>(body, propertyValue);
ValueTypeSetExpression = lambda.Compile();
}
}
@@ -2,6 +2,7 @@
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Artemis.Storage.Entities.Profile.DataBindings;
namespace Artemis.Core
{
@@ -58,7 +59,7 @@ namespace Artemis.Core
if (DataBinding != null)
return DataBinding;
var dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == PropertyExpression.ToString());
DataBindingEntity dataBinding = LayerProperty.Entity.DataBindingEntities.FirstOrDefault(e => e.TargetExpression == PropertyExpression.ToString());
if (dataBinding == null)
return null;
@@ -36,7 +36,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("ConditionalDataBinding");
var condition = Conditions.FirstOrDefault(c => c.Evaluate());
DataBindingCondition<TLayerProperty, TProperty> condition = Conditions.FirstOrDefault(c => c.Evaluate());
if (condition != null)
Console.WriteLine();
return condition == null ? baseValue : condition.Value;
@@ -49,7 +49,7 @@ namespace Artemis.Core
{
_disposed = true;
foreach (var dataBindingCondition in Conditions)
foreach (DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition in Conditions)
dataBindingCondition.Dispose();
}
@@ -66,7 +66,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("ConditionalDataBinding");
var condition = new DataBindingCondition<TLayerProperty, TProperty>(this);
DataBindingCondition<TLayerProperty, TProperty> condition = new DataBindingCondition<TLayerProperty, TProperty>(this);
_conditions.Add(condition);
ApplyOrder();
@@ -102,9 +102,9 @@ namespace Artemis.Core
throw new ObjectDisposedException("ConditionalDataBinding");
_conditions.Sort((a, b) => a.Order.CompareTo(b.Order));
for (var index = 0; index < _conditions.Count; index++)
for (int index = 0; index < _conditions.Count; index++)
{
var condition = _conditions[index];
DataBindingCondition<TLayerProperty, TProperty> condition = _conditions[index];
condition.Order = index + 1;
}
}
@@ -116,7 +116,7 @@ namespace Artemis.Core
/// <inheritdoc />
public void Load()
{
foreach (var dataBindingConditionEntity in Entity.Values)
foreach (DataBindingConditionEntity dataBindingConditionEntity in Entity.Values)
_conditions.Add(new DataBindingCondition<TLayerProperty, TProperty>(this, dataBindingConditionEntity));
ApplyOrder();
@@ -126,7 +126,7 @@ namespace Artemis.Core
public void Save()
{
Entity.Values.Clear();
foreach (var dataBindingCondition in Conditions)
foreach (DataBindingCondition<TLayerProperty, TProperty> dataBindingCondition in Conditions)
dataBindingCondition.Save();
}
@@ -147,7 +147,7 @@ namespace Artemis.Core
if (ParameterType == ProfileRightSideType.Dynamic && CompiledParameterAccessor != null)
{
var value = CompiledParameterAccessor(ParameterDataModel);
object value = CompiledParameterAccessor(ParameterDataModel);
return ModifierType.Apply(currentValue, value);
}
@@ -174,7 +174,7 @@ namespace Artemis.Core
return;
}
var targetType = DirectDataBinding.DataBinding.GetTargetType();
Type targetType = DirectDataBinding.DataBinding.GetTargetType();
if (!modifierType.SupportsType(targetType))
{
throw new ArtemisCoreException($"Cannot apply modifier type {modifierType.GetType().Name} to this modifier because " +
@@ -226,7 +226,7 @@ namespace Artemis.Core
ParameterDataModel = null;
ParameterPropertyPath = null;
var parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
Type parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
// If not null ensure the types match and if not, convert it
if (staticValue != null && staticValue.GetType() == parameterType)
@@ -252,7 +252,7 @@ namespace Artemis.Core
// Modifier type
if (Entity.ModifierTypePluginGuid != null && ModifierType == null)
{
var modifierType = DataBindingModifierTypeStore.Get(Entity.ModifierTypePluginGuid.Value, Entity.ModifierType)?.DataBindingModifierType;
DataBindingModifierType modifierType = DataBindingModifierTypeStore.Get(Entity.ModifierTypePluginGuid.Value, Entity.ModifierType)?.DataBindingModifierType;
if (modifierType != null)
UpdateModifierType(modifierType);
}
@@ -260,7 +260,7 @@ namespace Artemis.Core
// Dynamic parameter
if (ParameterType == ProfileRightSideType.Dynamic && Entity.ParameterDataModelGuid != null && ParameterDataModel == null)
{
var dataModel = DataModelStore.Get(Entity.ParameterDataModelGuid.Value)?.DataModel;
DataModel dataModel = DataModelStore.Get(Entity.ParameterDataModelGuid.Value)?.DataModel;
if (dataModel != null && dataModel.ContainsPath(Entity.ParameterPropertyPath))
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
}
@@ -268,7 +268,7 @@ 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 parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
Type parameterType = ModifierType?.ParameterType ?? DirectDataBinding.DataBinding.GetTargetType();
object staticValue;
try
@@ -299,10 +299,10 @@ namespace Artemis.Core
return;
// If the right side value is null, the constant type cannot be inferred and must be provided based on the data binding target
var parameterAccessor = ExpressionUtilities.CreateDataModelAccessor(
ParameterDataModel, ParameterPropertyPath, "parameter", out var rightSideParameter
Expression parameterAccessor = ExpressionUtilities.CreateDataModelAccessor(
ParameterDataModel, ParameterPropertyPath, "parameter", out ParameterExpression rightSideParameter
);
var lambda = Expression.Lambda<Func<DataModel, object>>(Expression.Convert(parameterAccessor, typeof(object)), rightSideParameter);
Expression<Func<DataModel, object>> lambda = Expression.Lambda<Func<DataModel, object>>(Expression.Convert(parameterAccessor, typeof(object)), rightSideParameter);
CompiledParameterAccessor = lambda.Compile();
}
}
@@ -314,7 +314,7 @@ namespace Artemis.Core
if (ModifierType != null)
return;
var modifierType = e.TypeRegistration.DataBindingModifierType;
DataBindingModifierType modifierType = e.TypeRegistration.DataBindingModifierType;
if (modifierType.PluginInfo.Guid == Entity.ModifierTypePluginGuid && modifierType.GetType().Name == Entity.ModifierType)
UpdateModifierType(modifierType);
}
@@ -327,7 +327,7 @@ namespace Artemis.Core
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
{
var dataModel = e.Registration.DataModel;
DataModel dataModel = e.Registration.DataModel;
if (dataModel.PluginInfo.Guid == Entity.ParameterDataModelGuid && dataModel.ContainsPath(Entity.ParameterPropertyPath))
UpdateParameter(dataModel, Entity.ParameterPropertyPath);
}
@@ -58,8 +58,8 @@ namespace Artemis.Core
if (CompiledTargetAccessor == null)
return baseValue;
var dataBindingValue = CompiledTargetAccessor(SourceDataModel);
foreach (var dataBindingModifier in Modifiers)
object dataBindingValue = CompiledTargetAccessor(SourceDataModel);
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
dataBindingValue = dataBindingModifier.Apply(dataBindingValue);
return DataBinding.Converter.ConvertFromObject(dataBindingValue);
@@ -75,7 +75,7 @@ namespace Artemis.Core
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var dataBindingModifier in Modifiers)
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
dataBindingModifier.Dispose();
}
@@ -89,7 +89,7 @@ namespace Artemis.Core
// Data model is done during Initialize
// Modifiers
foreach (var dataBindingModifierEntity in Entity.Modifiers)
foreach (DataBindingModifierEntity dataBindingModifierEntity in Entity.Modifiers)
_modifiers.Add(new DataBindingModifier<TLayerProperty, TProperty>(this, dataBindingModifierEntity));
ApplyOrder();
@@ -107,7 +107,7 @@ namespace Artemis.Core
// Modifiers
Entity.Modifiers.Clear();
foreach (var dataBindingModifier in Modifiers)
foreach (DataBindingModifier<TLayerProperty, TProperty> dataBindingModifier in Modifiers)
dataBindingModifier.Save();
}
@@ -123,7 +123,7 @@ namespace Artemis.Core
// Source
if (Entity.SourceDataModelGuid != null && SourceDataModel == null)
{
var dataModel = DataModelStore.Get(Entity.SourceDataModelGuid.Value)?.DataModel;
DataModel dataModel = DataModelStore.Get(Entity.SourceDataModelGuid.Value)?.DataModel;
if (dataModel != null && dataModel.ContainsPath(Entity.SourcePropertyPath))
UpdateSource(dataModel, Entity.SourcePropertyPath);
}
@@ -131,19 +131,19 @@ namespace Artemis.Core
private void CreateExpression()
{
var listType = SourceDataModel.GetListTypeInPath(SourcePropertyPath);
Type listType = SourceDataModel.GetListTypeInPath(SourcePropertyPath);
if (listType != null)
throw new ArtemisCoreException($"Cannot create a regular accessor at path {SourcePropertyPath} because the path contains a list");
var parameter = Expression.Parameter(typeof(DataModel), "targetDataModel");
var accessor = SourcePropertyPath.Split('.').Aggregate<string, Expression>(
ParameterExpression parameter = Expression.Parameter(typeof(DataModel), "targetDataModel");
Expression accessor = SourcePropertyPath.Split('.').Aggregate<string, Expression>(
Expression.Convert(parameter, SourceDataModel.GetType()), // Cast to the appropriate type
Expression.Property
);
var returnValue = Expression.Convert(accessor, typeof(object));
UnaryExpression returnValue = Expression.Convert(accessor, typeof(object));
var lambda = Expression.Lambda<Func<DataModel, object>>(returnValue, parameter);
Expression<Func<DataModel, object>> lambda = Expression.Lambda<Func<DataModel, object>>(returnValue, parameter);
CompiledTargetAccessor = lambda.Compile();
}
@@ -198,7 +198,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("DirectDataBinding");
var modifier = new DataBindingModifier<TLayerProperty, TProperty>(this, type);
DataBindingModifier<TLayerProperty, TProperty> modifier = new DataBindingModifier<TLayerProperty, TProperty>(this, type);
_modifiers.Add(modifier);
ApplyOrder();
@@ -230,9 +230,9 @@ namespace Artemis.Core
public void ApplyOrder()
{
_modifiers.Sort((a, b) => a.Order.CompareTo(b.Order));
for (var index = 0; index < _modifiers.Count; index++)
for (int index = 0; index < _modifiers.Count; index++)
{
var modifier = _modifiers[index];
DataBindingModifier<TLayerProperty, TProperty> modifier = _modifiers[index];
modifier.Order = index + 1;
}
}
@@ -243,7 +243,7 @@ namespace Artemis.Core
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
{
var dataModel = e.Registration.DataModel;
DataModel dataModel = e.Registration.DataModel;
if (dataModel.PluginInfo.Guid == Entity.SourceDataModelGuid && dataModel.ContainsPath(Entity.SourcePropertyPath))
UpdateSource(dataModel, Entity.SourcePropertyPath);
}
@@ -119,12 +119,12 @@ namespace Artemis.Core
if (IsStartSegment)
return null;
var propertyInfo = GetPropertyInfo();
PropertyInfo propertyInfo = GetPropertyInfo();
if (propertyInfo == null)
return null;
// Static types may have one as an attribute
var attribute = (DataModelPropertyAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(DataModelPropertyAttribute));
DataModelPropertyAttribute attribute = (DataModelPropertyAttribute) Attribute.GetCustomAttribute(propertyInfo, typeof(DataModelPropertyAttribute));
if (attribute != null)
{
if (string.IsNullOrWhiteSpace(attribute.Name))
@@ -145,12 +145,12 @@ namespace Artemis.Core
return DataModelPath.Target.GetType();
// Prefer basing the type on the property info
var propertyInfo = GetPropertyInfo();
var type = propertyInfo?.PropertyType;
PropertyInfo propertyInfo = GetPropertyInfo();
Type type = propertyInfo?.PropertyType;
// Property info is not available on dynamic paths though, so fall back on the current value
if (propertyInfo == null)
{
var currentValue = GetValue();
object currentValue = GetValue();
if (currentValue != null)
type = currentValue.GetType();
}
@@ -166,7 +166,7 @@ namespace Artemis.Core
return CreateExpression(parameter, expression, nullCondition);
}
var previousType = Previous.GetPropertyType();
Type previousType = Previous.GetPropertyType();
if (previousType == null)
{
Type = DataModelPathSegmentType.Invalid;
@@ -179,13 +179,13 @@ namespace Artemis.Core
// If no static type could be found, check if this is a data model and if so, look for a dynamic type
if (Type == DataModelPathSegmentType.Invalid && typeof(DataModel).IsAssignableFrom(previousType))
{
var dataModel = (DataModel) Previous.GetValue();
DataModel dataModel = (DataModel) Previous.GetValue();
// Cannot determine a dynamic type on a null data model, leave the segment invalid
if (dataModel == null)
return CreateExpression(parameter, expression, nullCondition);
// If a dynamic data model is found the use that
var hasDynamicDataModel = dataModel.DynamicDataModels.TryGetValue(Identifier, out var dynamicDataModel);
bool hasDynamicDataModel = dataModel.DynamicDataModels.TryGetValue(Identifier, out DataModel dynamicDataModel);
if (hasDynamicDataModel)
DetermineDynamicType(dynamicDataModel);
}
@@ -241,7 +241,7 @@ namespace Artemis.Core
private void DetermineStaticType(Type previousType)
{
var property = previousType.GetProperty(Identifier, BindingFlags.Public | BindingFlags.Instance);
PropertyInfo? property = previousType.GetProperty(Identifier, BindingFlags.Public | BindingFlags.Instance);
Type = property == null ? DataModelPathSegmentType.Invalid : DataModelPathSegmentType.Static;
}
}
+27 -27
View File
@@ -61,8 +61,8 @@ namespace Artemis.Core
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
var result = new List<ILayerProperty>();
foreach (var layerEffect in LayerEffects)
List<ILayerProperty> result = new List<ILayerProperty>();
foreach (BaseLayerEffect layerEffect in LayerEffects)
{
if (layerEffect.BaseProperties != null)
result.AddRange(layerEffect.BaseProperties.GetAllLayerProperties());
@@ -83,7 +83,7 @@ namespace Artemis.Core
return;
// Disable data bindings during an override
var wasApplyingDataBindings = ApplyDataBindingsEnabled;
bool wasApplyingDataBindings = ApplyDataBindingsEnabled;
ApplyDataBindingsEnabled = false;
UpdateDisplayCondition();
@@ -92,16 +92,16 @@ namespace Artemis.Core
// to it's start
UpdateTimeline(deltaTime);
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
{
baseLayerEffect.BaseProperties?.Update(deltaTime);
baseLayerEffect.Update(deltaTime);
}
// Iterate the children in reverse because that's how they must be rendered too
for (var index = Children.Count - 1; index > -1; index--)
for (int index = Children.Count - 1; index > -1; index--)
{
var profileElement = Children[index];
ProfileElement profileElement = Children[index];
profileElement.Update(deltaTime);
}
@@ -127,19 +127,19 @@ namespace Artemis.Core
if (!Enabled)
return;
var beginTime = TimelinePosition;
TimeSpan beginTime = TimelinePosition;
if (stickToMainSegment)
{
if (!DisplayContinuously)
{
var position = timeOverride + StartSegmentLength;
TimeSpan position = timeOverride + StartSegmentLength;
if (position > StartSegmentLength + EndSegmentLength)
TimelinePosition = StartSegmentLength + EndSegmentLength;
}
else
{
var progress = timeOverride.TotalMilliseconds % MainSegmentLength.TotalMilliseconds;
double progress = timeOverride.TotalMilliseconds % MainSegmentLength.TotalMilliseconds;
if (progress > 0)
TimelinePosition = TimeSpan.FromMilliseconds(progress) + StartSegmentLength;
else
@@ -149,9 +149,9 @@ namespace Artemis.Core
else
TimelinePosition = timeOverride;
var delta = (TimelinePosition - beginTime).TotalSeconds;
double delta = (TimelinePosition - beginTime).TotalSeconds;
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
{
baseLayerEffect.BaseProperties?.Update(delta);
baseLayerEffect.Update(delta);
@@ -178,24 +178,24 @@ namespace Artemis.Core
_folderBitmap = new SKBitmap(new SKImageInfo((int) Path.Bounds.Width, (int) Path.Bounds.Height));
}
using var folderPath = new SKPath(Path);
using var folderCanvas = new SKCanvas(_folderBitmap);
using var folderPaint = new SKPaint();
using SKPath folderPath = new SKPath(Path);
using SKCanvas folderCanvas = new SKCanvas(_folderBitmap);
using SKPaint folderPaint = new SKPaint();
folderCanvas.Clear();
folderPath.Transform(SKMatrix.MakeTranslation(folderPath.Bounds.Left * -1, folderPath.Bounds.Top * -1));
var targetLocation = Path.Bounds.Location;
SKPoint targetLocation = Path.Bounds.Location;
if (Parent is Folder parentFolder)
targetLocation -= parentFolder.Path.Bounds.Location;
canvas.Save();
using var clipPath = new SKPath(folderPath);
using SKPath clipPath = new SKPath(folderPath);
clipPath.Transform(SKMatrix.MakeTranslation(targetLocation.X, targetLocation.Y));
canvas.ClipPath(clipPath);
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PreProcess(folderCanvas, _folderBitmap.Info, folderPath, folderPaint);
// No point rendering if the alpha was set to zero by one of the effects
@@ -203,10 +203,10 @@ namespace Artemis.Core
return;
// Iterate the children in reverse because the first layer must be rendered last to end up on top
for (var index = Children.Count - 1; index > -1; index--)
for (int index = Children.Count - 1; index > -1; index--)
{
folderCanvas.Save();
var profileElement = Children[index];
ProfileElement profileElement = Children[index];
profileElement.Render(deltaTime, folderCanvas, _folderBitmap.Info);
folderCanvas.Restore();
}
@@ -214,11 +214,11 @@ namespace Artemis.Core
// If required, apply the opacity override of the module to the root folder
if (IsRootFolder && Profile.Module.OpacityOverride < 1)
{
var multiplier = Easings.SineEaseInOut(Profile.Module.OpacityOverride);
double multiplier = Easings.SineEaseInOut(Profile.Module.OpacityOverride);
folderPaint.Color = folderPaint.Color.WithAlpha((byte) (folderPaint.Color.Alpha * multiplier));
}
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PostProcess(canvas, canvasInfo, folderPath, folderPaint);
canvas.DrawBitmap(_folderBitmap, targetLocation, folderPaint);
@@ -257,8 +257,8 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Folder");
var path = new SKPath {FillType = SKPathFillType.Winding};
foreach (var child in Children)
SKPath path = new SKPath {FillType = SKPathFillType.Winding};
foreach (ProfileElement child in Children)
{
if (child is RenderProfileElement effectChild && effectChild.Path != null)
path.AddPath(effectChild.Path);
@@ -277,7 +277,7 @@ namespace Artemis.Core
{
_disposed = true;
foreach (var profileElement in Children)
foreach (ProfileElement profileElement in Children)
profileElement.Dispose();
_folderBitmap?.Dispose();
@@ -289,15 +289,15 @@ namespace Artemis.Core
_expandedPropertyGroups.AddRange(FolderEntity.ExpandedPropertyGroups);
// Load child folders
foreach (var childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId))
foreach (FolderEntity childFolder in Profile.ProfileEntity.Folders.Where(f => f.ParentId == EntityId))
ChildrenList.Add(new Folder(Profile, this, childFolder));
// Load child layers
foreach (var childLayer in Profile.ProfileEntity.Layers.Where(f => f.ParentId == EntityId))
foreach (LayerEntity childLayer in Profile.ProfileEntity.Layers.Where(f => f.ParentId == EntityId))
ChildrenList.Add(new Layer(Profile, this, childLayer));
// Ensure order integrity, should be unnecessary but no one is perfect specially me
ChildrenList = ChildrenList.OrderBy(c => c.Order).ToList();
for (var index = 0; index < ChildrenList.Count; index++)
for (int index = 0; index < ChildrenList.Count; index++)
ChildrenList[index].Order = index + 1;
LoadRenderElement();
+75 -75
View File
@@ -73,12 +73,12 @@ namespace Artemis.Core
/// <inheritdoc />
public override List<ILayerProperty> GetAllLayerProperties()
{
var result = new List<ILayerProperty>();
List<ILayerProperty> result = new List<ILayerProperty>();
result.AddRange(General.GetAllLayerProperties());
result.AddRange(Transform.GetAllLayerProperties());
if (LayerBrush?.BaseProperties != null)
result.AddRange(LayerBrush.BaseProperties.GetAllLayerProperties());
foreach (var layerEffect in LayerEffects)
foreach (BaseLayerEffect layerEffect in LayerEffects)
{
if (layerEffect.BaseProperties != null)
result.AddRange(layerEffect.BaseProperties.GetAllLayerProperties());
@@ -162,11 +162,11 @@ namespace Artemis.Core
LayerBrushStore.LayerBrushRemoved += LayerBrushStoreOnLayerBrushRemoved;
// Layers have two hardcoded property groups, instantiate them
var generalAttribute = Attribute.GetCustomAttribute(
Attribute? generalAttribute = Attribute.GetCustomAttribute(
GetType().GetProperty(nameof(General)),
typeof(PropertyGroupDescriptionAttribute)
);
var transformAttribute = Attribute.GetCustomAttribute(
Attribute? transformAttribute = Attribute.GetCustomAttribute(
GetType().GetProperty(nameof(Transform)),
typeof(PropertyGroupDescriptionAttribute)
);
@@ -214,9 +214,9 @@ namespace Artemis.Core
// LEDs
LayerEntity.Leds.Clear();
foreach (var artemisLed in Leds)
foreach (ArtemisLed artemisLed in Leds)
{
var ledEntity = new LedEntity
LedEntity ledEntity = new LedEntity
{
DeviceIdentifier = artemisLed.Device.RgbDevice.GetDeviceIdentifier(),
LedName = artemisLed.RgbLed.Id.ToString()
@@ -280,7 +280,7 @@ namespace Artemis.Core
LayerBrush.BaseProperties?.Update(deltaTime);
LayerBrush.Update(deltaTime);
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
{
baseLayerEffect.BaseProperties?.Update(deltaTime);
baseLayerEffect.Update(deltaTime);
@@ -301,10 +301,10 @@ namespace Artemis.Core
return;
// Disable data bindings during an override
var wasApplyingDataBindings = ApplyDataBindingsEnabled;
bool wasApplyingDataBindings = ApplyDataBindingsEnabled;
ApplyDataBindingsEnabled = false;
var beginTime = TimelinePosition;
TimeSpan beginTime = TimelinePosition;
if (stickToMainSegment)
{
@@ -312,7 +312,7 @@ namespace Artemis.Core
TimelinePosition = StartSegmentLength + timeOverride;
else
{
var progress = timeOverride.TotalMilliseconds % MainSegmentLength.TotalMilliseconds;
double progress = timeOverride.TotalMilliseconds % MainSegmentLength.TotalMilliseconds;
if (progress > 0)
TimelinePosition = TimeSpan.FromMilliseconds(progress) + StartSegmentLength;
else
@@ -322,14 +322,14 @@ namespace Artemis.Core
else
TimelinePosition = timeOverride;
var delta = (TimelinePosition - beginTime).TotalSeconds;
double delta = (TimelinePosition - beginTime).TotalSeconds;
General.Update(delta);
Transform.Update(delta);
LayerBrush.BaseProperties?.Update(delta);
LayerBrush.Update(delta);
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
{
baseLayerEffect.BaseProperties?.Update(delta);
baseLayerEffect.Update(delta);
@@ -363,9 +363,9 @@ namespace Artemis.Core
_layerBitmap = new SKBitmap(new SKImageInfo((int) Path.Bounds.Width, (int) Path.Bounds.Height));
}
using var layerPath = new SKPath(Path);
using var layerCanvas = new SKCanvas(_layerBitmap);
using var layerPaint = new SKPaint
using SKPath layerPath = new SKPath(Path);
using SKCanvas layerCanvas = new SKCanvas(_layerBitmap);
using SKPaint layerPaint = new SKPaint
{
FilterQuality = SKFilterQuality.Low,
Color = new SKColor(0, 0, 0, (byte) (Transform.Opacity.CurrentValue * 2.55f))
@@ -374,7 +374,7 @@ namespace Artemis.Core
layerPath.Transform(SKMatrix.MakeTranslation(layerPath.Bounds.Left * -1, layerPath.Bounds.Top * -1));
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PreProcess(layerCanvas, _layerBitmap.Info, layerPath, layerPaint);
// No point rendering if the alpha was set to zero by one of the effects
@@ -388,15 +388,15 @@ namespace Artemis.Core
else if (General.ResizeMode.CurrentValue == LayerResizeMode.Clip)
ClipRender(layerCanvas, _layerBitmap.Info, layerPaint, layerPath);
foreach (var baseLayerEffect in LayerEffects.Where(e => e.Enabled))
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
baseLayerEffect.PostProcess(layerCanvas, _layerBitmap.Info, layerPath, layerPaint);
var targetLocation = new SKPoint(0, 0);
SKPoint targetLocation = new SKPoint(0, 0);
if (Parent is Folder parentFolder)
targetLocation = Path.Bounds.Location - parentFolder.Path.Bounds.Location;
using var canvasPaint = new SKPaint {BlendMode = General.BlendMode.CurrentValue};
using var canvasPath = new SKPath(Path);
using SKPaint canvasPaint = new SKPaint {BlendMode = General.BlendMode.CurrentValue};
using SKPath canvasPath = new SKPath(Path);
canvasPath.Transform(SKMatrix.MakeTranslation(
(canvasPath.Bounds.Left - targetLocation.X) * -1,
(canvasPath.Bounds.Top - targetLocation.Y) * -1)
@@ -407,46 +407,46 @@ namespace Artemis.Core
private void SimpleRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint, SKPath layerPath)
{
using var renderPath = new SKPath(LayerShape.Path);
using SKPath renderPath = new SKPath(LayerShape.Path);
LayerBrush.InternalRender(canvas, canvasInfo, renderPath, paint);
}
private void StretchRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint, SKPath layerPath)
{
// Apply transformations
var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Transform.Rotation.CurrentValue;
SKSize sizeProperty = Transform.Scale.CurrentValue;
float rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition(layerPath);
var anchorProperty = Transform.AnchorPoint.CurrentValue;
SKPoint anchorPosition = GetLayerAnchorPosition(layerPath);
SKPoint anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
var x = anchorPosition.X - layerPath.Bounds.MidX - anchorProperty.X * layerPath.Bounds.Width;
var y = anchorPosition.Y - layerPath.Bounds.MidY - anchorProperty.Y * layerPath.Bounds.Height;
float x = anchorPosition.X - layerPath.Bounds.MidX - anchorProperty.X * layerPath.Bounds.Width;
float y = anchorPosition.Y - layerPath.Bounds.MidY - anchorProperty.Y * layerPath.Bounds.Height;
// Apply these before translation because anchorPosition takes translation into account
canvas.RotateDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y);
canvas.Scale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y);
canvas.Translate(x, y);
using var renderPath = new SKPath(LayerShape.Path);
using SKPath renderPath = new SKPath(LayerShape.Path);
LayerBrush.InternalRender(canvas, canvasInfo, renderPath, paint);
}
private void ClipRender(SKCanvas canvas, SKImageInfo canvasInfo, SKPaint paint, SKPath layerPath)
{
// Apply transformation
var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Transform.Rotation.CurrentValue;
SKSize sizeProperty = Transform.Scale.CurrentValue;
float rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition(layerPath);
var anchorProperty = Transform.AnchorPoint.CurrentValue;
SKPoint anchorPosition = GetLayerAnchorPosition(layerPath);
SKPoint anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
var x = anchorPosition.X - layerPath.Bounds.MidX - anchorProperty.X * layerPath.Bounds.Width;
var y = anchorPosition.Y - layerPath.Bounds.MidY - anchorProperty.Y * layerPath.Bounds.Height;
float x = anchorPosition.X - layerPath.Bounds.MidX - anchorProperty.X * layerPath.Bounds.Width;
float y = anchorPosition.Y - layerPath.Bounds.MidY - anchorProperty.Y * layerPath.Bounds.Height;
using var clipPath = new SKPath(LayerShape.Path);
using SKPath clipPath = new SKPath(LayerShape.Path);
clipPath.Transform(SKMatrix.MakeTranslation(x, y));
clipPath.Transform(SKMatrix.MakeScale(sizeProperty.Width / 100f, sizeProperty.Height / 100f, anchorPosition.X, anchorPosition.Y));
clipPath.Transform(SKMatrix.MakeRotationDegrees(rotationProperty, anchorPosition.X, anchorPosition.Y));
@@ -457,13 +457,13 @@ namespace Artemis.Core
// Render the layer in the largest required bounds, this still creates stretching in some situations
// but the only alternative I see right now is always forcing brushes to render on the entire canvas
var boundsRect = new SKRect(
SKRect boundsRect = new SKRect(
Math.Min(clipPath.Bounds.Left - x, Bounds.Left - x),
Math.Min(clipPath.Bounds.Top - y, Bounds.Top - y),
Math.Max(clipPath.Bounds.Right - x, Bounds.Right - x),
Math.Max(clipPath.Bounds.Bottom - y, Bounds.Bottom - y)
);
using var renderPath = new SKPath();
using SKPath renderPath = new SKPath();
renderPath.AddRect(boundsRect);
LayerBrush.InternalRender(canvas, canvasInfo, renderPath, paint);
@@ -478,8 +478,8 @@ namespace Artemis.Core
Path = new SKPath();
else
{
var path = new SKPath {FillType = SKPathFillType.Winding};
foreach (var artemisLed in Leds)
SKPath path = new SKPath {FillType = SKPathFillType.Winding};
foreach (ArtemisLed artemisLed in Leds)
path.AddRect(artemisLed.AbsoluteRenderRectangle);
Path = path;
@@ -501,10 +501,10 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Layer");
var positionProperty = Transform.Position.CurrentValue;
SKPoint positionProperty = Transform.Position.CurrentValue;
// Start at the center of the shape
var position = zeroBased
SKPoint position = zeroBased
? new SKPoint(layerPath.Bounds.MidX - layerPath.Bounds.Left, layerPath.Bounds.MidY - layerPath.Bounds.Top)
: new SKPoint(layerPath.Bounds.MidX, layerPath.Bounds.MidY);
@@ -525,15 +525,15 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Layer");
var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Transform.Rotation.CurrentValue;
SKSize sizeProperty = Transform.Scale.CurrentValue;
float rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition(Path, zeroBased);
var anchorProperty = Transform.AnchorPoint.CurrentValue;
SKPoint anchorPosition = GetLayerAnchorPosition(Path, zeroBased);
SKPoint anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
var x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
var y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
float x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
float y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
if (General.ResizeMode == LayerResizeMode.Normal)
{
@@ -557,18 +557,18 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Layer");
var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Transform.Rotation.CurrentValue;
SKSize sizeProperty = Transform.Scale.CurrentValue;
float rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition(Path, zeroBased);
var anchorProperty = Transform.AnchorPoint.CurrentValue;
SKPoint anchorPosition = GetLayerAnchorPosition(Path, zeroBased);
SKPoint anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
var x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
var y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
float x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
float y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
var reversedXScale = 1f / (sizeProperty.Width / 100f);
var reversedYScale = 1f / (sizeProperty.Height / 100f);
float reversedXScale = 1f / (sizeProperty.Width / 100f);
float reversedYScale = 1f / (sizeProperty.Height / 100f);
if (General.ResizeMode == LayerResizeMode.Normal)
{
@@ -593,18 +593,18 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Layer");
var sizeProperty = Transform.Scale.CurrentValue;
var rotationProperty = Transform.Rotation.CurrentValue;
SKSize sizeProperty = Transform.Scale.CurrentValue;
float rotationProperty = Transform.Rotation.CurrentValue;
var anchorPosition = GetLayerAnchorPosition(Path, zeroBased);
var anchorProperty = Transform.AnchorPoint.CurrentValue;
SKPoint anchorPosition = GetLayerAnchorPosition(Path, zeroBased);
SKPoint anchorProperty = Transform.AnchorPoint.CurrentValue;
// Translation originates from the unscaled center of the shape and is tied to the anchor
var x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
var y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
float x = anchorPosition.X - (zeroBased ? Bounds.MidX - Bounds.Left : Bounds.MidX) - anchorProperty.X * Bounds.Width;
float y = anchorPosition.Y - (zeroBased ? Bounds.MidY - Bounds.Top : Bounds.MidY) - anchorProperty.Y * Bounds.Height;
var reversedXScale = 1f / (sizeProperty.Width / 100f);
var reversedYScale = 1f / (sizeProperty.Height / 100f);
float reversedXScale = 1f / (sizeProperty.Width / 100f);
float reversedYScale = 1f / (sizeProperty.Height / 100f);
if (General.ResizeMode == LayerResizeMode.Normal)
{
@@ -680,14 +680,14 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Layer");
var leds = new List<ArtemisLed>();
List<ArtemisLed> leds = new List<ArtemisLed>();
// Get the surface LEDs for this layer
var availableLeds = surface.Devices.SelectMany(d => d.Leds).ToList();
foreach (var ledEntity in LayerEntity.Leds)
List<ArtemisLed> availableLeds = surface.Devices.SelectMany(d => d.Leds).ToList();
foreach (LedEntity ledEntity in LayerEntity.Leds)
{
var match = availableLeds.FirstOrDefault(a => a.Device.RgbDevice.GetDeviceIdentifier() == ledEntity.DeviceIdentifier &&
a.RgbLed.Id.ToString() == ledEntity.LedName);
ArtemisLed match = availableLeds.FirstOrDefault(a => a.Device.RgbDevice.GetDeviceIdentifier() == ledEntity.DeviceIdentifier &&
a.RgbLed.Id.ToString() == ledEntity.LedName);
if (match != null)
leds.Add(match);
}
@@ -710,13 +710,13 @@ namespace Artemis.Core
if (LayerBrush != null)
{
var brush = LayerBrush;
BaseLayerBrush brush = LayerBrush;
LayerBrush = null;
brush.Dispose();
}
// Ensure the brush reference matches the brush
var current = General.BrushReference.BaseValue;
LayerBrushReference current = General.BrushReference.BaseValue;
if (!descriptor.MatchesLayerBrushReference(current))
General.BrushReference.BaseValue = new LayerBrushReference(descriptor);
@@ -731,18 +731,18 @@ namespace Artemis.Core
if (LayerBrush == null)
return;
var brush = LayerBrush;
BaseLayerBrush brush = LayerBrush;
DeactivateLayerBrush();
LayerEntity.PropertyEntities.RemoveAll(p => p.PluginGuid == brush.PluginInfo.Guid && p.Path.StartsWith("LayerBrush."));
}
internal void ActivateLayerBrush()
{
var current = General.BrushReference.CurrentValue;
LayerBrushReference current = General.BrushReference.CurrentValue;
if (current == null)
return;
var descriptor = LayerBrushStore.Get(current.BrushPluginGuid, current.BrushType)?.LayerBrushDescriptor;
LayerBrushDescriptor descriptor = LayerBrushStore.Get(current.BrushPluginGuid, current.BrushType)?.LayerBrushDescriptor;
descriptor?.CreateInstance(this);
OnLayerBrushUpdated();
@@ -753,7 +753,7 @@ namespace Artemis.Core
if (LayerBrush == null)
return;
var brush = LayerBrush;
BaseLayerBrush brush = LayerBrush;
LayerBrush = null;
brush.Dispose();
@@ -775,7 +775,7 @@ namespace Artemis.Core
if (LayerBrush != null || General.BrushReference?.CurrentValue == null)
return;
var current = General.BrushReference.CurrentValue;
LayerBrushReference current = General.BrushReference.CurrentValue;
if (e.Registration.Plugin.PluginInfo.Guid == current.BrushPluginGuid &&
e.Registration.LayerBrushDescriptor.LayerBrushType.Name == current.BrushType)
ActivateLayerBrush();
@@ -56,7 +56,7 @@ namespace Artemis.Core
{
_disposed = true;
foreach (var dataBinding in _dataBindings)
foreach (IDataBinding dataBinding in _dataBindings)
dataBinding.Dispose();
}
@@ -158,7 +158,7 @@ namespace Artemis.Core
else
{
// If on a keyframe, update the keyframe
var currentKeyframe = Keyframes.FirstOrDefault(k => k.Position == time.Value);
LayerPropertyKeyframe<T> currentKeyframe = Keyframes.FirstOrDefault(k => k.Position == time.Value);
// Create a new keyframe if none found
if (currentKeyframe == null)
AddKeyframe(new LayerPropertyKeyframe<T>(value, time.Value, Easings.Functions.Linear, this));
@@ -256,7 +256,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("LayerProperty");
var newKeyframe = new LayerPropertyKeyframe<T>(
LayerPropertyKeyframe<T> newKeyframe = new LayerPropertyKeyframe<T>(
keyframe.Value,
keyframe.Position,
keyframe.EasingFunction,
@@ -301,7 +301,7 @@ namespace Artemis.Core
// The current keyframe is the last keyframe before the current time
CurrentKeyframe = _keyframes.LastOrDefault(k => k.Position <= ProfileElement.TimelinePosition);
// Keyframes are sorted by position so we can safely assume the next keyframe's position is after the current
var nextIndex = _keyframes.IndexOf(CurrentKeyframe) + 1;
int nextIndex = _keyframes.IndexOf(CurrentKeyframe) + 1;
NextKeyframe = _keyframes.Count > nextIndex ? _keyframes[nextIndex] : null;
// No need to update the current value if either of the keyframes are null
@@ -312,9 +312,9 @@ namespace Artemis.Core
// Only determine progress and current value if both keyframes are present
else
{
var timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
var keyframeProgress = (float) ((ProfileElement.TimelinePosition - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
var keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
TimeSpan timeDiff = NextKeyframe.Position - CurrentKeyframe.Position;
float keyframeProgress = (float) ((ProfileElement.TimelinePosition - CurrentKeyframe.Position).TotalMilliseconds / timeDiff.TotalMilliseconds);
float keyframeProgressEased = (float) Easings.Interpolate(keyframeProgress, CurrentKeyframe.EasingFunction);
UpdateCurrentValue(keyframeProgress, keyframeProgressEased);
}
}
@@ -350,8 +350,8 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("LayerProperty");
var match = _dataBindingRegistrations.FirstOrDefault(r => r is DataBindingRegistration<T, TProperty> registration &&
registration.PropertyExpression.ToString() == expression);
IDataBindingRegistration match = _dataBindingRegistrations.FirstOrDefault(r => r is DataBindingRegistration<T, TProperty> registration &&
registration.PropertyExpression.ToString() == expression);
return (DataBindingRegistration<T, TProperty>) match;
}
@@ -392,7 +392,7 @@ namespace Artemis.Core
if (dataBindingRegistration.DataBinding != null)
throw new ArtemisCoreException("Provided data binding registration already has an enabled data binding");
var dataBinding = new DataBinding<T, TProperty>(dataBindingRegistration);
DataBinding<T, TProperty> dataBinding = new DataBinding<T, TProperty>(dataBindingRegistration);
_dataBindings.Add(dataBinding);
OnDataBindingEnabled(new LayerPropertyEventArgs<T>(dataBinding.LayerProperty));
@@ -417,7 +417,7 @@ namespace Artemis.Core
private void UpdateDataBindings(double deltaTime)
{
foreach (var dataBinding in _dataBindings)
foreach (IDataBinding dataBinding in _dataBindings)
{
dataBinding.Update(deltaTime);
dataBinding.Apply();
@@ -497,9 +497,9 @@ namespace Artemis.Core
}
_dataBindings.Clear();
foreach (var dataBindingRegistration in _dataBindingRegistrations)
foreach (IDataBindingRegistration dataBindingRegistration in _dataBindingRegistrations)
{
var dataBinding = dataBindingRegistration.CreateDataBinding();
IDataBinding dataBinding = dataBindingRegistration.CreateDataBinding();
if (dataBinding != null)
_dataBindings.Add(dataBinding);
}
@@ -528,7 +528,7 @@ namespace Artemis.Core
}));
Entity.DataBindingEntities.Clear();
foreach (var dataBinding in _dataBindings)
foreach (IDataBinding dataBinding in _dataBindings)
dataBinding.Save();
}
@@ -95,9 +95,9 @@ namespace Artemis.Core
_disposed = true;
DisableProperties();
foreach (var layerProperty in _layerProperties)
foreach (ILayerProperty layerProperty in _layerProperties)
layerProperty.Dispose();
foreach (var layerPropertyGroup in _layerPropertyGroups)
foreach (LayerPropertyGroup layerPropertyGroup in _layerPropertyGroups)
layerPropertyGroup.Dispose();
}
@@ -114,8 +114,8 @@ namespace Artemis.Core
if (!PropertiesInitialized)
return new List<ILayerProperty>();
var result = new List<ILayerProperty>(LayerProperties);
foreach (var layerPropertyGroup in LayerPropertyGroups)
List<ILayerProperty> result = new List<ILayerProperty>(LayerProperties);
foreach (LayerPropertyGroup layerPropertyGroup in LayerPropertyGroups)
result.AddRange(layerPropertyGroup.GetAllLayerProperties());
return result.AsReadOnly();
@@ -161,14 +161,14 @@ namespace Artemis.Core
Path = path.TrimEnd('.');
// Get all properties with a PropertyDescriptionAttribute
foreach (var propertyInfo in GetType().GetProperties())
foreach (PropertyInfo propertyInfo in GetType().GetProperties())
{
var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute));
Attribute? propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute));
if (propertyDescription != null)
InitializeProperty(propertyInfo, (PropertyDescriptionAttribute) propertyDescription);
else
{
var propertyGroupDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyGroupDescriptionAttribute));
Attribute? propertyGroupDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyGroupDescriptionAttribute));
if (propertyGroupDescription != null)
InitializeChildGroup(propertyInfo, (PropertyGroupDescriptionAttribute) propertyGroupDescription);
}
@@ -178,7 +178,7 @@ namespace Artemis.Core
PopulateDefaults();
// Load the layer properties after defaults have been applied
foreach (var layerProperty in _layerProperties)
foreach (ILayerProperty layerProperty in _layerProperties)
layerProperty.Load();
EnableProperties();
@@ -191,10 +191,10 @@ namespace Artemis.Core
if (!PropertiesInitialized)
return;
foreach (var layerProperty in LayerProperties)
foreach (ILayerProperty layerProperty in LayerProperties)
layerProperty.Save();
foreach (var layerPropertyGroup in LayerPropertyGroups)
foreach (LayerPropertyGroup layerPropertyGroup in LayerPropertyGroups)
layerPropertyGroup.ApplyToEntity();
}
@@ -207,12 +207,12 @@ namespace Artemis.Core
private void InitializeProperty(PropertyInfo propertyInfo, PropertyDescriptionAttribute propertyDescription)
{
var path = $"{Path}.{propertyInfo.Name}";
string path = $"{Path}.{propertyInfo.Name}";
if (!typeof(ILayerProperty).IsAssignableFrom(propertyInfo.PropertyType))
throw new ArtemisPluginException($"Layer property with PropertyDescription attribute must be of type LayerProperty at {path}");
var instance = (ILayerProperty) Activator.CreateInstance(propertyInfo.PropertyType, true);
ILayerProperty instance = (ILayerProperty) Activator.CreateInstance(propertyInfo.PropertyType, true);
if (instance == null)
throw new ArtemisPluginException($"Failed to create instance of layer property at {path}");
@@ -220,7 +220,7 @@ namespace Artemis.Core
if (string.IsNullOrWhiteSpace(propertyDescription.Name))
propertyDescription.Name = propertyInfo.Name.Humanize();
var entity = GetPropertyEntity(ProfileElement, path, out var fromStorage);
PropertyEntity entity = GetPropertyEntity(ProfileElement, path, out bool fromStorage);
instance.Initialize(ProfileElement, this, entity, fromStorage, propertyDescription, path);
propertyInfo.SetValue(this, instance);
_layerProperties.Add(instance);
@@ -228,12 +228,12 @@ namespace Artemis.Core
private void InitializeChildGroup(PropertyInfo propertyInfo, PropertyGroupDescriptionAttribute propertyGroupDescription)
{
var path = Path + ".";
string path = Path + ".";
if (!typeof(LayerPropertyGroup).IsAssignableFrom(propertyInfo.PropertyType))
throw new ArtemisPluginException("Layer property with PropertyGroupDescription attribute must be of type LayerPropertyGroup");
var instance = (LayerPropertyGroup) Activator.CreateInstance(propertyInfo.PropertyType);
LayerPropertyGroup instance = (LayerPropertyGroup) Activator.CreateInstance(propertyInfo.PropertyType);
if (instance == null)
throw new ArtemisPluginException($"Failed to create instance of layer property group at {path + propertyInfo.Name}");
@@ -253,7 +253,7 @@ namespace Artemis.Core
private PropertyEntity GetPropertyEntity(RenderProfileElement profileElement, string path, out bool fromStorage)
{
var entity = profileElement.RenderElementEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == PluginInfo.Guid && p.Path == path);
PropertyEntity entity = profileElement.RenderElementEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == PluginInfo.Guid && p.Path == path);
fromStorage = entity != null;
if (entity == null)
{
@@ -14,7 +14,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override void CalculateRenderProperties()
{
var path = new SKPath();
SKPath path = new SKPath();
path.AddOval(SKRect.Create(Layer.Bounds.Width, Layer.Bounds.Height));
Path = path;
}
@@ -14,7 +14,7 @@ namespace Artemis.Core
/// <inheritdoc />
public override void CalculateRenderProperties()
{
var path = new SKPath();
SKPath path = new SKPath();
path.AddRect(SKRect.Create(Layer.Bounds.Width, Layer.Bounds.Height));
Path = path;
}
+9 -9
View File
@@ -22,7 +22,7 @@ namespace Artemis.Core
UndoStack = new Stack<string>();
RedoStack = new Stack<string>();
var _ = new Folder(this, "Root folder");
Folder _ = new Folder(this, "Root folder");
Save();
}
@@ -61,7 +61,7 @@ namespace Artemis.Core
if (!IsActivated)
throw new ArtemisCoreException($"Cannot update inactive profile: {this}");
foreach (var profileElement in Children)
foreach (ProfileElement profileElement in Children)
profileElement.Update(deltaTime);
}
}
@@ -75,7 +75,7 @@ namespace Artemis.Core
if (!IsActivated)
throw new ArtemisCoreException($"Cannot render inactive profile: {this}");
foreach (var profileElement in Children)
foreach (ProfileElement profileElement in Children)
profileElement.Render(deltaTime, canvas, canvasInfo);
}
}
@@ -98,15 +98,15 @@ namespace Artemis.Core
lock (ChildrenList)
{
// Remove the old profile tree
foreach (var profileElement in Children)
foreach (ProfileElement profileElement in Children)
profileElement.Dispose();
ChildrenList.Clear();
// Populate the profile starting at the root, the rest is populated recursively
var rootFolder = ProfileEntity.Folders.FirstOrDefault(f => f.ParentId == EntityId);
FolderEntity rootFolder = ProfileEntity.Folders.FirstOrDefault(f => f.ParentId == EntityId);
if (rootFolder == null)
{
var _ = new Folder(this, "Root folder");
Folder _ = new Folder(this, "Root folder");
}
else
AddChild(new Folder(this, this, rootFolder));
@@ -125,7 +125,7 @@ namespace Artemis.Core
OnDeactivating();
foreach (var profileElement in Children)
foreach (ProfileElement profileElement in Children)
profileElement.Dispose();
ChildrenList.Clear();
@@ -143,7 +143,7 @@ namespace Artemis.Core
ProfileEntity.Name = Name;
ProfileEntity.IsActive = IsActivated;
foreach (var profileElement in Children)
foreach (ProfileElement profileElement in Children)
profileElement.Save();
ProfileEntity.Folders.Clear();
@@ -173,7 +173,7 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException("Profile");
foreach (var layer in GetAllLayers())
foreach (Layer layer in GetAllLayers())
layer.PopulateLeds(surface);
}
@@ -125,7 +125,7 @@ namespace Artemis.Core
// Shift everything after the given order
else
{
foreach (var profileElement in ChildrenList.Where(c => c.Order >= order).ToList())
foreach (ProfileElement profileElement in ChildrenList.Where(c => c.Order >= order).ToList())
profileElement.Order++;
int targetIndex;
@@ -160,7 +160,7 @@ namespace Artemis.Core
ChildrenList.Remove(child);
// Shift everything after the given order
foreach (var profileElement in ChildrenList.Where(c => c.Order > child.Order).ToList())
foreach (ProfileElement profileElement in ChildrenList.Where(c => c.Order > child.Order).ToList())
profileElement.Order--;
child.Parent = null;
@@ -178,8 +178,8 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException(GetType().Name);
var folders = new List<Folder>();
foreach (var childFolder in Children.Where(c => c is Folder).Cast<Folder>())
List<Folder> folders = new List<Folder>();
foreach (Folder childFolder in Children.Where(c => c is Folder).Cast<Folder>())
{
// Add all folders in this element
folders.Add(childFolder);
@@ -199,13 +199,13 @@ namespace Artemis.Core
if (_disposed)
throw new ObjectDisposedException(GetType().Name);
var layers = new List<Layer>();
List<Layer> layers = new List<Layer>();
// Add all layers in this element
layers.AddRange(Children.Where(c => c is Layer).Cast<Layer>());
// Add all layers in folders inside this element
foreach (var childFolder in Children.Where(c => c is Folder).Cast<Folder>())
foreach (Folder childFolder in Children.Where(c => c is Folder).Cast<Folder>())
layers.AddRange(childFolder.GetAllLayers());
return layers;
@@ -31,7 +31,7 @@ namespace Artemis.Core
LayerEffectStore.LayerEffectAdded -= LayerEffectStoreOnLayerEffectAdded;
LayerEffectStore.LayerEffectRemoved -= LayerEffectStoreOnLayerEffectRemoved;
foreach (var baseLayerEffect in LayerEffects)
foreach (BaseLayerEffect baseLayerEffect in LayerEffects)
baseLayerEffect.Dispose();
base.Dispose(disposing);
@@ -68,9 +68,9 @@ namespace Artemis.Core
RenderElementEntity.AlwaysFinishTimeline = AlwaysFinishTimeline;
RenderElementEntity.LayerEffects.Clear();
foreach (var layerEffect in LayerEffects)
foreach (BaseLayerEffect layerEffect in LayerEffects)
{
var layerEffectEntity = new LayerEffectEntity
LayerEffectEntity layerEffectEntity = new LayerEffectEntity
{
Id = layerEffect.EntityId,
PluginGuid = layerEffect.Descriptor.PlaceholderFor ?? layerEffect.PluginInfo.Guid,
@@ -228,9 +228,9 @@ namespace Artemis.Core
protected double UpdateTimeline(double deltaTime)
{
var oldPosition = _timelinePosition;
var deltaTimeSpan = TimeSpan.FromSeconds(deltaTime);
var mainSegmentEnd = StartSegmentLength + MainSegmentLength;
TimeSpan oldPosition = _timelinePosition;
TimeSpan deltaTimeSpan = TimeSpan.FromSeconds(deltaTime);
TimeSpan mainSegmentEnd = StartSegmentLength + MainSegmentLength;
TimelinePosition += deltaTimeSpan;
// Manage segments while the condition is met
@@ -278,7 +278,7 @@ namespace Artemis.Core
if (descriptor == null)
throw new ArgumentNullException(nameof(descriptor));
var entity = new LayerEffectEntity
LayerEffectEntity entity = new LayerEffectEntity
{
Id = Guid.NewGuid(),
Enabled = true,
@@ -309,8 +309,8 @@ namespace Artemis.Core
private void OrderEffects()
{
var index = 0;
foreach (var baseLayerEffect in LayerEffects.OrderBy(e => e.Order))
int index = 0;
foreach (BaseLayerEffect baseLayerEffect in LayerEffects.OrderBy(e => e.Order))
{
baseLayerEffect.Order = Order = index + 1;
index++;
@@ -321,14 +321,14 @@ namespace Artemis.Core
internal void ActivateEffects()
{
foreach (var layerEffectEntity in RenderElementEntity.LayerEffects)
foreach (LayerEffectEntity layerEffectEntity in RenderElementEntity.LayerEffects)
{
// If there is a non-placeholder existing effect, skip this entity
var existing = _layerEffects.FirstOrDefault(e => e.EntityId == layerEffectEntity.Id);
BaseLayerEffect existing = _layerEffects.FirstOrDefault(e => e.EntityId == layerEffectEntity.Id);
if (existing != null && existing.Descriptor.PlaceholderFor == null)
continue;
var descriptor = LayerEffectStore.Get(layerEffectEntity.PluginGuid, layerEffectEntity.EffectType)?.LayerEffectDescriptor;
LayerEffectDescriptor descriptor = LayerEffectStore.Get(layerEffectEntity.PluginGuid, layerEffectEntity.EffectType)?.LayerEffectDescriptor;
if (descriptor != null)
{
// If a descriptor is found but there is an existing placeholder, remove the placeholder
@@ -362,15 +362,15 @@ namespace Artemis.Core
private void LayerEffectStoreOnLayerEffectRemoved(object sender, LayerEffectStoreEvent e)
{
// If effects provided by the plugin are on the element, replace them with placeholders
var pluginEffects = _layerEffects.Where(ef => ef.Descriptor.LayerEffectProvider != null &&
ef.PluginInfo.Guid == e.Registration.Plugin.PluginInfo.Guid).ToList();
foreach (var pluginEffect in pluginEffects)
List<BaseLayerEffect> pluginEffects = _layerEffects.Where(ef => ef.Descriptor.LayerEffectProvider != null &&
ef.PluginInfo.Guid == e.Registration.Plugin.PluginInfo.Guid).ToList();
foreach (BaseLayerEffect pluginEffect in pluginEffects)
{
var entity = RenderElementEntity.LayerEffects.First(en => en.Id == pluginEffect.EntityId);
LayerEffectEntity entity = RenderElementEntity.LayerEffects.First(en => en.Id == pluginEffect.EntityId);
_layerEffects.Remove(pluginEffect);
pluginEffect.Dispose();
var descriptor = PlaceholderLayerEffectDescriptor.Create(pluginEffect.PluginInfo.Guid);
LayerEffectDescriptor descriptor = PlaceholderLayerEffectDescriptor.Create(pluginEffect.PluginInfo.Guid);
descriptor.CreateInstance(this, entity);
}
}
@@ -420,7 +420,7 @@ namespace Artemis.Core
public void UpdateDisplayCondition()
{
var conditionMet = DisplayCondition == null || DisplayCondition.Evaluate();
bool conditionMet = DisplayCondition == null || DisplayCondition.Evaluate();
if (conditionMet && !DisplayConditionMet)
TimelinePosition = TimeSpan.Zero;