Core - Added ways for the core to easily access brush properties

%*/@ me, dealing with generic types in APIs is tricky
This commit is contained in:
Robert committed 2020-04-29 12:49:11 +02:00
1 parent 492ee5c8c1
commit bbeb471754
7 files changed
+145 -41

No files matched your search

@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.Events;
using Artemis.Core.Exceptions;
using Artemis.Core.Models.Profile.LayerProperties;
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
using Artemis.Core.Plugins.Exceptions;
@@ -10,13 +13,31 @@ namespace Artemis.Core.Models.Profile
{
public class LayerPropertyGroup
{
private ReadOnlyCollection<BaseLayerProperty> _allLayerProperties;
protected LayerPropertyGroup()
{
LayerProperties = new List<BaseLayerProperty>();
LayerPropertyGroups = new List<LayerPropertyGroup>();
}
public bool PropertiesInitialized { get; private set; }
/// <summary>
/// Used to declare that this property group doesn't belong to a plugin and should use the core plugin GUID
/// Used to declare that this property group doesn't belong to a plugin and should use the core plugin GUID
/// </summary>
internal bool IsCorePropertyGroup { get; set; }
/// <summary>
/// A list of all layer properties in this group
/// </summary>
internal List<BaseLayerProperty> LayerProperties { get; set; }
/// <summary>
/// A list of al child groups in this group
/// </summary>
internal List<LayerPropertyGroup> LayerPropertyGroups { get; set; }
/// <summary>
/// Called when all layer properties in this property group have been initialized
/// </summary>
@@ -26,6 +47,10 @@ namespace Artemis.Core.Models.Profile
internal void InitializeProperties(ILayerService layerService, Layer layer, string path)
{
// Doubt this will happen but let's make sure
if (PropertiesInitialized)
throw new ArtemisCoreException("Layer property group already initialized, wut");
// Get all properties with a PropertyDescriptionAttribute
foreach (var propertyInfo in GetType().GetProperties())
{
@@ -38,6 +63,7 @@ namespace Artemis.Core.Models.Profile
var instance = (BaseLayerProperty) Activator.CreateInstance(propertyInfo.PropertyType);
InitializeProperty(layer, path, instance);
propertyInfo.SetValue(this, instance);
LayerProperties.Add(instance);
}
else
{
@@ -50,6 +76,7 @@ namespace Artemis.Core.Models.Profile
var instance = (LayerPropertyGroup) Activator.CreateInstance(propertyInfo.PropertyType);
instance.InitializeProperties(layerService, layer, $"{path}{propertyInfo.Name}.");
propertyInfo.SetValue(this, instance);
LayerPropertyGroups.Add(instance);
}
}
}
@@ -90,6 +117,25 @@ namespace Artemis.Core.Models.Profile
OnPropertyGroupOverriding(new PropertyGroupUpdatingEventArgs(overrideTime));
}
/// <summary>
/// Recursively gets all layer properties on this group and any subgroups
/// </summary>
/// <returns></returns>
internal IReadOnlyCollection<BaseLayerProperty> GetAllLayerProperties()
{
if (!PropertiesInitialized)
return new List<BaseLayerProperty>();
if (_allLayerProperties != null)
return _allLayerProperties;
var result = new List<BaseLayerProperty>(LayerProperties);
foreach (var layerPropertyGroup in LayerPropertyGroups)
result.AddRange(layerPropertyGroup.GetAllLayerProperties());
_allLayerProperties = result.AsReadOnly();
return _allLayerProperties;
}
private void InitializeProperty(Layer layer, string path, BaseLayerProperty instance)
{
var pluginGuid = IsCorePropertyGroup || instance.IsCoreProperty ? Constants.CorePluginInfo.Guid : layer.LayerBrush.PluginInfo.Guid;