mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Core - Renamed LayerService to RenderElementService
Display conditions - Implemented persistent storage
This commit is contained in:
1 parent
16c2b7f7fd
commit
0e873a48cf
32 files changed
+209
-111
No files matched your search
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Abstract
|
||||
{
|
||||
public abstract class DisplayConditionPart
|
||||
{
|
||||
public Guid EntityId { get; internal set; }
|
||||
|
||||
private readonly List<DisplayConditionPart> _children;
|
||||
|
||||
protected DisplayConditionPart()
|
||||
@@ -36,6 +34,9 @@ namespace Artemis.Core.Models.Profile.Conditions.Abstract
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void ApplyToEntity();
|
||||
public abstract DisplayConditionPartEntity GetEntity();
|
||||
|
||||
internal abstract void ApplyToEntity();
|
||||
internal abstract void Initialize(IDataModelService dataModelService);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
@@ -9,7 +12,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
public DisplayConditionGroup(DisplayConditionPart parent)
|
||||
{
|
||||
Parent = parent;
|
||||
EntityId = Guid.NewGuid();
|
||||
DisplayConditionGroupEntity = new DisplayConditionGroupEntity();
|
||||
}
|
||||
|
||||
@@ -17,7 +19,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
Parent = parent;
|
||||
DisplayConditionGroupEntity = entity;
|
||||
EntityId = DisplayConditionGroupEntity.Id;
|
||||
BooleanOperator = (BooleanOperator) DisplayConditionGroupEntity.BooleanOperator;
|
||||
|
||||
foreach (var childEntity in DisplayConditionGroupEntity.Children)
|
||||
@@ -32,15 +33,26 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
public BooleanOperator BooleanOperator { get; set; }
|
||||
public DisplayConditionGroupEntity DisplayConditionGroupEntity { get; set; }
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
DisplayConditionGroupEntity.Id = EntityId;
|
||||
DisplayConditionGroupEntity.ParentId = Parent?.EntityId ?? Guid.Empty;
|
||||
DisplayConditionGroupEntity.BooleanOperator = (int) BooleanOperator;
|
||||
|
||||
DisplayConditionGroupEntity.Children.Clear();
|
||||
DisplayConditionGroupEntity.Children.AddRange(Children.Select(c => c.GetEntity()));
|
||||
foreach (var child in Children)
|
||||
child.ApplyToEntity();
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
{
|
||||
foreach (var child in Children)
|
||||
child.Initialize(dataModelService);
|
||||
}
|
||||
|
||||
public override DisplayConditionPartEntity GetEntity()
|
||||
{
|
||||
return DisplayConditionGroupEntity;
|
||||
}
|
||||
}
|
||||
|
||||
public enum BooleanOperator
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
@@ -6,9 +8,17 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public ListOperator ListOperator { get; set; }
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
{
|
||||
}
|
||||
|
||||
public override DisplayConditionPartEntity GetEntity()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@ using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
@@ -22,10 +25,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
Parent = parent;
|
||||
DisplayConditionPredicateEntity = entity;
|
||||
|
||||
// TODO: This has to be done from somewhere
|
||||
// LeftDataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.LeftDataModelGuid);
|
||||
// RightDataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.RightDataModelGuid);
|
||||
}
|
||||
|
||||
public DisplayConditionPredicateEntity DisplayConditionPredicateEntity { get; set; }
|
||||
@@ -122,13 +121,77 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
CreateStaticExpression();
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
DisplayConditionPredicateEntity.LeftDataModelGuid = LeftDataModel?.PluginInfo?.Guid;
|
||||
DisplayConditionPredicateEntity.LeftPropertyPath = LeftPropertyPath;
|
||||
|
||||
DisplayConditionPredicateEntity.RightDataModelGuid = RightDataModel?.PluginInfo?.Guid;
|
||||
DisplayConditionPredicateEntity.RightPropertyPath = RightPropertyPath;
|
||||
DisplayConditionPredicateEntity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue);
|
||||
|
||||
DisplayConditionPredicateEntity.OperatorPluginGuid = Operator?.PluginInfo?.Guid;
|
||||
DisplayConditionPredicateEntity.OperatorType = Operator?.GetType().Name;
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
{
|
||||
// Left side
|
||||
if (DisplayConditionPredicateEntity.LeftDataModelGuid != null)
|
||||
{
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.LeftDataModelGuid.Value);
|
||||
if (dataModel != null)
|
||||
UpdateLeftSide(dataModel, DisplayConditionPredicateEntity.LeftPropertyPath);
|
||||
}
|
||||
|
||||
// Operator
|
||||
if (DisplayConditionPredicateEntity.OperatorPluginGuid != null)
|
||||
{
|
||||
var conditionOperator = dataModelService.GetConditionOperator(DisplayConditionPredicateEntity.OperatorPluginGuid.Value, DisplayConditionPredicateEntity.OperatorType);
|
||||
if (conditionOperator != null)
|
||||
UpdateOperator(conditionOperator);
|
||||
}
|
||||
|
||||
// Right side dynamic
|
||||
if (DisplayConditionPredicateEntity.RightDataModelGuid != null)
|
||||
{
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.RightDataModelGuid.Value);
|
||||
if (dataModel != null)
|
||||
UpdateRightSide(dataModel, DisplayConditionPredicateEntity.RightPropertyPath);
|
||||
}
|
||||
// Right side static
|
||||
else if (DisplayConditionPredicateEntity.RightStaticValue != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (LeftDataModel != null)
|
||||
{
|
||||
// Use the left side type so JSON.NET has a better idea what to do
|
||||
var leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
|
||||
UpdateRightSide(JsonConvert.DeserializeObject(DisplayConditionPredicateEntity.RightStaticValue, leftSideType));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hope for the best...
|
||||
UpdateRightSide(JsonConvert.DeserializeObject(DisplayConditionPredicateEntity.RightStaticValue));
|
||||
}
|
||||
}
|
||||
catch (JsonReaderException)
|
||||
{
|
||||
// ignored
|
||||
// TODO: Some logging would be nice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override DisplayConditionPartEntity GetEntity()
|
||||
{
|
||||
return DisplayConditionPredicateEntity;
|
||||
}
|
||||
|
||||
private void ValidateOperator()
|
||||
{
|
||||
if (LeftDataModel == null)
|
||||
if (LeftDataModel == null || Operator == null)
|
||||
return;
|
||||
|
||||
var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
|
||||
@@ -136,7 +199,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
Operator = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validates the right side, ensuring it is still compatible with the current left side
|
||||
/// </summary>
|
||||
@@ -217,7 +279,7 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
|
||||
private void CreateStaticExpression()
|
||||
{
|
||||
if (LeftDataModel == null)
|
||||
if (LeftDataModel == null || Operator == null)
|
||||
return;
|
||||
|
||||
var leftSideParameter = Expression.Parameter(typeof(DataModel), "leftDataModel");
|
||||
|
||||
@@ -58,8 +58,7 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
|
||||
internal FolderEntity FolderEntity { get; set; }
|
||||
internal override PropertiesEntity PropertiesEntity => FolderEntity;
|
||||
internal override EffectsEntity EffectsEntity => FolderEntity;
|
||||
internal override RenderElementEntity RenderElementEntity => FolderEntity;
|
||||
|
||||
public override void Update(double deltaTime)
|
||||
{
|
||||
@@ -189,6 +188,7 @@ namespace Artemis.Core.Models.Profile
|
||||
ApplyLayerEffectsToEntity();
|
||||
|
||||
// Conditions
|
||||
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.DisplayConditionGroupEntity;
|
||||
DisplayConditionGroup?.ApplyToEntity();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ using SkiaSharp;
|
||||
namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a layer on a profile. To create new layers use the <see cref="LayerService" /> by injecting
|
||||
/// <see cref="ILayerService" /> into your code
|
||||
/// Represents a layer on a profile. To create new layers use the <see cref="RenderElementService" /> by injecting
|
||||
/// <see cref="IRenderElementService" /> into your code
|
||||
/// </summary>
|
||||
public sealed class Layer : RenderProfileElement
|
||||
{
|
||||
@@ -72,8 +72,7 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
|
||||
internal LayerEntity LayerEntity { get; set; }
|
||||
internal override PropertiesEntity PropertiesEntity => LayerEntity;
|
||||
internal override EffectsEntity EffectsEntity => LayerEntity;
|
||||
internal override RenderElementEntity RenderElementEntity => LayerEntity;
|
||||
|
||||
/// <summary>
|
||||
/// A collection of all the LEDs this layer is assigned to.
|
||||
@@ -158,6 +157,7 @@ namespace Artemis.Core.Models.Profile
|
||||
}
|
||||
|
||||
// Conditions
|
||||
RenderElementEntity.RootDisplayCondition = DisplayConditionGroup?.DisplayConditionGroupEntity;
|
||||
DisplayConditionGroup?.ApplyToEntity();
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Artemis.Core.Models.Profile
|
||||
PropertyGroupInitialized?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
internal void InitializeProperties(ILayerService layerService, RenderProfileElement profileElement, [NotNull] string path)
|
||||
internal void InitializeProperties(IRenderElementService renderElementService, RenderProfileElement profileElement, [NotNull] string path)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
@@ -177,7 +177,7 @@ namespace Artemis.Core.Models.Profile
|
||||
instance.GroupDescription = (PropertyGroupDescriptionAttribute) propertyGroupDescription;
|
||||
instance.LayerBrush = LayerBrush;
|
||||
instance.LayerEffect = LayerEffect;
|
||||
instance.InitializeProperties(layerService, profileElement, $"{path}{propertyInfo.Name}.");
|
||||
instance.InitializeProperties(renderElementService, profileElement, $"{path}{propertyInfo.Name}.");
|
||||
|
||||
propertyInfo.SetValue(this, instance);
|
||||
_layerPropertyGroups.Add(instance);
|
||||
@@ -246,13 +246,13 @@ namespace Artemis.Core.Models.Profile
|
||||
else
|
||||
pluginGuid = instance.Parent.LayerEffect.PluginInfo.Guid;
|
||||
|
||||
var entity = profileElement.PropertiesEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == pluginGuid && p.Path == path);
|
||||
var entity = profileElement.RenderElementEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == pluginGuid && p.Path == path);
|
||||
var fromStorage = true;
|
||||
if (entity == null)
|
||||
{
|
||||
fromStorage = false;
|
||||
entity = new PropertyEntity {PluginGuid = pluginGuid, Path = path};
|
||||
profileElement.PropertiesEntity.PropertyEntities.Add(entity);
|
||||
profileElement.RenderElementEntity.PropertyEntities.Add(entity);
|
||||
}
|
||||
|
||||
instance.ApplyToLayerProperty(entity, this, fromStorage);
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Artemis.Core.Models.Profile
|
||||
#region Properties
|
||||
|
||||
private SKPath _path;
|
||||
internal abstract PropertiesEntity PropertiesEntity { get; }
|
||||
internal abstract RenderElementEntity RenderElementEntity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path containing all the LEDs this entity is applied to, any rendering outside the entity Path is
|
||||
@@ -68,7 +68,6 @@ namespace Artemis.Core.Models.Profile
|
||||
#region Effects
|
||||
|
||||
protected List<BaseLayerEffect> _layerEffects;
|
||||
internal abstract EffectsEntity EffectsEntity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection of the layer effects on this entity
|
||||
@@ -77,7 +76,7 @@ namespace Artemis.Core.Models.Profile
|
||||
|
||||
protected void ApplyLayerEffectsToEntity()
|
||||
{
|
||||
EffectsEntity.LayerEffects.Clear();
|
||||
RenderElementEntity.LayerEffects.Clear();
|
||||
foreach (var layerEffect in LayerEffects)
|
||||
{
|
||||
var layerEffectEntity = new LayerEffectEntity
|
||||
@@ -90,7 +89,7 @@ namespace Artemis.Core.Models.Profile
|
||||
HasBeenRenamed = layerEffect.HasBeenRenamed,
|
||||
Order = layerEffect.Order
|
||||
};
|
||||
EffectsEntity.LayerEffects.Add(layerEffectEntity);
|
||||
RenderElementEntity.LayerEffects.Add(layerEffectEntity);
|
||||
layerEffect.BaseProperties.ApplyToEntity();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user