1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Data model - Improved encapsulation

Conditions - Renamed from DisplayConditions to DataModelConditions to better match their nature
Core - More documentation
This commit is contained in:
SpoinkyNL 2020-09-19 11:43:49 +02:00
parent 6b93b1c878
commit a646ff95ed
39 changed files with 581 additions and 355 deletions

View File

@ -2,9 +2,16 @@
namespace Artemis.Core.DefaultTypes
{
/// <inheritdoc />
/// <summary>
/// Represents a generic data binding converter that acts as the bridge between a
/// <see cref="DataBinding{TLayerProperty, TProperty}" /> and a <see cref="LayerProperty{T}" /> and does not support
/// sum or interpolation
/// </summary>
public class GeneralDataBindingConverter<T> : DataBindingConverter<T, object> where T : ILayerProperty
{
/// <summary>
/// Creates a new instance of the <see cref="GeneralDataBindingConverter{T}" /> class
/// </summary>
public GeneralDataBindingConverter()
{
SupportsSum = false;

View File

@ -8,43 +8,43 @@ namespace Artemis.Core
/// <summary>
/// An abstract class for display condition parts
/// </summary>
public abstract class DisplayConditionPart : IDisposable
public abstract class DataModelConditionPart : IDisposable
{
private readonly List<DisplayConditionPart> _children = new List<DisplayConditionPart>();
private readonly List<DataModelConditionPart> _children = new List<DataModelConditionPart>();
/// <summary>
/// Gets the parent of this part
/// </summary>
public DisplayConditionPart Parent { get; internal set; }
public DataModelConditionPart Parent { get; internal set; }
/// <summary>
/// Gets the children of this part
/// </summary>
public IReadOnlyList<DisplayConditionPart> Children => _children.AsReadOnly();
public IReadOnlyList<DataModelConditionPart> Children => _children.AsReadOnly();
/// <summary>
/// Adds a child to the display condition part's <see cref="Children" /> collection
/// </summary>
/// <param name="displayConditionPart"></param>
public void AddChild(DisplayConditionPart displayConditionPart)
/// <param name="dataModelConditionPart"></param>
public void AddChild(DataModelConditionPart dataModelConditionPart)
{
if (!_children.Contains(displayConditionPart))
if (!_children.Contains(dataModelConditionPart))
{
displayConditionPart.Parent = this;
_children.Add(displayConditionPart);
dataModelConditionPart.Parent = this;
_children.Add(dataModelConditionPart);
}
}
/// <summary>
/// Removes a child from the display condition part's <see cref="Children" /> collection
/// </summary>
/// <param name="displayConditionPart">The child to remove</param>
public void RemoveChild(DisplayConditionPart displayConditionPart)
/// <param name="dataModelConditionPart">The child to remove</param>
public void RemoveChild(DataModelConditionPart dataModelConditionPart)
{
if (_children.Contains(displayConditionPart))
if (_children.Contains(dataModelConditionPart))
{
displayConditionPart.Parent = null;
_children.Remove(displayConditionPart);
dataModelConditionPart.Parent = null;
_children.Remove(dataModelConditionPart);
}
}
@ -59,13 +59,16 @@ namespace Artemis.Core
/// </summary>
/// <param name="target"></param>
/// <returns></returns>
public abstract bool EvaluateObject(object target);
internal abstract bool EvaluateObject(object target);
internal abstract void Save();
internal abstract DisplayConditionPartEntity GetEntity();
#region IDisposable
/// <summary>
/// Disposed the condition part
/// </summary>
protected virtual void Dispose(bool disposing)
{
if (disposing)
@ -73,6 +76,7 @@ namespace Artemis.Core
}
}
/// <inheritdoc />
public void Dispose()
{
Dispose(true);

View File

@ -6,29 +6,29 @@ using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core
{
/// <summary>
/// A group containing zero to many <see cref="DisplayConditionPart" />s which it evaluates using a boolean specific
/// A group containing zero to many <see cref="DataModelConditionPart" />s which it evaluates using a boolean specific
/// operator
/// </summary>
public class DisplayConditionGroup : DisplayConditionPart
public class DataModelConditionGroup : DataModelConditionPart
{
private bool _disposed;
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class
/// Creates a new instance of the <see cref="DataModelConditionGroup" /> class
/// </summary>
/// <param name="parent"></param>
public DisplayConditionGroup(DisplayConditionPart parent)
public DataModelConditionGroup(DataModelConditionPart parent)
{
Parent = parent;
Entity = new DisplayConditionGroupEntity();
}
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class
/// Creates a new instance of the <see cref="DataModelConditionGroup" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="entity"></param>
public DisplayConditionGroup(DisplayConditionPart parent, DisplayConditionGroupEntity entity)
public DataModelConditionGroup(DataModelConditionPart parent, DisplayConditionGroupEntity entity)
{
Parent = parent;
Entity = entity;
@ -37,13 +37,13 @@ namespace Artemis.Core
foreach (var childEntity in Entity.Children)
{
if (childEntity is DisplayConditionGroupEntity groupEntity)
AddChild(new DisplayConditionGroup(this, groupEntity));
AddChild(new DataModelConditionGroup(this, groupEntity));
else if (childEntity is DisplayConditionListEntity listEntity)
AddChild(new DisplayConditionList(this, listEntity));
AddChild(new DataModelConditionList(this, listEntity));
else if (childEntity is DisplayConditionPredicateEntity predicateEntity)
AddChild(new DisplayConditionPredicate(this, predicateEntity));
AddChild(new DataModelConditionPredicate(this, predicateEntity));
else if (childEntity is DisplayConditionListPredicateEntity listPredicateEntity)
AddChild(new DisplayConditionListPredicate(this, listPredicateEntity));
AddChild(new DataModelConditionListPredicate(this, listPredicateEntity));
}
}
@ -82,8 +82,22 @@ namespace Artemis.Core
}
}
#region IDisposable
/// <inheritdoc />
public override bool EvaluateObject(object target)
protected override void Dispose(bool disposing)
{
_disposed = true;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
/// <inheritdoc />
internal override bool EvaluateObject(object target)
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionGroup");
@ -119,26 +133,31 @@ namespace Artemis.Core
{
return Entity;
}
#region IDisposable
protected override void Dispose(bool disposing)
{
_disposed = true;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
}
/// <summary>
/// Represents a boolean operator
/// </summary>
public enum BooleanOperator
{
/// <summary>
/// All the conditions in the group should evaluate to true
/// </summary>
And,
/// <summary>
/// Any of the conditions in the group should evaluate to true
/// </summary>
Or,
/// <summary>
/// All the conditions in the group should evaluate to false
/// </summary>
AndNot,
/// <summary>
/// Any of the conditions in the group should evaluate to false
/// </summary>
OrNot
}
}

View File

@ -8,11 +8,18 @@ using Artemis.Storage.Entities.Profile.Conditions;
namespace Artemis.Core
{
public class DisplayConditionList : DisplayConditionPart
/// <summary>
/// A condition that evaluates one or more predicates inside a list
/// </summary>
public class DataModelConditionList : DataModelConditionPart
{
private bool _disposed;
public DisplayConditionList(DisplayConditionPart parent)
/// <summary>
/// Creates a new instance of the <see cref="DataModelConditionList" /> class
/// </summary>
/// <param name="parent"></param>
public DataModelConditionList(DataModelConditionPart parent)
{
Parent = parent;
Entity = new DisplayConditionListEntity();
@ -20,7 +27,7 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionList(DisplayConditionPart parent, DisplayConditionListEntity entity)
internal DataModelConditionList(DataModelConditionPart parent, DisplayConditionListEntity entity)
{
Parent = parent;
Entity = entity;
@ -29,14 +36,29 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionListEntity Entity { get; set; }
internal DisplayConditionListEntity Entity { get; set; }
/// <summary>
/// Gets or sets the list operator
/// </summary>
public ListOperator ListOperator { get; set; }
/// <summary>
/// Gets the currently used instance of the list data model
/// </summary>
public DataModel ListDataModel { get; private set; }
/// <summary>
/// Gets the path of the list property in the <see cref="ListDataModel" />
/// </summary>
public string ListPropertyPath { get; private set; }
public Func<object, IList> CompiledListAccessor { get; set; }
/// <summary>
/// Gets the compiled function that accesses the list this condition evaluates on
/// </summary>
public Func<object, IList> CompiledListAccessor { get; private set; }
/// <inheritdoc />
public override bool Evaluate()
{
if (_disposed)
@ -48,27 +70,11 @@ namespace Artemis.Core
return EvaluateObject(CompiledListAccessor(ListDataModel));
}
public override bool EvaluateObject(object target)
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionList");
if (!Children.Any())
return false;
if (!(target is IList list))
return false;
var objectList = list.Cast<object>();
return ListOperator switch
{
ListOperator.Any => objectList.Any(o => Children[0].EvaluateObject(o)),
ListOperator.All => objectList.All(o => Children[0].EvaluateObject(o)),
ListOperator.None => objectList.Any(o => !Children[0].EvaluateObject(o)),
ListOperator.Count => false,
_ => throw new ArgumentOutOfRangeException()
};
}
/// <summary>
/// Updates the list the predicate is evaluated on
/// </summary>
/// <param name="dataModel">The data model of the list</param>
/// <param name="path">The path pointing to the list inside the list</param>
public void UpdateList(DataModel dataModel, string path)
{
if (_disposed)
@ -98,24 +104,49 @@ namespace Artemis.Core
return;
// Create a new root group
AddChild(new DisplayConditionGroup(this));
AddChild(new DataModelConditionGroup(this));
CreateExpression();
}
public void CreateExpression()
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
_disposed = true;
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
internal override bool EvaluateObject(object target)
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionList");
var parameter = Expression.Parameter(typeof(object), "listDataModel");
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
Expression.Convert(parameter, ListDataModel.GetType()),
(expression, s) => Expression.Convert(Expression.Property(expression, s), typeof(IList)));
if (!Children.Any())
return false;
if (!(target is IList list))
return false;
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
CompiledListAccessor = lambda.Compile();
var objectList = list.Cast<object>();
return ListOperator switch
{
ListOperator.Any => objectList.Any(o => Children[0].EvaluateObject(o)),
ListOperator.All => objectList.All(o => Children[0].EvaluateObject(o)),
ListOperator.None => objectList.Any(o => !Children[0].EvaluateObject(o)),
ListOperator.Count => false,
_ => throw new ArgumentOutOfRangeException()
};
}
internal override void Save()
{
// Target list
@ -159,14 +190,28 @@ namespace Artemis.Core
// There should only be one child and it should be a group
if (Entity.Children.SingleOrDefault() is DisplayConditionGroupEntity rootGroup)
AddChild(new DisplayConditionGroup(this, rootGroup));
AddChild(new DataModelConditionGroup(this, rootGroup));
else
{
Entity.Children.Clear();
AddChild(new DisplayConditionGroup(this));
AddChild(new DataModelConditionGroup(this));
}
}
private void CreateExpression()
{
if (_disposed)
throw new ObjectDisposedException("DisplayConditionList");
var parameter = Expression.Parameter(typeof(object), "listDataModel");
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
Expression.Convert(parameter, ListDataModel.GetType()),
(expression, s) => Expression.Convert(Expression.Property(expression, s), typeof(IList)));
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
CompiledListAccessor = lambda.Compile();
}
#region Event handlers
@ -191,31 +236,31 @@ namespace Artemis.Core
}
#endregion
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
_disposed = true;
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
foreach (var child in Children)
child.Dispose();
base.Dispose(disposing);
}
#endregion
}
/// <summary>
/// Represents a list operator
/// </summary>
public enum ListOperator
{
/// <summary>
/// Any of the list items should evaluate to true
/// </summary>
Any,
/// <summary>
/// All of the list items should evaluate to true
/// </summary>
All,
/// <summary>
/// None of the list items should evaluate to true
/// </summary>
None,
/// <summary>
/// A specific amount of the list items should evaluate to true
/// </summary>
Count
}
}

