Core - Streamlined public parts of profile creation

UI - Started adjusting the VMs for the layer refactor
This commit is contained in:
Robert authored and SpoinkyNL committed 2020-09-10 19:56:39 +02:00
1 parent 1de6fefc2a
commit c07ea09c9d
58 files changed
+694 -1196

No files matched your search

@@ -61,7 +61,7 @@ namespace Artemis.Core
/// <returns></returns>
public abstract bool EvaluateObject(object target);
internal abstract void ApplyToEntity();
internal abstract void Save();
internal abstract DisplayConditionPartEntity GetEntity();
#region IDisposable
@@ -105,14 +105,14 @@ namespace Artemis.Core
};
}
internal override void ApplyToEntity()
internal override void Save()
{
Entity.BooleanOperator = (int) BooleanOperator;
Entity.Children.Clear();
Entity.Children.AddRange(Children.Select(c => c.GetEntity()));
foreach (var child in Children)
child.ApplyToEntity();
child.Save();
}
internal override DisplayConditionPartEntity GetEntity()
@@ -116,7 +116,7 @@ namespace Artemis.Core
CompiledListAccessor = lambda.Compile();
}
internal override void ApplyToEntity()
internal override void Save()
{
// Target list
if (ListDataModel != null)
@@ -132,7 +132,7 @@ namespace Artemis.Core
Entity.Children.Clear();
Entity.Children.AddRange(Children.Select(c => c.GetEntity()));
foreach (var child in Children)
child.ApplyToEntity();
child.Save();
}
internal override DisplayConditionPartEntity GetEntity()
@@ -190,22 +190,31 @@ namespace Artemis.Core
return result;
}
internal override void ApplyToEntity()
internal override void Save()
{
Entity.PredicateType = (int) PredicateType;
Entity.ListDataModelGuid = ListDataModel?.PluginInfo?.Guid;
Entity.ListPropertyPath = ListPropertyPath;
if (ListDataModel != null)
{
Entity.ListDataModelGuid = ListDataModel.PluginInfo.Guid;
Entity.ListPropertyPath = ListPropertyPath;
}
Entity.LeftPropertyPath = LeftPropertyPath;
Entity.RightPropertyPath = RightPropertyPath;
Entity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue);
Entity.OperatorPluginGuid = Operator?.PluginInfo?.Guid;
Entity.OperatorType = Operator?.GetType().Name;
if (Operator != null)
{
Entity.OperatorPluginGuid = Operator.PluginInfo.Guid;
Entity.OperatorType = Operator.GetType().Name;
}
}
internal void Initialize()
private void Initialize()
{
ConditionOperatorStore.ConditionOperatorAdded += ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved += ConditionOperatorStoreOnConditionOperatorRemoved;
// Left side
if (Entity.LeftPropertyPath != null && ListContainsInnerPath(Entity.LeftPropertyPath))
UpdateLeftSide(Entity.LeftPropertyPath);
@@ -222,7 +231,7 @@ namespace Artemis.Core
if (PredicateType == ProfileRightSideType.Dynamic && Entity.RightPropertyPath != null)
{
if (ListContainsInnerPath(Entity.RightPropertyPath))
UpdateLeftSide(Entity.LeftPropertyPath);
UpdateRightSideDynamic(Entity.RightPropertyPath);
}
// Right side static
else if (PredicateType == ProfileRightSideType.Static && Entity.RightStaticValue != null)
@@ -384,5 +393,37 @@ namespace Artemis.Core
Expression.Property
);
}
#region Event handlers
private void ConditionOperatorStoreOnConditionOperatorAdded(object sender, ConditionOperatorStoreEvent e)
{
var conditionOperator = e.Registration.ConditionOperator;
if (Entity.OperatorPluginGuid == conditionOperator.PluginInfo.Guid && Entity.OperatorType == conditionOperator.GetType().Name)
UpdateOperator(conditionOperator);
}
private void ConditionOperatorStoreOnConditionOperatorRemoved(object sender, ConditionOperatorStoreEvent e)
{
if (e.Registration.ConditionOperator != Operator)
return;
Operator = null;
CompiledListPredicate = null;
}
#endregion
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;
base.Dispose(disposing);
}
#endregion
}
}
@@ -232,7 +232,7 @@ namespace Artemis.Core
return $"[Static] {LeftPropertyPath} {Operator.Description} {RightStaticValue}";
}
internal override void ApplyToEntity()
internal override void Save()
{
Entity.PredicateType = (int) PredicateType;
Entity.LeftDataModelGuid = LeftDataModel?.PluginInfo?.Guid;
@@ -250,6 +250,8 @@ namespace Artemis.Core
{
DataModelStore.DataModelAdded += DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved += DataModelStoreOnDataModelRemoved;
ConditionOperatorStore.ConditionOperatorAdded += ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved += ConditionOperatorStoreOnConditionOperatorRemoved;
// Left side
if (Entity.LeftDataModelGuid != null)
@@ -415,19 +417,6 @@ namespace Artemis.Core
);
}
private Expression CreateListAccessor(DataModel dataModel, string path, ParameterExpression listParameter)
{
var listType = dataModel.GetListTypeInPath(path);
if (listType == null)
throw new ArtemisCoreException($"Cannot create a list accessor at path {path} because the path does not contain a list");
path = dataModel.GetListInnerPath(path);
return path.Split('.').Aggregate<string, Expression>(
Expression.Convert(listParameter, listType), // Cast to the appropriate type
Expression.Property
);
}
#region Event handlers
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
@@ -454,6 +443,23 @@ namespace Artemis.Core
}
}
private void ConditionOperatorStoreOnConditionOperatorAdded(object sender, ConditionOperatorStoreEvent e)
{
var conditionOperator = e.Registration.ConditionOperator;
if (Entity.OperatorPluginGuid == conditionOperator.PluginInfo.Guid && Entity.OperatorType == conditionOperator.GetType().Name)
UpdateOperator(conditionOperator);
}
private void ConditionOperatorStoreOnConditionOperatorRemoved(object sender, ConditionOperatorStoreEvent e)
{
if (e.Registration.ConditionOperator != Operator)
return;
Operator = null;
CompiledStaticPredicate = null;
CompiledDynamicPredicate = null;
}
#endregion
/// <inheritdoc />
@@ -461,6 +467,8 @@ namespace Artemis.Core
{
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
ConditionOperatorStore.ConditionOperatorAdded -= ConditionOperatorStoreOnConditionOperatorAdded;
ConditionOperatorStore.ConditionOperatorRemoved -= ConditionOperatorStoreOnConditionOperatorRemoved;
base.Dispose(disposing);
}
+16 -20
View File
@@ -8,24 +8,35 @@ using SkiaSharp;
namespace Artemis.Core
{
/// <summary>
/// Represents a folder in a <see cref="Profile" />
/// </summary>
public sealed class Folder : RenderProfileElement
{
private SKBitmap _folderBitmap;
public Folder(Profile profile, ProfileElement parent, string name)
/// <summary>
/// Creates a new instance of the <see cref="Folder" /> class and adds itself to the child collection of the provided
/// <paramref name="parent" />
/// </summary>
/// <param name="parent">The parent of the folder</param>
/// <param name="name">The name of the folder</param>
public Folder(ProfileElement parent, string name)
{
FolderEntity = new FolderEntity();
EntityId = Guid.NewGuid();
Profile = profile;
Parent = parent;
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
Profile = Parent.Profile;
Name = name;
Enabled = true;
DisplayContinuously = true;
_layerEffects = new List<BaseLayerEffect>();
_expandedPropertyGroups = new List<string>();
ApplyRenderElementDefaults();
Parent.AddChild(this);
}
internal Folder(Profile profile, ProfileElement parent, FolderEntity folderEntity)
@@ -182,22 +193,7 @@ namespace Artemis.Core
canvas.Restore();
}
/// <summary>
/// Adds a new folder to the bottom of this folder
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public Folder AddFolder(string name)
{
if (_disposed)
throw new ObjectDisposedException("Folder");
var folder = new Folder(Profile, this, name) {Order = Children.LastOrDefault()?.Order ?? 1};
AddChild(folder);
return folder;
}
/// <inheritdoc />
public override void AddChild(ProfileElement child, int? order = null)
{
@@ -296,7 +292,7 @@ namespace Artemis.Core
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.ApplyToEntity();
DisplayConditionGroup?.Save();
SaveRenderElement();
}
+44 -12
View File
@@ -11,8 +11,7 @@ using SkiaSharp;
namespace Artemis.Core
{
/// <summary>
/// Represents a layer on a profile. To create new layers use the <see cref="RenderElementService" /> by injecting
/// <see cref="IRenderElementService" /> into your code
/// Represents a layer in a <see cref="Profile" />
/// </summary>
public sealed class Layer : RenderProfileElement
{
@@ -23,13 +22,19 @@ namespace Artemis.Core
private List<ArtemisLed> _leds;
private LayerTransformProperties _transform;
internal Layer(Profile profile, ProfileElement parent, string name)
/// <summary>
/// Creates a new instance of the <see cref="Layer" /> class and adds itself to the child collection of the provided
/// <paramref name="parent" />
/// </summary>
/// <param name="parent">The parent of the layer</param>
/// <param name="name">The name of the layer</param>
public Layer(ProfileElement parent, string name)
{
LayerEntity = new LayerEntity();
EntityId = Guid.NewGuid();
Profile = profile;
Parent = parent;
Parent = parent ?? throw new ArgumentNullException(nameof(parent));
Profile = Parent.Profile;
Name = name;
Enabled = true;
DisplayContinuously = true;
@@ -40,10 +45,10 @@ namespace Artemis.Core
_leds = new List<ArtemisLed>();
_expandedPropertyGroups = new List<string>();
InitializeDefaultGroups();
parent.AddChild(this);
Initialize();
ApplyRenderElementDefaults();
Parent.AddChild(this);
}
internal Layer(Profile profile, ProfileElement parent, LayerEntity layerEntity)
@@ -58,8 +63,7 @@ namespace Artemis.Core
_leds = new List<ArtemisLed>();
_expandedPropertyGroups = new List<string>();
InitializeDefaultGroups();
Initialize();
Load();
}
@@ -114,6 +118,8 @@ namespace Artemis.Core
return $"[Layer] {nameof(Name)}: {Name}, {nameof(Order)}: {Order}";
}
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
@@ -133,8 +139,13 @@ namespace Artemis.Core
_transform?.Dispose();
}
private void InitializeDefaultGroups()
#endregion
private void Initialize()
{
LayerBrushStore.LayerBrushAdded += LayerBrushStoreOnLayerBrushAdded;
LayerBrushStore.LayerBrushRemoved += LayerBrushStoreOnLayerBrushRemoved;
// Layers have two hardcoded property groups, instantiate them
General.Initialize(this, "General.", Constants.CorePluginInfo);
Transform.Initialize(this, "Transform.", Constants.CorePluginInfo);
@@ -191,7 +202,7 @@ namespace Artemis.Core
// Conditions
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.Entity;
DisplayConditionGroup?.ApplyToEntity();
DisplayConditionGroup?.Save();
SaveRenderElement();
}
@@ -711,6 +722,27 @@ namespace Artemis.Core
#endregion
#region Event handlers
private void LayerBrushStoreOnLayerBrushRemoved(object sender, LayerBrushStoreEvent e)
{
if (LayerBrush.Descriptor == e.Registration.LayerBrushDescriptor)
DeactivateLayerBrush();
}
private void LayerBrushStoreOnLayerBrushAdded(object sender, LayerBrushStoreEvent e)
{
if (LayerBrush != null)
return;
var current = General.BrushReference.CurrentValue;
if (e.Registration.Plugin.PluginInfo.Guid == current.BrushPluginGuid &&
e.Registration.LayerBrushDescriptor.LayerBrushType.Name == current.BrushType)
ActivateLayerBrush();
}
#endregion
#region Events
public event EventHandler RenderPropertiesUpdated;
+6 -2
View File
@@ -16,17 +16,19 @@ namespace Artemis.Core
ProfileEntity = new ProfileEntity();
EntityId = Guid.NewGuid();
Profile = this;
Module = module;
Name = name;
UndoStack = new Stack<string>();
RedoStack = new Stack<string>();
AddChild(new Folder(this, this, "Root folder"));
var _ = new Folder(this, "Root folder");
Save();
}
internal Profile(ProfileModule module, ProfileEntity profileEntity)
{
Profile = this;
ProfileEntity = profileEntity;
EntityId = profileEntity.Id;
@@ -103,7 +105,9 @@ namespace Artemis.Core
// Populate the profile starting at the root, the rest is populated recursively
var rootFolder = ProfileEntity.Folders.FirstOrDefault(f => f.ParentId == EntityId);
if (rootFolder == null)
AddChild(new Folder(this, this, "Root folder"));
{
var _ = new Folder(this, "Root folder");
}
else
AddChild(new Folder(this, this, rootFolder));
}
@@ -110,9 +110,12 @@ namespace Artemis.Core
{
if (_disposed)
throw new ObjectDisposedException(GetType().Name);
lock (ChildrenList)
{
if (ChildrenList.Contains(child))
return;
// Add to the end of the list
if (order == null)
{
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.LayerEffects;
using Artemis.Core.LayerEffects.Placeholder;
using Artemis.Core.Properties;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Entities.Profile.Abstract;
@@ -49,7 +50,7 @@ namespace Artemis.Core
{
Id = layerEffect.EntityId,
PluginGuid = layerEffect.PluginInfo.Guid,
EffectType = layerEffect.GetType().Name,
EffectType = layerEffect.GetEffectTypeName(),
Name = layerEffect.Name,
Enabled = layerEffect.Enabled,
HasBeenRenamed = layerEffect.HasBeenRenamed,
@@ -268,11 +269,29 @@ namespace Artemis.Core
{
foreach (var layerEffectEntity in RenderElementEntity.LayerEffects)
{
if (_layerEffects.Any(e => e.EntityId == layerEffectEntity.Id))
// If there is a non-placeholder existing effect, skip this entity
var existing = _layerEffects.FirstOrDefault(e => e.EntityId == layerEffectEntity.Id);
if (existing != null && !existing.Descriptor.IsPlaceHolder)
continue;
var descriptor = LayerEffectStore.Get(layerEffectEntity.PluginGuid, layerEffectEntity.EffectType)?.LayerEffectDescriptor;
descriptor?.CreateInstance(this, layerEffectEntity);
if (descriptor != null)
{
// If a descriptor is found but there is an existing placeholder, remove the placeholder
if (existing != null)
{
_layerEffects.Remove(existing);
existing.Dispose();
}
// Create an instance with the descriptor
descriptor.CreateInstance(this, layerEffectEntity);
}
else if (existing == null)
{
// If no descriptor was found and there was no existing placeholder, create a placeholder
descriptor = PlaceholderLayerEffectDescriptor.Create();
descriptor.CreateInstance(this, layerEffectEntity);
}
}
}
@@ -297,9 +316,10 @@ namespace Artemis.Core
throw new NotImplementedException();
}
private void LayerEffectStoreOnLayerEffectAdded(object? sender, LayerEffectStoreEvent e)
private void LayerEffectStoreOnLayerEffectAdded(object sender, LayerEffectStoreEvent e)
{
ActivateEffects();
if (RenderElementEntity.LayerEffects.Any(ef => ef.PluginGuid == e.Registration.Plugin.PluginInfo.Guid))
ActivateEffects();
}
#endregion