mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
UI - Centralized default editors registration into a service
Display conditions - Added more test operators Display conditions - Implemented operator selection Display conditions - Implemented property selection and rules
This commit is contained in:
1 parent
0ac6431755
commit
2ad78411c8
26 files changed
+470
-179
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
@@ -8,6 +9,24 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public abstract class DisplayConditionOperator
|
||||
{
|
||||
/// <summary>
|
||||
/// A read-only collection containing all primitive number types
|
||||
/// </summary>
|
||||
protected static IReadOnlyCollection<Type> NumberTypes = 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)
|
||||
};
|
||||
|
||||
private IDataModelService _dataModelService;
|
||||
private bool _registered;
|
||||
|
||||
@@ -25,12 +44,12 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
/// <summary>
|
||||
/// Gets or sets the description of this logical operator
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
public abstract string Description { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the icon of this logical operator
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
public abstract string Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a binary expression comparing two types
|
||||
@@ -69,5 +88,12 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
// Profile editor service will call Unsubscribe
|
||||
_dataModelService.RemoveConditionOperator(this);
|
||||
}
|
||||
|
||||
public bool SupportsType(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
return true;
|
||||
return CompatibleTypes.Any(t => t.IsAssignableFrom(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class EqualsConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> {typeof(object)};
|
||||
|
||||
public override string Description => "Equals";
|
||||
public override string Icon => "Equal";
|
||||
|
||||
public override BinaryExpression CreateExpression(Type leftSideType, Type rightSideType)
|
||||
{
|
||||
var leftSideParameter = Expression.Parameter(leftSideType, "a");
|
||||
var rightSideParameter = Expression.Parameter(rightSideType, "b");
|
||||
return Expression.Equal(leftSideParameter, rightSideParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-14
@@ -6,20 +6,10 @@ namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class GreaterThanConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
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 IReadOnlyCollection<Type> CompatibleTypes => NumberTypes;
|
||||
|
||||
public override string Description => "Is greater than";
|
||||
public override string Icon => "GreaterThan";
|
||||
|
||||
public override BinaryExpression CreateExpression(Type leftSideType, Type rightSideType)
|
||||
{
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class GreaterThanOrEqualConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => NumberTypes;
|
||||
|
||||
public override string Description => "Is greater than or equal to";
|
||||
public override string Icon => "GreaterThanOrEqual";
|
||||
|
||||
public override BinaryExpression CreateExpression(Type leftSideType, Type rightSideType)
|
||||
{
|
||||
var leftSideParameter = Expression.Parameter(leftSideType, "a");
|
||||
var rightSideParameter = Expression.Parameter(rightSideType, "b");
|
||||
return Expression.GreaterThanOrEqual(leftSideParameter, rightSideParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class LessThanConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => NumberTypes;
|
||||
|
||||
public override string Description => "Is less than";
|
||||
public override string Icon => "LessThan";
|
||||
|
||||
public override BinaryExpression CreateExpression(Type leftSideType, Type rightSideType)
|
||||
{
|
||||
var leftSideParameter = Expression.Parameter(leftSideType, "a");
|
||||
var rightSideParameter = Expression.Parameter(rightSideType, "b");
|
||||
return Expression.LessThan(leftSideParameter, rightSideParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class LessThanOrEqualConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => NumberTypes;
|
||||
|
||||
public override string Description => "Is less than or equal to";
|
||||
public override string Icon => "LessThanOrEqual";
|
||||
|
||||
public override BinaryExpression CreateExpression(Type leftSideType, Type rightSideType)
|
||||
{
|
||||
var leftSideParameter = Expression.Parameter(leftSideType, "a");
|
||||
var rightSideParameter = Expression.Parameter(rightSideType, "b");
|
||||
return Expression.LessThanOrEqual(leftSideParameter, rightSideParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Operators
|
||||
{
|
||||
public class NotEqualConditionOperator : DisplayConditionOperator
|
||||
{
|
||||
public override IReadOnlyCollection<Type> CompatibleTypes => new List<Type> { typeof(object) };
|
||||
|
||||
public override string Description => "Does not equal";
|
||||
public override string Icon => "NotEqualVariant";
|
||||
|
||||
public override BinaryExpression CreateExpression(Type leftSideType, Type rightSideType)
|
||||
{
|
||||
var leftSideParameter = Expression.Parameter(leftSideType, "a");
|
||||
var rightSideParameter = Expression.Parameter(rightSideType, "b");
|
||||
return Expression.NotEqual(leftSideParameter, rightSideParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,18 @@ namespace Artemis.Core.Services
|
||||
AddDataModelExpansionDataModel(dataModelExpansion);
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<DataModel> DataModelExpansions
|
||||
public IReadOnlyCollection<DisplayConditionOperator> RegisteredConditionOperators
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
return _registeredConditionOperators.AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyCollection<DataModel> DataModelExpansions
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -128,13 +139,20 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
lock (_registeredConditionOperators)
|
||||
{
|
||||
return _registeredConditionOperators.Where(c => c.CompatibleTypes.Contains(type)).ToList();
|
||||
if (type == null)
|
||||
return new List<DisplayConditionOperator>(_registeredConditionOperators);
|
||||
return _registeredConditionOperators.Where(c => c.CompatibleTypes.Any(t => t.IsAssignableFrom(type))).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterBuiltInConditionOperators()
|
||||
{
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new EqualsConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new NotEqualConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new LessThanConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new GreaterThanConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new LessThanOrEqualConditionOperator());
|
||||
RegisterConditionOperator(Constants.CorePluginInfo, new GreaterThanOrEqualConditionOperator());
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Annotations;
|
||||
using Artemis.Core.Models.Profile.Conditions;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
@@ -9,7 +10,8 @@ namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
public interface IDataModelService : IArtemisService
|
||||
{
|
||||
ReadOnlyCollection<DataModel> DataModelExpansions { get; }
|
||||
IReadOnlyCollection<DisplayConditionOperator> RegisteredConditionOperators { get; }
|
||||
IReadOnlyCollection<DataModel> DataModelExpansions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Add an expansion to the datamodel to be available for use after the next update
|
||||
@@ -48,5 +50,7 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// </summary>
|
||||
/// <param name="displayConditionOperator">The layer condition operator to remove</param>
|
||||
void RemoveConditionOperator([NotNull] DisplayConditionOperator displayConditionOperator);
|
||||
|
||||
List<DisplayConditionOperator> GetCompatibleConditionOperators(Type type);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user