View File

@ -8,9 +8,17 @@ using Newtonsoft.Json;
namespace Artemis.Core
{
public class DisplayConditionListPredicate : DisplayConditionPart
/// <summary>
/// A predicate like evaluated inside a <see cref="DataModelConditionList" />
/// </summary>
public class DataModelConditionListPredicate : DataModelConditionPart
{
public DisplayConditionListPredicate(DisplayConditionPart parent, ProfileRightSideType predicateType)
/// <summary>
/// Creates a new instance of the <see cref="DataModelConditionListPredicate" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="predicateType"></param>
public DataModelConditionListPredicate(DataModelConditionPart parent, ProfileRightSideType predicateType)
{
Parent = parent;
PredicateType = predicateType;
@ -20,7 +28,7 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionListPredicate(DisplayConditionPart parent, DisplayConditionListPredicateEntity entity)
internal DataModelConditionListPredicate(DataModelConditionPart parent, DisplayConditionListPredicateEntity entity)
{
Parent = parent;
Entity = entity;
@ -30,27 +38,150 @@ namespace Artemis.Core
Initialize();
}
public DisplayConditionListPredicateEntity Entity { get; set; }
internal DisplayConditionListPredicateEntity Entity { get; set; }
/// <summary>
/// Gets or sets the predicate type
/// </summary>
public ProfileRightSideType PredicateType { get; set; }
/// <summary>
/// Gets the operator
/// </summary>
public ConditionOperator Operator { get; private set; }
/// <summary>
/// Gets the type of the content of the list this predicate is evaluated on
/// </summary>
public Type ListType { get; private set; }
/// <summary>
/// Gets the currently used instance of the list data model
/// </summary>
public DataModel ListDataModel { get; private set; }
/// <summary>
/// Gets the path of the list property in the <see cref="ListDataModel" />
/// </summary>
public string ListPropertyPath { get; private set; }
/// <summary>
/// Gets the path of the left property in the <see cref="ListType" />
/// </summary>
public string LeftPropertyPath { get; private set; }
/// <summary>
/// Gets the path of the right property in the <see cref="ListType" />
/// </summary>
public string RightPropertyPath { get; private set; }
/// <summary>
/// Gets the right static value, only used it <see cref="PredicateType" /> is
/// <see cref="ProfileRightSideType.Static" />
/// </summary>
public object RightStaticValue { get; private set; }
/// <summary>
/// Gets the compiled function that evaluates this predicate
/// </summary>
public Func<object, bool> CompiledListPredicate { get; private set; }
public void ApplyParentList()
/// <summary>
/// Updates the left side of the predicate
/// </summary>
/// <param name="path">The path pointing to the left side value inside the list</param>
public void UpdateLeftSide(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
LeftPropertyPath = path;
ValidateOperator();
ValidateRightSide();
CreateExpression();
}
/// <summary>
/// Updates the right side of the predicate, makes the predicate dynamic and re-compiles the expression
/// </summary>
/// <param name="path">The path pointing to the right side value inside the list</param>
public void UpdateRightSideDynamic(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
PredicateType = ProfileRightSideType.Dynamic;
RightPropertyPath = path;
CreateExpression();
}
/// <summary>
/// Updates the right side of the predicate, makes the predicate static and re-compiles the expression
/// </summary>
/// <param name="staticValue">The right side value to use</param>
public void UpdateRightSideStatic(object staticValue)
{
PredicateType = ProfileRightSideType.Static;
RightPropertyPath = null;
SetStaticValue(staticValue);
CreateExpression();
}
/// <summary>
/// Updates the operator of the predicate and re-compiles the expression
/// </summary>
/// <param name="conditionOperator"></param>
public void UpdateOperator(ConditionOperator conditionOperator)
{
if (conditionOperator == null)
{
Operator = null;
return;
}
if (LeftPropertyPath == null)
{
Operator = conditionOperator;
return;
}
var leftType = GetTypeAtInnerPath(LeftPropertyPath);
if (conditionOperator.SupportsType(leftType))
Operator = conditionOperator;
CreateExpression();
}
/// <summary>
/// Not supported for list predicates, always returns <c>false</c>
/// </summary>
public override bool Evaluate()
{
return false;
}
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;
base.Dispose(disposing);
}
#endregion
internal void ApplyParentList()
{
var current = Parent;
while (current != null)
{
if (current is DisplayConditionList parentList)
if (current is DataModelConditionList parentList)
{
UpdateList(parentList.ListDataModel, parentList.ListPropertyPath);
return;
@ -60,7 +191,7 @@ namespace Artemis.Core
}
}
public void UpdateList(DataModel dataModel, string path)
internal void UpdateList(DataModel dataModel, string path)
{
if (dataModel != null && path == null)
throw new ArtemisCoreException("If a data model is provided, a path is also required");
@ -89,70 +220,19 @@ namespace Artemis.Core
CreateExpression();
}
public void UpdateLeftSide(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
LeftPropertyPath = path;
ValidateOperator();
ValidateRightSide();
CreateExpression();
}
public void UpdateRightSideDynamic(string path)
{
if (!ListContainsInnerPath(path))
throw new ArtemisCoreException($"List type {ListType.Name} does not contain path {path}");
PredicateType = ProfileRightSideType.Dynamic;
RightPropertyPath = path;
CreateExpression();
}
public void UpdateRightSideStatic(object staticValue)
{
PredicateType = ProfileRightSideType.Static;
RightPropertyPath = null;
SetStaticValue(staticValue);
CreateExpression();
}
public void UpdateOperator(ConditionOperator conditionOperator)
{
if (conditionOperator == null)
{
Operator = null;
return;
}
if (LeftPropertyPath == null)
{
Operator = conditionOperator;
return;
}
var leftType = GetTypeAtInnerPath(LeftPropertyPath);
if (conditionOperator.SupportsType(leftType))
Operator = conditionOperator;
CreateExpression();
}
public override bool Evaluate()
{
return false;
}
public override bool EvaluateObject(object target)
/// <summary>
/// Evaluates the condition part on the given target
/// </summary>
/// <param name="target">
/// An instance of the list described in <see cref="ListDataModel" /> and
/// <see cref="ListPropertyPath" />
/// </param>
internal override bool EvaluateObject(object target)
{
return CompiledListPredicate != null && CompiledListPredicate(target);
}
public bool ListContainsInnerPath(string path)
internal bool ListContainsInnerPath(string path)
{
if (ListType == null)
return false;
@ -171,7 +251,7 @@ namespace Artemis.Core
return true;
}
public Type GetTypeAtInnerPath(string path)
internal Type GetTypeAtInnerPath(string path)
{
if (!ListContainsInnerPath(path))
return null;
@ -210,6 +290,11 @@ namespace Artemis.Core
}
}
internal override DisplayConditionPartEntity GetEntity()
{
return Entity;
}
private void Initialize()
{
ConditionOperatorStore.ConditionOperatorAdded += ConditionOperatorStoreOnConditionOperatorAdded;
@ -270,11 +355,6 @@ namespace Artemis.Core
}
}
internal override DisplayConditionPartEntity GetEntity()
{
return Entity;
}
private void CreateExpression()
{
CompiledListPredicate = null;
@ -412,18 +492,5 @@ namespace Artemis.Core
}
#endregion
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;
base.Dispose(disposing);
}
#endregion
}
}

