mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core - Reworked brush/effect property storage
Profile editor - Added brush selection Profile editor - Added playback controls
This commit is contained in:
1 parent
022beb6a48
commit
1832a25426
64 files changed
+1168
-481
No files matched your search
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
@@ -24,6 +25,7 @@ namespace Artemis.Core.LayerBrushes
|
||||
// Both are set right after construction to keep the constructor of inherited classes clean
|
||||
_layer = null!;
|
||||
_descriptor = null!;
|
||||
LayerBrushEntity = null!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -35,6 +37,11 @@ namespace Artemis.Core.LayerBrushes
|
||||
internal set => SetAndNotify(ref _layer, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the brush entity this brush uses for persistent storage
|
||||
/// </summary>
|
||||
public LayerBrushEntity LayerBrushEntity { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the descriptor of this brush
|
||||
/// </summary>
|
||||
@@ -185,6 +192,13 @@ namespace Artemis.Core.LayerBrushes
|
||||
public override string BrokenDisplayName => Descriptor.DisplayName;
|
||||
|
||||
#endregion
|
||||
|
||||
internal void Save()
|
||||
{
|
||||
// No need to update the type or provider ID, they're set once by the LayerBrushDescriptors CreateInstance and can't change
|
||||
BaseProperties?.ApplyToEntity();
|
||||
LayerBrushEntity.PropertyGroup = BaseProperties?.PropertyGroupEntity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
{
|
||||
@@ -32,12 +33,11 @@ namespace Artemis.Core.LayerBrushes
|
||||
internal set => _properties = value;
|
||||
}
|
||||
|
||||
internal void InitializeProperties()
|
||||
internal void InitializeProperties(PropertyGroupEntity? propertyGroupEntity)
|
||||
{
|
||||
Properties = Activator.CreateInstance<T>();
|
||||
Properties.GroupDescription = new PropertyGroupDescriptionAttribute {Name = Descriptor.DisplayName, Description = Descriptor.Description};
|
||||
Properties.LayerBrush = this;
|
||||
Properties.Initialize(Layer, "LayerBrush.", Descriptor.Provider);
|
||||
PropertyGroupDescriptionAttribute groupDescription = new() {Identifier = "Brush", Name = Descriptor.DisplayName, Description = Descriptor.Description};
|
||||
Properties.Initialize(Layer, null, groupDescription, propertyGroupEntity);
|
||||
PropertiesInitialized = true;
|
||||
|
||||
EnableLayerBrush();
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Artemis.Core.LayerBrushes
|
||||
|
||||
internal override void Initialize()
|
||||
{
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
TryOrBreak(() => InitializeProperties(Layer.LayerEntity.LayerBrush?.PropertyGroup), "Failed to initialize");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Ninject;
|
||||
|
||||
namespace Artemis.Core.LayerBrushes
|
||||
@@ -57,23 +58,20 @@ namespace Artemis.Core.LayerBrushes
|
||||
/// <summary>
|
||||
/// Creates an instance of the described brush and applies it to the layer
|
||||
/// </summary>
|
||||
internal void CreateInstance(Layer layer)
|
||||
public BaseLayerBrush CreateInstance(Layer layer, LayerBrushEntity? entity)
|
||||
{
|
||||
if (layer == null) throw new ArgumentNullException(nameof(layer));
|
||||
if (layer.LayerBrush != null)
|
||||
throw new ArtemisCoreException("Layer already has an instantiated layer brush");
|
||||
if (layer == null)
|
||||
throw new ArgumentNullException(nameof(layer));
|
||||
|
||||
BaseLayerBrush brush = (BaseLayerBrush) Provider.Plugin.Kernel!.Get(LayerBrushType);
|
||||
brush.Layer = layer;
|
||||
brush.Descriptor = this;
|
||||
brush.LayerBrushEntity = entity ?? new LayerBrushEntity { ProviderId = Provider.Id, BrushType = LayerBrushType.FullName };
|
||||
|
||||
brush.Initialize();
|
||||
brush.Update(0);
|
||||
|
||||
layer.LayerBrush = brush;
|
||||
layer.OnLayerBrushUpdated();
|
||||
|
||||
if (layer.ShouldBeEnabled)
|
||||
brush.InternalEnable();
|
||||
return brush;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace Artemis.Core.LayerBrushes
|
||||
|
||||
internal override void Initialize()
|
||||
{
|
||||
TryOrBreak(InitializeProperties, "Failed to initialize");
|
||||
TryOrBreak(() => InitializeProperties(Layer.LayerEntity.LayerBrush?.PropertyGroup), "Failed to initialize");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Artemis.Core.LayerEffects
|
||||
@@ -24,16 +25,13 @@ namespace Artemis.Core.LayerEffects
|
||||
_profileElement = null!;
|
||||
_descriptor = null!;
|
||||
_name = null!;
|
||||
LayerEffectEntity = null!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique ID of this effect
|
||||
/// Gets the
|
||||
/// </summary>
|
||||
public Guid EntityId
|
||||
{
|
||||
get => _entityId;
|
||||
internal set => SetAndNotify(ref _entityId, value);
|
||||
}
|
||||
public LayerEffectEntity LayerEffectEntity { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile element (such as layer or folder) this effect is applied to
|
||||
@@ -109,8 +107,6 @@ namespace Artemis.Core.LayerEffects
|
||||
/// </summary>
|
||||
public virtual LayerPropertyGroup? BaseProperties => null;
|
||||
|
||||
internal string PropertyRootPath => $"LayerEffect.{EntityId}.{GetType().Name}.";
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the layer effect is enabled or not
|
||||
/// </summary>
|
||||
@@ -227,5 +223,17 @@ namespace Artemis.Core.LayerEffects
|
||||
public override string BrokenDisplayName => Name;
|
||||
|
||||
#endregion
|
||||
|
||||
public void Save()
|
||||
{
|
||||
// No need to update the ID, type and provider ID. They're set once by the LayerBrushDescriptors CreateInstance and can't change
|
||||
LayerEffectEntity.Name = Name;
|
||||
LayerEffectEntity.Suspended = Suspended;
|
||||
LayerEffectEntity.HasBeenRenamed = HasBeenRenamed;
|
||||
LayerEffectEntity.Order = Order;
|
||||
|
||||
BaseProperties?.ApplyToEntity();
|
||||
LayerEffectEntity.PropertyGroup = BaseProperties?.PropertyGroupEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,8 +36,7 @@ namespace Artemis.Core.LayerEffects
|
||||
internal void InitializeProperties()
|
||||
{
|
||||
Properties = Activator.CreateInstance<T>();
|
||||
Properties.LayerEffect = this;
|
||||
Properties.Initialize(ProfileElement, PropertyRootPath, Descriptor.Provider);
|
||||
Properties.Initialize(ProfileElement, null, new PropertyGroupDescriptionAttribute(){Identifier = "LayerEffect"}, LayerEffectEntity.PropertyGroup);
|
||||
PropertiesInitialized = true;
|
||||
|
||||
EnableLayerEffect();
|
||||
|
||||
@@ -54,11 +54,28 @@ namespace Artemis.Core.LayerEffects
|
||||
/// <summary>
|
||||
/// Creates an instance of the described effect and applies it to the render element
|
||||
/// </summary>
|
||||
internal void CreateInstance(RenderProfileElement renderElement, LayerEffectEntity entity)
|
||||
internal void CreateInstance(RenderProfileElement renderElement, LayerEffectEntity? entity)
|
||||
{
|
||||
// Skip effects already on the element
|
||||
if (renderElement.LayerEffects.Any(e => e.EntityId == entity.Id))
|
||||
return;
|
||||
if (LayerEffectType == null)
|
||||
throw new ArtemisCoreException("Cannot create an instance of a layer effect because this descriptor is not a placeholder but is still missing its LayerEffectType");
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new LayerEffectEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Suspended = false,
|
||||
Order = renderElement.LayerEffects.Count + 1,
|
||||
ProviderId = Provider.Id,
|
||||
EffectType = LayerEffectType.FullName
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// Skip effects already on the element
|
||||
if (renderElement.LayerEffects.Any(e => e.LayerEffectEntity.Id == entity.Id))
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlaceholderFor != null)
|
||||
{
|
||||
@@ -66,12 +83,9 @@ namespace Artemis.Core.LayerEffects
|
||||
return;
|
||||
}
|
||||
|
||||
if (LayerEffectType == null)
|
||||
throw new ArtemisCoreException("Cannot create an instance of a layer effect because this descriptor is not a placeholder but is still missing its LayerEffectType");
|
||||
|
||||
BaseLayerEffect effect = (BaseLayerEffect) Provider.Plugin.Kernel!.Get(LayerEffectType);
|
||||
effect.ProfileElement = renderElement;
|
||||
effect.EntityId = entity.Id;
|
||||
effect.LayerEffectEntity = entity;
|
||||
effect.Order = entity.Order;
|
||||
effect.Name = entity.Name;
|
||||
effect.Suspended = entity.Suspended;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Artemis.Core.LayerEffects.Placeholder
|
||||
OriginalEntity = originalEntity;
|
||||
PlaceholderFor = placeholderFor;
|
||||
|
||||
EntityId = OriginalEntity.Id;
|
||||
LayerEffectEntity = originalEntity;
|
||||
Order = OriginalEntity.Order;
|
||||
Name = OriginalEntity.Name;
|
||||
Suspended = OriginalEntity.Suspended;
|
||||
|
||||
Reference in new issue
Block a user