mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Display conditions - Added basic models
Display conditions - Added externally registerable condition operators Display conditions - Added GreaterThan condition for testing
This commit is contained in:
1 parent
6ee06b2fc5
commit
55555ed6a8
12 files changed
+248
-10
No files matched your search
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Abstract
|
||||
{
|
||||
public abstract class LayerConditionPart
|
||||
{
|
||||
protected LayerConditionPart()
|
||||
{
|
||||
Children = new List<LayerConditionPart>();
|
||||
}
|
||||
|
||||
public List<LayerConditionPart> Children { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
public class LayerCondition
|
||||
{
|
||||
public Expression<Func<DataModel, bool>> ExpressionTree { get; set; }
|
||||
public LayerConditionGroup RootGroup { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public class LayerConditionGroup : LayerConditionPart
|
||||
{
|
||||
public BooleanOperator BooleanOperator { get; set; }
|
||||
}
|
||||
|
||||
public enum BooleanOperator
|
||||
{
|
||||
And,
|
||||
Or,
|
||||
AndNot,
|
||||
OrNot
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public class LayerConditionListStatement : LayerConditionPart
|
||||
{
|
||||
public ListOperator ListOperator { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public enum ListOperator
|
||||
{
|
||||
Any,
|
||||
All,
|
||||
None,
|
||||
Count
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public abstract class LayerConditionOperator
|
||||
{
|
||||
private IDataModelService _dataModelService;
|
||||
private bool _registered;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the plugin info this condition operator belongs to
|
||||
/// <para>Note: Not set until after registering</para>
|
||||
/// </summary>
|
||||
public PluginInfo PluginInfo { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the types this operator supports
|
||||
/// </summary>
|
||||
public abstract IReadOnlyCollection<Type> CompatibleTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the description of this logical operator
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the icon of this logical operator
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a binary expression comparing two types
|
||||
/// </summary>
|
||||
/// <param name="leftSideType">The type of parameter passed to the left side of the expression</param>
|
||||
/// <param name="rightSideType">The type of parameter passed to the right side of the expression</param>
|
||||
/// <returns></returns>
|
||||
public abstract BinaryExpression CreateExpression(Type leftSideType, Type rightSideType);
|
||||
|
||||
internal void Register(PluginInfo pluginInfo, IDataModelService dataModelService)
|
||||
{
|
||||
if (_registered)
|
||||
return;
|
||||
|
||||
PluginInfo = pluginInfo;
|
||||
_dataModelService = dataModelService;
|
||||
|
||||
if (PluginInfo != Constants.CorePluginInfo)
|
||||
PluginInfo.Instance.PluginDisabled += InstanceOnPluginDisabled;
|
||||
|
||||
_registered = true;
|
||||
}
|
||||
|
||||
internal void Unsubscribe()
|
||||
{
|
||||
if (!_registered)
|
||||
return;
|
||||
|
||||
if (PluginInfo != Constants.CorePluginInfo)
|
||||
PluginInfo.Instance.PluginDisabled -= InstanceOnPluginDisabled;
|
||||
_registered = false;
|
||||
}
|
||||
|
||||
private void InstanceOnPluginDisabled(object sender, EventArgs e)
|
||||
{
|
||||
// Profile editor service will call Unsubscribe
|
||||
_dataModelService.RemoveConditionOperator(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public class LayerConditionStatement : LayerConditionPart
|
||||
{
|
||||
public Guid DataModelGuid { get; set; }
|
||||
public string PropertyPath { get; set; }
|
||||
|
||||
public LayerConditionOperator Operator { get; set; }
|
||||
public object Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class GreaterThanConditionOperator : LayerConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type>
|
||||
{
|
||||
typeof(sbyte),
|
||||
typeof(byte),
|
||||
typeof(short),
|
||||
typeof(ushort),
|
||||
typeof(int),
|
||||
typeof(uint),
|
||||
typeof(long),
|
||||
typeof(ulong),
|
||||
typeof(float),
|
||||
typeof(double),
|
||||
typeof(decimal)
|
||||
};
|
||||
|
||||
public override BinaryExpression CreateExpression(Type leftSideType, Type rightSideType)
|
||||
{
|
||||
var leftSideParameter = Expression.Parameter(leftSideType, "a");
|
||||
var rightSideParameter = Expression.Parameter(rightSideType, "b");
|
||||
return Expression.GreaterThan(leftSideParameter, rightSideParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user