View File

@ -9,17 +9,17 @@ using Newtonsoft.Json;
namespace Artemis.Core
{
/// <summary>
/// A predicate in a display condition using either two data model values or one data model value and a
/// A predicate in a data model condition using either two data model values or one data model value and a
/// static value
/// </summary>
public class DisplayConditionPredicate : DisplayConditionPart
public class DataModelConditionPredicate : DataModelConditionPart
{
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionPredicate" /> class
/// Creates a new instance of the <see cref="DataModelConditionPredicate" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="predicateType"></param>
public DisplayConditionPredicate(DisplayConditionPart parent, ProfileRightSideType predicateType)
public DataModelConditionPredicate(DataModelConditionPart parent, ProfileRightSideType predicateType)
{
Parent = parent;
PredicateType = predicateType;
@ -28,12 +28,7 @@ namespace Artemis.Core
Initialize();
}
/// <summary>
/// Creates a new instance of the <see cref="DisplayConditionPredicate" /> class
/// </summary>
/// <param name="parent"></param>
/// <param name="entity"></param>
public DisplayConditionPredicate(DisplayConditionPart parent, DisplayConditionPredicateEntity entity)
internal DataModelConditionPredicate(DataModelConditionPart parent, DisplayConditionPredicateEntity entity)
{
Parent = parent;
Entity = entity;
@ -219,7 +214,7 @@ namespace Artemis.Core
}
/// <inheritdoc />
public override bool EvaluateObject(object target)
internal override bool EvaluateObject(object target)
{
return false;
}

View File

@ -11,15 +11,18 @@ namespace Artemis.Core
public abstract class DataBindingConverter<TLayerProperty, TProperty> : IDataBindingConverter
{
/// <summary>
/// A dynamically compiled getter pointing to the data bound property
/// Gets a dynamically compiled getter pointing to the data bound property
/// </summary>
public Func<TLayerProperty, TProperty> GetExpression { get; private set; }
/// <summary>
/// A dynamically compiled setter pointing to the data bound property
/// Gets a dynamically compiled setter pointing to the data bound property used for value types
/// </summary>
public Action<TProperty> ValueTypeSetExpression { get; private set; }
/// <summary>
/// Gets a dynamically compiled setter pointing to the data bound property used for reference types
/// </summary>
public Action<TLayerProperty, TProperty> ReferenceTypeSetExpression { get; private set; }
/// <summary>

View File

@ -49,9 +49,9 @@ namespace Artemis.Core
DisplayContinuously = RenderElementEntity.DisplayContinuously;
AlwaysFinishTimeline = RenderElementEntity.AlwaysFinishTimeline;
DisplayConditionGroup = RenderElementEntity.RootDisplayCondition != null
? new DisplayConditionGroup(null, RenderElementEntity.RootDisplayCondition)
: new DisplayConditionGroup(null);
DataModelConditionGroup = RenderElementEntity.RootDisplayCondition != null
? new DataModelConditionGroup(null, RenderElementEntity.RootDisplayCondition)
: new DataModelConditionGroup(null);
ActivateEffects();
}
@ -82,8 +82,8 @@ namespace Artemis.Core
}
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.Save();
RenderElementEntity.RootDisplayCondition = DataModelConditionGroup?.Entity;
DataModelConditionGroup?.Save();
}
#region Properties
@ -392,22 +392,22 @@ namespace Artemis.Core
private set => SetAndNotify(ref _displayConditionMet, value);
}
private DisplayConditionGroup _displayConditionGroup;
private DataModelConditionGroup _dataModelConditionGroup;
private TimeSpan _timelinePosition;
private bool _displayConditionMet;
/// <summary>
/// Gets or sets the root display condition group
/// </summary>
public DisplayConditionGroup DisplayConditionGroup
public DataModelConditionGroup DataModelConditionGroup
{
get => _displayConditionGroup;
set => SetAndNotify(ref _displayConditionGroup, value);
get => _dataModelConditionGroup;
set => SetAndNotify(ref _dataModelConditionGroup, value);
}
public void UpdateDisplayCondition()
{
var conditionMet = DisplayConditionGroup == null || DisplayConditionGroup.Evaluate();
var conditionMet = DataModelConditionGroup == null || DataModelConditionGroup.Evaluate();
if (conditionMet && !DisplayConditionMet)
TimelinePosition = TimeSpan.Zero;

View File

@ -2,6 +2,9 @@
namespace Artemis.Core.DataModelExpansions
{
/// <summary>
/// Represents an attribute that marks a data model property to be ignored by the UI
/// </summary>
public class DataModelIgnoreAttribute : Attribute
{
}

View File

@ -2,6 +2,9 @@
namespace Artemis.Core.DataModelExpansions
{
/// <summary>
/// Represents an attribute that describes a data model property
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class DataModelPropertyAttribute : Attribute
{

View File

@ -28,7 +28,7 @@ namespace Artemis.Core.DataModelExpansions
[DataModelIgnore]
public bool IsExpansion { get; internal set; }
public bool ContainsPath(string path)
internal bool ContainsPath(string path)
{
var parts = path.Split('.');
var current = GetType();
@ -43,7 +43,7 @@ namespace Artemis.Core.DataModelExpansions
return true;
}
public Type GetTypeAtPath(string path)
internal Type GetTypeAtPath(string path)
{
if (!ContainsPath(path))
return null;
@ -62,7 +62,7 @@ namespace Artemis.Core.DataModelExpansions
return result;
}
public Type GetListTypeInPath(string path)
internal Type GetListTypeInPath(string path)
{
if (!ContainsPath(path))
return null;
@ -90,7 +90,7 @@ namespace Artemis.Core.DataModelExpansions
return null;
}
public Type GetListTypeAtPath(string path)
internal Type GetListTypeAtPath(string path)
{
if (!ContainsPath(path))
return null;
@ -98,29 +98,7 @@ namespace Artemis.Core.DataModelExpansions
var child = GetTypeAtPath(path);
return child.GenericTypeArguments.Length > 0 ? child.GenericTypeArguments[0] : null;
}
public string GetListInnerPath(string path)
{
if (GetListTypeInPath(path) == null)
throw new ArtemisCoreException($"Cannot determine inner list path at {path} because it does not contain a list");
var parts = path.Split('.');
var current = GetType();
for (var index = 0; index < parts.Length; index++)
{
var part = parts[index];
var property = current.GetProperty(part);
if (typeof(IList).IsAssignableFrom(property.PropertyType))
return string.Join('.', parts.Skip(index + 1).ToList());
current = property.PropertyType;
}
return null;
}
/// <summary>
/// Returns a read-only list of all properties in this datamodel that are to be ignored
/// </summary>

View File

@ -10,14 +10,22 @@ namespace Artemis.Core.DataModelExpansions
/// </summary>
public abstract class BaseDataModelExpansion : Plugin
{
protected readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Gets a list of all properties ignored at runtime using IgnoreProperty(x => x.y)
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
internal DataModel InternalDataModel { get; set; }
/// <summary>
/// Called each frame when the data model should update
/// </summary>
/// <param name="deltaTime">Time in seconds since the last update</param>
public abstract void Update(double deltaTime);
/// <summary>

View File

@ -2,13 +2,23 @@
namespace Artemis.Core.LayerBrushes
{
/// <summary>
/// Represents a view model for a brush configuration window
/// </summary>
public abstract class BrushConfigurationViewModel : Screen
{
/// <summary>
/// Creates a new instance of the <see cref="BrushConfigurationViewModel" /> class
/// </summary>
/// <param name="layerBrush"></param>
protected BrushConfigurationViewModel(BaseLayerBrush layerBrush)
{
LayerBrush = layerBrush;
}
/// <summary>
/// Gets the layer brush this view model is associated with
/// </summary>
public BaseLayerBrush LayerBrush { get; }
}
}

View File

@ -1,10 +1,16 @@
using Artemis.Core.Services;
using SkiaSharp;
using SkiaSharp;
namespace Artemis.Core.LayerBrushes
{
/// <summary>
/// Represents a brush that renders on a layer
/// </summary>
/// <typeparam name="T">The type of brush properties</typeparam>
public abstract class LayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{
/// <summary>
/// Creates a new instance of the <see cref="LayerBrush{T}" /> class
/// </summary>
protected LayerBrush()
{
BrushType = LayerBrushType.Regular;

View File

@ -44,6 +44,16 @@ namespace Artemis.Core.LayerBrushes
/// </summary>
public LayerBrushProvider LayerBrushProvider { get; }
/// <summary>
/// Determines whether the provided <paramref name="reference" /> references to a brush provided by this descriptor
/// </summary>
public bool MatchesLayerBrushReference(LayerBrushReference reference)
{
if (reference == null)
return false;
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
}
/// <summary>
/// Creates an instance of the described brush and applies it to the layer
/// </summary>
@ -61,12 +71,5 @@ namespace Artemis.Core.LayerBrushes
layer.LayerBrush = brush;
layer.OnLayerBrushUpdated();
}
public bool MatchesLayerBrushReference(LayerBrushReference reference)
{
if (reference == null)
return false;
return LayerBrushProvider.PluginInfo.Guid == reference.BrushPluginGuid && LayerBrushType.Name == reference.BrushType;
}
}
}

View File

@ -1,16 +1,21 @@
using Artemis.Core.Services;
using SkiaSharp;
using SkiaSharp;
namespace Artemis.Core.LayerBrushes
{
/// <summary>
/// Represents a brush that renders on a per-layer basis
/// </summary>
/// <typeparam name="T">The type of brush properties</typeparam>
public abstract class PerLedLayerBrush<T> : PropertiesLayerBrush<T> where T : LayerPropertyGroup
{
/// <summary>
/// Creates a new instance of the <see cref="PerLedLayerBrush{T}" /> class
/// </summary>
protected PerLedLayerBrush()
{
BrushType = LayerBrushType.Regular;
}
/// <summary>
/// The main method of rendering for this type of brush. Called once per frame for each LED in the layer
/// <para>

View File

@ -2,13 +2,23 @@
namespace Artemis.Core.LayerEffects
{
/// <summary>
/// Represents a view model for an effect configuration window
/// </summary>
public abstract class EffectConfigurationViewModel : Screen
{
/// <summary>
/// Creates a new instance of the <see cref="EffectConfigurationViewModel" /> class
/// </summary>
/// <param name="layerEffect"></param>
protected EffectConfigurationViewModel(BaseLayerEffect layerEffect)
{
LayerEffect = layerEffect;
}
/// <summary>
/// Gets the layer effect this view model is associated with
/// </summary>
public BaseLayerEffect LayerEffect { get; }
}
}

View File

@ -1,8 +1,11 @@
using System;
using Artemis.Core.Services;
namespace Artemis.Core.LayerEffects
{
/// <summary>
/// Represents an effect that applies preprocessing and/or postprocessing to a layer
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class LayerEffect<T> : BaseLayerEffect where T : LayerPropertyGroup
{
private T _properties;

View File

@ -16,6 +16,7 @@
return ActivationMet;
}
/// <inheritdoc />
public string GetUserFriendlyDescription()
{
return "No description available";

View File

@ -43,6 +43,7 @@ namespace Artemis.Core.Modules
: processes.Any();
}
/// <inheritdoc />
public string GetUserFriendlyDescription()
{
var description = $"Requirement met when \"{ProcessName}.exe\" is running";

View File

@ -144,13 +144,13 @@ namespace Artemis.Core.Modules
public bool IsUpdateAllowed => IsActivated && (UpdateDuringActivationOverride || !IsActivatedOverride);
/// <summary>
/// Called each frame when the module must update
/// Called each frame when the module should update
/// </summary>
/// <param name="deltaTime">Time in seconds since the last update</param>
public abstract void Update(double deltaTime);
/// <summary>
/// Called each frame when the module must render
/// Called each frame when the module should render
/// </summary>
/// <param name="deltaTime">Time since the last render</param>
/// <param name="surface">The RGB Surface to render to</param>

View File

@ -91,18 +91,27 @@ namespace Artemis.Core.Modules
/// </summary>
public abstract class ProfileModule : Module
{
protected readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
protected internal readonly List<PropertyInfo> HiddenPropertiesList = new List<PropertyInfo>();
/// <summary>
/// Creates a new instance of the <see cref="ProfileModule" /> class
/// </summary>
protected ProfileModule()
{
OpacityOverride = 1;
}
/// <summary>
/// Gets a list of all properties ignored at runtime using IgnoreProperty(x => x.y)
/// Gets a list of all properties ignored at runtime using <c>IgnoreProperty(x => x.y)</c>
/// </summary>
public ReadOnlyCollection<PropertyInfo> HiddenProperties => HiddenPropertiesList.AsReadOnly();
/// <summary>
/// Gets the currently active profile
/// </summary>
public Profile ActiveProfile { get; private set; }
/// <summary>
@ -225,8 +234,14 @@ namespace Artemis.Core.Modules
#region Events
/// <summary>
/// Occurs when the <see cref="ActiveProfile" /> has changed
/// </summary>
public event EventHandler ActiveProfileChanged;
/// <summary>
/// Invokes the <see cref="ActiveProfileChanged" /> event
/// </summary>
protected virtual void OnActiveProfileChanged()
{
ActiveProfileChanged?.Invoke(this, EventArgs.Empty);

View File

@ -2,13 +2,23 @@
namespace Artemis.Core
{
/// <summary>
/// Represents a view model for a plugin configuration window
/// </summary>
public abstract class PluginConfigurationViewModel : Screen
{
/// <summary>
/// Creates a new instance of the <see cref="PluginConfigurationViewModel" /> class
/// </summary>
/// <param name="plugin"></param>
protected PluginConfigurationViewModel(Plugin plugin)
{
Plugin = plugin;
}
/// <summary>
/// Gets the plugin this configuration view model is associated with
/// </summary>
public Plugin Plugin { get; }
}
}

View File

@ -8,6 +8,9 @@ using Stylet;
namespace Artemis.Core
{
/// <summary>
/// Represents basic info about a plugin and contains a reference to the instance of said plugin
/// </summary>
[JsonObject(MemberSerialization.OptIn)]
public class PluginInfo : PropertyChangedBase
{
@ -17,7 +20,6 @@ namespace Artemis.Core
private Guid _guid;
private string _icon;
private Plugin _instance;
private bool _lastEnableSuccessful;
private Exception _loadException;
private string _main;
private string _name;
@ -140,6 +142,7 @@ namespace Artemis.Core
/// </summary>
internal PluginEntity PluginEntity { get; set; }
/// <inheritdoc />
public override string ToString()
{
return $"{Name} v{Version} - {Guid}";

View File

@ -93,12 +93,12 @@ namespace Artemis.Core
Action(interval.TotalSeconds);
}
private void InstanceOnPluginEnabled(object? sender, EventArgs e)
private void InstanceOnPluginEnabled(object sender, EventArgs e)
{
Start();
}
private void InstanceOnPluginDisabled(object? sender, EventArgs e)
private void InstanceOnPluginDisabled(object sender, EventArgs e)
{
Stop();
}

View File

@ -6,6 +6,10 @@ using Stylet;
namespace Artemis.Core
{
/// <summary>
/// Represents a setting tied to a plugin of type <typeparamref name="T" />
/// </summary>
/// <typeparam name="T">The value type of the setting</typeparam>
public class PluginSetting<T> : PropertyChangedBase
{
// ReSharper disable once NotAccessedField.Local
@ -78,14 +82,21 @@ namespace Artemis.Core
_pluginRepository.SaveSetting(_pluginSettingEntity);
}
/// <summary>
/// Occurs when the value of the setting has been changed
/// </summary>
public event EventHandler<EventArgs> SettingChanged;
/// <inheritdoc />
public override string ToString()
{
return $"{nameof(Name)}: {Name}, {nameof(Value)}: {Value}, {nameof(HasChanged)}: {HasChanged}";
}
protected virtual void OnSettingChanged()
/// <summary>
/// Invokes the <see cref="SettingChanged" /> event
/// </summary>
protected internal virtual void OnSettingChanged()
{
SettingChanged?.Invoke(this, EventArgs.Empty);
}

View File

@ -47,8 +47,19 @@ namespace Artemis.Core
/// <inheritdoc />
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>();
/// <summary>
/// Gets or sets the desired scale of the bitmap brush
/// </summary>
public Scale Scale { get; set; }
/// <summary>
/// Gets the last rendered scale of the bitmap brush
/// </summary>
public Scale RenderedScale { get; private set; }
/// <summary>
/// Gets the bitmap used to sample the brush
/// </summary>
public SKBitmap Bitmap { get; private set; }
#endregion
@ -148,6 +159,7 @@ namespace Artemis.Core
{
}
/// <inheritdoc />
public void Dispose()
{
lock (_disposeLock)
@ -157,7 +169,7 @@ namespace Artemis.Core
}
}
public bool IsDisposed { get; set; }
internal bool IsDisposed { get; set; }
#endregion
}

View File

@ -70,10 +70,10 @@ namespace Artemis.Core.Services
List<PluginInfo> GetAllPluginInfo();
/// <summary>
/// Finds all enabled <see cref="Plugin" /> instances of type T
/// Finds all enabled <see cref="Plugin" /> instances of <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">Either <see cref="Plugin" /> or a plugin type implementing <see cref="Plugin" /></typeparam>
/// <returns>Returns a list of plug instances of type T
/// <returns>Returns a list of plugin instances of <typeparamref name="T"/></returns>
List<T> GetPluginsOfType<T>() where T : Plugin;
/// <summary>

View File

@ -3,6 +3,9 @@ using System.Collections.ObjectModel;
namespace Artemis.Core.Services
{
/// <summary>
/// Provides access to the device surface and its configuration
/// </summary>
public interface ISurfaceService : IArtemisService
{
/// <summary>

View File

@ -13,26 +13,26 @@ namespace Artemis.Core
_logger = kernel.Get<ILogger>();
}
public static void LogPredicateDeserializationFailure(DisplayConditionPredicate displayConditionPredicate, JsonException exception)
public static void LogPredicateDeserializationFailure(DataModelConditionPredicate dataModelConditionPredicate, JsonException exception)
{
_logger.Warning(
exception,
"Failed to deserialize display condition predicate {left} {operator} {right}",
displayConditionPredicate.Entity.LeftPropertyPath,
displayConditionPredicate.Entity.OperatorType,
displayConditionPredicate.Entity.RightPropertyPath
dataModelConditionPredicate.Entity.LeftPropertyPath,
dataModelConditionPredicate.Entity.OperatorType,
dataModelConditionPredicate.Entity.RightPropertyPath
);
}
public static void LogListPredicateDeserializationFailure(DisplayConditionListPredicate displayConditionPredicate, JsonException exception)
public static void LogListPredicateDeserializationFailure(DataModelConditionListPredicate dataModelConditionPredicate, JsonException exception)
{
_logger.Warning(
exception,
"Failed to deserialize display condition list predicate {list} => {left} {operator} {right}",
displayConditionPredicate.Entity.ListPropertyPath,
displayConditionPredicate.Entity.LeftPropertyPath,
displayConditionPredicate.Entity.OperatorType,
displayConditionPredicate.Entity.RightPropertyPath
dataModelConditionPredicate.Entity.ListPropertyPath,
dataModelConditionPredicate.Entity.LeftPropertyPath,
dataModelConditionPredicate.Entity.OperatorType,
dataModelConditionPredicate.Entity.RightPropertyPath
);
}

View File

@ -1,4 +1,5 @@
using System;
#pragma warning disable 1591
using System;
namespace Artemis.Core
{

View File

@ -176,7 +176,7 @@ namespace Artemis.UI.Shared
IsMatchingFilteredTypes = filteredTypes.Any(t => t == PropertyInfo.PropertyType || t == typeof(Enum) && PropertyInfo.PropertyType.IsEnum);
}
public DataModelVisualizationViewModel GetChildForCondition(DisplayConditionPredicate predicate, DisplayConditionSide side)
public DataModelVisualizationViewModel GetChildForCondition(DataModelConditionPredicate predicate, DisplayConditionSide side)
{
if (side == DisplayConditionSide.Left)
{

View File

@ -65,10 +65,10 @@ namespace Artemis.UI.Ninject.Factories
public interface IDisplayConditionsVmFactory : IVmFactory
{
DisplayConditionGroupViewModel DisplayConditionGroupViewModel(DisplayConditionGroup displayConditionGroup, bool isListGroup);
DisplayConditionListViewModel DisplayConditionListViewModel(DisplayConditionList displayConditionList);
DisplayConditionPredicateViewModel DisplayConditionPredicateViewModel(DisplayConditionPredicate displayConditionPredicate);
DisplayConditionListPredicateViewModel DisplayConditionListPredicateViewModel(DisplayConditionListPredicate displayConditionListPredicate);
DisplayConditionGroupViewModel DisplayConditionGroupViewModel(DataModelConditionGroup dataModelConditionGroup, bool isListGroup);
DisplayConditionListViewModel DisplayConditionListViewModel(DataModelConditionList dataModelConditionList);
DisplayConditionPredicateViewModel DisplayConditionPredicateViewModel(DataModelConditionPredicate dataModelConditionPredicate);
DisplayConditionListPredicateViewModel DisplayConditionListPredicateViewModel(DataModelConditionListPredicate dataModelConditionListPredicate);
}
public interface ILayerPropertyVmFactory : IVmFactory

View File

@ -5,12 +5,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions.Abstract
{
public abstract class DisplayConditionViewModel : Conductor<DisplayConditionViewModel>.Collection.AllActive
{
protected DisplayConditionViewModel(DisplayConditionPart model)
protected DisplayConditionViewModel(DataModelConditionPart model)
{
Model = model;
}
public DisplayConditionPart Model { get; }
public DataModelConditionPart Model { get; }
public abstract void Update();

View File

@ -17,11 +17,11 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private bool _isInitialized;
private bool _isRootGroup;
public DisplayConditionGroupViewModel(DisplayConditionGroup displayConditionGroup,
public DisplayConditionGroupViewModel(DataModelConditionGroup dataModelConditionGroup,
bool isListGroup,
IProfileEditorService profileEditorService,
IDisplayConditionsVmFactory displayConditionsVmFactory)
: base(displayConditionGroup)
: base(dataModelConditionGroup)
{
IsListGroup = isListGroup;
_profileEditorService = profileEditorService;
@ -38,7 +38,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public bool IsListGroup { get; }
public DisplayConditionGroup DisplayConditionGroup => (DisplayConditionGroup) Model;
public DataModelConditionGroup DataModelConditionGroup => (DataModelConditionGroup) Model;
public bool IsRootGroup
{
@ -53,12 +53,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
}
public bool DisplayBooleanOperator => Items.Count > 1;
public string SelectedBooleanOperator => DisplayConditionGroup.BooleanOperator.Humanize();
public string SelectedBooleanOperator => DataModelConditionGroup.BooleanOperator.Humanize();
public void SelectBooleanOperator(string type)
{
var enumValue = Enum.Parse<BooleanOperator>(type);
DisplayConditionGroup.BooleanOperator = enumValue;
DataModelConditionGroup.BooleanOperator = enumValue;
NotifyOfPropertyChange(nameof(SelectedBooleanOperator));
_profileEditorService.UpdateSelectedProfileElement();
@ -69,19 +69,19 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
if (type == "Static")
{
if (!IsListGroup)
DisplayConditionGroup.AddChild(new DisplayConditionPredicate(DisplayConditionGroup, ProfileRightSideType.Static));
DataModelConditionGroup.AddChild(new DataModelConditionPredicate(DataModelConditionGroup, ProfileRightSideType.Static));
else
DisplayConditionGroup.AddChild(new DisplayConditionListPredicate(DisplayConditionGroup, ProfileRightSideType.Static));
DataModelConditionGroup.AddChild(new DataModelConditionListPredicate(DataModelConditionGroup, ProfileRightSideType.Static));
}
else if (type == "Dynamic")
{
if (!IsListGroup)
DisplayConditionGroup.AddChild(new DisplayConditionPredicate(DisplayConditionGroup, ProfileRightSideType.Dynamic));
DataModelConditionGroup.AddChild(new DataModelConditionPredicate(DataModelConditionGroup, ProfileRightSideType.Dynamic));
else
DisplayConditionGroup.AddChild(new DisplayConditionListPredicate(DisplayConditionGroup, ProfileRightSideType.Dynamic));
DataModelConditionGroup.AddChild(new DataModelConditionListPredicate(DataModelConditionGroup, ProfileRightSideType.Dynamic));
}
else if (type == "List" && !IsListGroup)
DisplayConditionGroup.AddChild(new DisplayConditionList(DisplayConditionGroup));
DataModelConditionGroup.AddChild(new DataModelConditionList(DataModelConditionGroup));
Update();
_profileEditorService.UpdateSelectedProfileElement();
@ -89,7 +89,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void AddGroup()
{
DisplayConditionGroup.AddChild(new DisplayConditionGroup(DisplayConditionGroup));
DataModelConditionGroup.AddChild(new DataModelConditionGroup(DataModelConditionGroup));
Update();
_profileEditorService.UpdateSelectedProfileElement();
@ -100,7 +100,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
NotifyOfPropertyChange(nameof(SelectedBooleanOperator));
// Remove VMs of effects no longer applied on the layer
var toRemove = Items.Where(c => !DisplayConditionGroup.Children.Contains(c.Model)).ToList();
var toRemove = Items.Where(c => !DataModelConditionGroup.Children.Contains(c.Model)).ToList();
// Using RemoveRange breaks our lovely animations
foreach (var displayConditionViewModel in toRemove)
Items.Remove(displayConditionViewModel);
@ -112,17 +112,17 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
switch (childModel)
{
case DisplayConditionGroup displayConditionGroup:
case DataModelConditionGroup displayConditionGroup:
Items.Add(_displayConditionsVmFactory.DisplayConditionGroupViewModel(displayConditionGroup, IsListGroup));
break;
case DisplayConditionList displayConditionListPredicate:
case DataModelConditionList displayConditionListPredicate:
Items.Add(_displayConditionsVmFactory.DisplayConditionListViewModel(displayConditionListPredicate));
break;
case DisplayConditionPredicate displayConditionPredicate:
case DataModelConditionPredicate displayConditionPredicate:
if (!IsListGroup)
Items.Add(_displayConditionsVmFactory.DisplayConditionPredicateViewModel(displayConditionPredicate));
break;
case DisplayConditionListPredicate displayConditionListPredicate:
case DataModelConditionListPredicate displayConditionListPredicate:
if (IsListGroup)
Items.Add(_displayConditionsVmFactory.DisplayConditionListPredicateViewModel(displayConditionListPredicate));
break;

View File

@ -38,12 +38,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private List<Type> _supportedInputTypes;
public DisplayConditionListPredicateViewModel(
DisplayConditionListPredicate displayConditionListPredicate,
DataModelConditionListPredicate dataModelConditionListPredicate,
IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService,
IConditionOperatorService conditionOperatorService,
ISettingsService settingsService,
IEventAggregator eventAggregator) : base(displayConditionListPredicate)
IEventAggregator eventAggregator) : base(dataModelConditionListPredicate)
{
_profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService;
@ -63,8 +63,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
Task.Run(Initialize);
}
public DisplayConditionListPredicate DisplayConditionListPredicate => (DisplayConditionListPredicate) Model;
public bool ShowRightSidePropertySelection => DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic;
public DataModelConditionListPredicate DataModelConditionListPredicate => (DataModelConditionListPredicate) Model;
public bool ShowRightSidePropertySelection => DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic;
public bool CanActivateRightSideInputViewModel => SelectedLeftSideProperty?.PropertyInfo != null;
public PluginSetting<bool> ShowDataModelValues { get; }
@ -193,45 +193,45 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
if (LeftSideDataModel == null || RightSideDataModel == null)
return;
var listDataModelGuid = DisplayConditionListPredicate.ListDataModel.PluginInfo.Guid;
var listDataModelGuid = DataModelConditionListPredicate.ListDataModel.PluginInfo.Guid;
// If static, only allow selecting properties also supported by input
if (DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Static)
if (DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
// Determine the left side property first
SelectedLeftSideProperty = LeftSideDataModel.GetChildByPath(listDataModelGuid, DisplayConditionListPredicate.LeftPropertyPath);
SelectedLeftSideProperty = LeftSideDataModel.GetChildByPath(listDataModelGuid, DataModelConditionListPredicate.LeftPropertyPath);
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
// Get the supported operators
Operators.Clear();
Operators.AddRange(_conditionOperatorService.GetConditionOperatorsForType(leftSideType));
if (DisplayConditionListPredicate.Operator == null)
DisplayConditionListPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType)));
SelectedOperator = DisplayConditionListPredicate.Operator;
if (DataModelConditionListPredicate.Operator == null)
DataModelConditionListPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType)));
SelectedOperator = DataModelConditionListPredicate.Operator;
// Determine the right side
if (DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic)
if (DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Dynamic)
{
SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DisplayConditionListPredicate.RightPropertyPath);
SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DataModelConditionListPredicate.RightPropertyPath);
RightSideDataModel.ApplyTypeFilter(true, leftSideType);
}
else
RightStaticValue = DisplayConditionListPredicate.RightStaticValue;
RightStaticValue = DataModelConditionListPredicate.RightStaticValue;
}
public void ApplyLeftSide()
{
DisplayConditionListPredicate.UpdateLeftSide(SelectedLeftSideProperty.PropertyPath);
DataModelConditionListPredicate.UpdateLeftSide(SelectedLeftSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
SelectedOperator = DisplayConditionListPredicate.Operator;
SelectedOperator = DataModelConditionListPredicate.Operator;
Update();
}
public void ApplyRightSideDynamic()
{
DisplayConditionListPredicate.UpdateRightSideDynamic(SelectedRightSideProperty.PropertyPath);
DataModelConditionListPredicate.UpdateRightSideDynamic(SelectedRightSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
Update();
@ -241,7 +241,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
{
if (isSubmitted)
{
DisplayConditionListPredicate.UpdateRightSideStatic(value);
DataModelConditionListPredicate.UpdateRightSideStatic(value);
_profileEditorService.UpdateSelectedProfileElement();
Update();
@ -255,7 +255,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void ApplyOperator()
{
DisplayConditionListPredicate.UpdateOperator(SelectedOperator);
DataModelConditionListPredicate.UpdateOperator(SelectedOperator);
_profileEditorService.UpdateSelectedProfileElement();
Update();
@ -270,7 +270,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
RightSideInputViewModel = _dataModelUIService.GetDataModelInputViewModel(
SelectedLeftSideProperty.PropertyInfo.PropertyType,
SelectedLeftSideProperty.PropertyDescription,
DisplayConditionListPredicate.RightStaticValue,
DataModelConditionListPredicate.RightStaticValue,
ApplyRightSideStatic
);
_eventAggregator.Subscribe(this);
@ -286,12 +286,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void RightDataModelUpdateRequested(object sender, EventArgs e)
{
var listDataModelGuid = DisplayConditionListPredicate.ListDataModel.PluginInfo.Guid;
var listDataModelGuid = DataModelConditionListPredicate.ListDataModel.PluginInfo.Guid;
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
// If the right side property is missing it may be available now that the data model has been updated
if (SelectedRightSideProperty == null && DisplayConditionListPredicate.RightPropertyPath != null)
SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DisplayConditionListPredicate.RightPropertyPath);
if (SelectedRightSideProperty == null && DataModelConditionListPredicate.RightPropertyPath != null)
SelectedRightSideProperty = RightSideDataModel.GetChildByPath(listDataModelGuid, DataModelConditionListPredicate.RightPropertyPath);
// With the data model updated, also reapply the filter
RightSideDataModel.ApplyTypeFilter(true, leftSideType);
@ -299,19 +299,19 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void LeftDataModelUpdateRequested(object sender, EventArgs e)
{
if (DisplayConditionListPredicate.PredicateType == ProfileRightSideType.Static)
if (DataModelConditionListPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
}
private DataModelVisualizationViewModel GetListDataModel()
{
if (DisplayConditionListPredicate.ListDataModel == null || DisplayConditionListPredicate.ListPropertyPath == null)
if (DataModelConditionListPredicate.ListDataModel == null || DataModelConditionListPredicate.ListPropertyPath == null)
throw new ArtemisUIException("Cannot create a list predicate without first selecting a target list");
var dataModel = _dataModelUIService.GetPluginDataModelVisualization(_profileEditorService.GetCurrentModule(), true);
var listDataModel = (DataModelListViewModel) dataModel.GetChildByPath(
DisplayConditionListPredicate.ListDataModel.PluginInfo.Guid,
DisplayConditionListPredicate.ListPropertyPath
DataModelConditionListPredicate.ListDataModel.PluginInfo.Guid,
DataModelConditionListPredicate.ListPropertyPath
);
return listDataModel.GetListTypeViewModel(_dataModelUIService);

View File

@ -25,12 +25,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private DataModelPropertiesViewModel _targetDataModel;
public DisplayConditionListViewModel(
DisplayConditionList displayConditionList,
DataModelConditionList dataModelConditionList,
DisplayConditionViewModel parent,
IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService,
IDisplayConditionsVmFactory displayConditionsVmFactory,
ISettingsService settingsService) : base(displayConditionList)
ISettingsService settingsService) : base(dataModelConditionList)
{
_profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService;
@ -48,7 +48,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public DelegateCommand SelectListPropertyCommand { get; }
public PluginSetting<bool> ShowDataModelValues { get; }
public DisplayConditionList DisplayConditionList => (DisplayConditionList) Model;
public DataModelConditionList DataModelConditionList => (DataModelConditionList) Model;
public bool IsInitialized
{
@ -70,12 +70,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
set => SetAndNotify(ref _selectedListProperty, value);
}
public string SelectedListOperator => DisplayConditionList.ListOperator.Humanize();
public string SelectedListOperator => DataModelConditionList.ListOperator.Humanize();
public void SelectListOperator(string type)
{
var enumValue = Enum.Parse<ListOperator>(type);
DisplayConditionList.ListOperator = enumValue;
DataModelConditionList.ListOperator = enumValue;
NotifyOfPropertyChange(nameof(SelectedListOperator));
_profileEditorService.UpdateSelectedProfileElement();
@ -84,9 +84,9 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void AddCondition(string type)
{
if (type == "Static")
DisplayConditionList.AddChild(new DisplayConditionPredicate(DisplayConditionList, ProfileRightSideType.Static));
DataModelConditionList.AddChild(new DataModelConditionPredicate(DataModelConditionList, ProfileRightSideType.Static));
else if (type == "Dynamic")
DisplayConditionList.AddChild(new DisplayConditionPredicate(DisplayConditionList, ProfileRightSideType.Dynamic));
DataModelConditionList.AddChild(new DataModelConditionPredicate(DataModelConditionList, ProfileRightSideType.Dynamic));
Update();
_profileEditorService.UpdateSelectedProfileElement();
@ -94,7 +94,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void AddGroup()
{
DisplayConditionList.AddChild(new DisplayConditionGroup(DisplayConditionList));
DataModelConditionList.AddChild(new DataModelConditionGroup(DataModelConditionList));
Update();
_profileEditorService.UpdateSelectedProfileElement();
@ -122,7 +122,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void ApplyList()
{
DisplayConditionList.UpdateList(SelectedListProperty.DataModel, SelectedListProperty.PropertyPath);
DataModelConditionList.UpdateList(SelectedListProperty.DataModel, SelectedListProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
Update();
@ -136,11 +136,11 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
NotifyOfPropertyChange(nameof(SelectedListOperator));
// Update the selected list property
if (DisplayConditionList.ListDataModel != null && DisplayConditionList.ListPropertyPath != null)
if (DataModelConditionList.ListDataModel != null && DataModelConditionList.ListPropertyPath != null)
{
var child = TargetDataModel.GetChildByPath(
DisplayConditionList.ListDataModel.PluginInfo.Guid,
DisplayConditionList.ListPropertyPath
DataModelConditionList.ListDataModel.PluginInfo.Guid,
DataModelConditionList.ListPropertyPath
);
SelectedListProperty = child as DataModelListViewModel;
}
@ -149,7 +149,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
TargetDataModel.ApplyTypeFilter(true, typeof(IList));
// Remove VMs of effects no longer applied on the layer
var toRemove = Items.Where(c => !DisplayConditionList.Children.Contains(c.Model)).ToList();
var toRemove = Items.Where(c => !DataModelConditionList.Children.Contains(c.Model)).ToList();
// Using RemoveRange breaks our lovely animations
foreach (var displayConditionViewModel in toRemove)
Items.Remove(displayConditionViewModel);
@ -158,7 +158,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
{
if (Items.Any(c => c.Model == childModel))
continue;
if (!(childModel is DisplayConditionGroup displayConditionGroup))
if (!(childModel is DataModelConditionGroup displayConditionGroup))
continue;
var viewModel = _displayConditionsVmFactory.DisplayConditionGroupViewModel(displayConditionGroup, true);

View File

@ -37,12 +37,12 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private List<Type> _supportedInputTypes;
public DisplayConditionPredicateViewModel(
DisplayConditionPredicate displayConditionPredicate,
DataModelConditionPredicate dataModelConditionPredicate,
IProfileEditorService profileEditorService,
IDataModelUIService dataModelUIService,
IConditionOperatorService conditionOperatorService,
ISettingsService settingsService,
IEventAggregator eventAggregator) : base(displayConditionPredicate)
IEventAggregator eventAggregator) : base(dataModelConditionPredicate)
{
_profileEditorService = profileEditorService;
_dataModelUIService = dataModelUIService;
@ -61,8 +61,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
Initialize();
}
public DisplayConditionPredicate DisplayConditionPredicate => (DisplayConditionPredicate) Model;
public bool ShowRightSidePropertySelection => DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic;
public DataModelConditionPredicate DataModelConditionPredicate => (DataModelConditionPredicate) Model;
public bool ShowRightSidePropertySelection => DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic;
public bool CanActivateRightSideInputViewModel => SelectedLeftSideProperty?.PropertyInfo != null;
public PluginSetting<bool> ShowDataModelValues { get; }
@ -188,46 +188,46 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public override void Update()
{
if (LeftSideDataModel == null || DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic && RightSideDataModel == null)
if (LeftSideDataModel == null || DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic && RightSideDataModel == null)
return;
// If static, only allow selecting properties also supported by input
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Static)
if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
// Determine the left side property first
SelectedLeftSideProperty = LeftSideDataModel.GetChildForCondition(DisplayConditionPredicate, DisplayConditionSide.Left);
SelectedLeftSideProperty = LeftSideDataModel.GetChildForCondition(DataModelConditionPredicate, DisplayConditionSide.Left);
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
// Get the supported operators
Operators.Clear();
Operators.AddRange(_conditionOperatorService.GetConditionOperatorsForType(leftSideType));
if (DisplayConditionPredicate.Operator == null)
DisplayConditionPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType)));
SelectedOperator = DisplayConditionPredicate.Operator;
if (DataModelConditionPredicate.Operator == null)
DataModelConditionPredicate.UpdateOperator(Operators.FirstOrDefault(o => o.SupportsType(leftSideType)));
SelectedOperator = DataModelConditionPredicate.Operator;
// Determine the right side
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic)
if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic)
{
SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DisplayConditionPredicate, DisplayConditionSide.Right);
SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DataModelConditionPredicate, DisplayConditionSide.Right);
RightSideDataModel.ApplyTypeFilter(true, leftSideType);
}
else
RightStaticValue = DisplayConditionPredicate.RightStaticValue;
RightStaticValue = DataModelConditionPredicate.RightStaticValue;
}
public void ApplyLeftSide()
{
DisplayConditionPredicate.UpdateLeftSide(SelectedLeftSideProperty.DataModel, SelectedLeftSideProperty.PropertyPath);
DataModelConditionPredicate.UpdateLeftSide(SelectedLeftSideProperty.DataModel, SelectedLeftSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
SelectedOperator = DisplayConditionPredicate.Operator;
SelectedOperator = DataModelConditionPredicate.Operator;
Update();
}
public void ApplyRightSideDynamic()
{
DisplayConditionPredicate.UpdateRightSide(SelectedRightSideProperty.DataModel, SelectedRightSideProperty.PropertyPath);
DataModelConditionPredicate.UpdateRightSide(SelectedRightSideProperty.DataModel, SelectedRightSideProperty.PropertyPath);
_profileEditorService.UpdateSelectedProfileElement();
Update();
@ -237,7 +237,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
{
if (isSubmitted)
{
DisplayConditionPredicate.UpdateRightSide(value);
DataModelConditionPredicate.UpdateRightSide(value);
_profileEditorService.UpdateSelectedProfileElement();
Update();
@ -251,7 +251,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
public void ApplyOperator()
{
DisplayConditionPredicate.UpdateOperator(SelectedOperator);
DataModelConditionPredicate.UpdateOperator(SelectedOperator);
_profileEditorService.UpdateSelectedProfileElement();
Update();
@ -266,7 +266,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
RightSideInputViewModel = _dataModelUIService.GetDataModelInputViewModel(
SelectedLeftSideProperty.PropertyInfo.PropertyType,
SelectedLeftSideProperty.PropertyDescription,
DisplayConditionPredicate.RightStaticValue,
DataModelConditionPredicate.RightStaticValue,
ApplyRightSideStatic
);
_eventAggregator.Subscribe(this);
@ -283,8 +283,8 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void RightDataModelUpdateRequested(object sender, EventArgs e)
{
var leftSideType = SelectedLeftSideProperty?.PropertyInfo?.PropertyType;
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Dynamic)
SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DisplayConditionPredicate, DisplayConditionSide.Right);
if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Dynamic)
SelectedRightSideProperty = LeftSideDataModel.GetChildForCondition(DataModelConditionPredicate, DisplayConditionSide.Right);
// With the data model updated, also reapply the filter
RightSideDataModel.ApplyTypeFilter(true, leftSideType);
@ -292,7 +292,7 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
private void LeftDataModelUpdateRequested(object sender, EventArgs e)
{
if (DisplayConditionPredicate.PredicateType == ProfileRightSideType.Static)
if (DataModelConditionPredicate.PredicateType == ProfileRightSideType.Static)
LeftSideDataModel.ApplyTypeFilter(false, _supportedInputTypes.ToArray());
}

View File

@ -82,10 +82,10 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
}
// Ensure the layer has a root display condition group
if (e.RenderProfileElement.DisplayConditionGroup == null)
e.RenderProfileElement.DisplayConditionGroup = new DisplayConditionGroup(null);
if (e.RenderProfileElement.DataModelConditionGroup == null)
e.RenderProfileElement.DataModelConditionGroup = new DataModelConditionGroup(null);
ActiveItem = _displayConditionsVmFactory.DisplayConditionGroupViewModel(e.RenderProfileElement.DisplayConditionGroup, false);
ActiveItem = _displayConditionsVmFactory.DisplayConditionGroupViewModel(e.RenderProfileElement.DataModelConditionGroup, false);
ActiveItem.IsRootGroup = true;
ActiveItem.Update();