mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Conditions - Refactor layer properties WIP
This commit is contained in:
1 parent
f3898b5500
commit
492ee5c8c1
33 files changed
+363
-492
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Profile.LayerProperties;
|
||||
using Artemis.Core.Models.Profile.LayerProperties.Attributes;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
@@ -11,6 +12,11 @@ namespace Artemis.Core.Models.Profile
|
||||
{
|
||||
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
|
||||
/// </summary>
|
||||
internal bool IsCorePropertyGroup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called when all layer properties in this property group have been initialized
|
||||
/// </summary>
|
||||
@@ -26,10 +32,10 @@ namespace Artemis.Core.Models.Profile
|
||||
var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute));
|
||||
if (propertyDescription != null)
|
||||
{
|
||||
if (!typeof(GenericLayerProperty<>).IsAssignableFrom(propertyInfo.PropertyType))
|
||||
if (!typeof(LayerProperty<>).IsAssignableFrom(propertyInfo.PropertyType))
|
||||
throw new ArtemisPluginException("Layer property with PropertyDescription attribute must be of type LayerProperty");
|
||||
|
||||
var instance = (LayerProperty) Activator.CreateInstance(propertyInfo.PropertyType);
|
||||
var instance = (BaseLayerProperty) Activator.CreateInstance(propertyInfo.PropertyType);
|
||||
InitializeProperty(layer, path, instance);
|
||||
propertyInfo.SetValue(this, instance);
|
||||
}
|
||||
@@ -52,11 +58,61 @@ namespace Artemis.Core.Models.Profile
|
||||
PropertiesInitialized = true;
|
||||
}
|
||||
|
||||
private void InitializeProperty(Layer layer, string path, LayerProperty instance)
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
var entity = layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.Id == path);
|
||||
if (entity != null)
|
||||
instance.LoadFromEntity(entity);
|
||||
// Get all properties with a PropertyDescriptionAttribute
|
||||
foreach (var propertyInfo in GetType().GetProperties())
|
||||
{
|
||||
var propertyDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyDescriptionAttribute));
|
||||
if (propertyDescription != null)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
var propertyGroupDescription = Attribute.GetCustomAttribute(propertyInfo, typeof(PropertyGroupDescriptionAttribute));
|
||||
if (propertyGroupDescription != null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Update(double deltaTime)
|
||||
{
|
||||
// Since at this point we don't know what properties the group has without using reflection,
|
||||
// let properties subscribe to the update event and update themselves
|
||||
OnPropertyGroupUpdating(new PropertyGroupUpdatingEventArgs(deltaTime));
|
||||
}
|
||||
|
||||
internal void Override(TimeSpan overrideTime)
|
||||
{
|
||||
// Same as above, but now the progress is overridden
|
||||
OnPropertyGroupOverriding(new PropertyGroupUpdatingEventArgs(overrideTime));
|
||||
}
|
||||
|
||||
private void InitializeProperty(Layer layer, string path, BaseLayerProperty instance)
|
||||
{
|
||||
var pluginGuid = IsCorePropertyGroup || instance.IsCoreProperty ? Constants.CorePluginInfo.Guid : layer.LayerBrush.PluginInfo.Guid;
|
||||
var entity = layer.LayerEntity.PropertyEntities.FirstOrDefault(p => p.PluginGuid == pluginGuid && p.Path == path);
|
||||
if (entity != null)
|
||||
instance.ApplyToLayerProperty(entity, this);
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
internal event EventHandler<PropertyGroupUpdatingEventArgs> PropertyGroupUpdating;
|
||||
internal event EventHandler<PropertyGroupUpdatingEventArgs> PropertyGroupOverriding;
|
||||
|
||||
internal virtual void OnPropertyGroupUpdating(PropertyGroupUpdatingEventArgs e)
|
||||
{
|
||||
PropertyGroupUpdating?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyGroupOverriding(PropertyGroupUpdatingEventArgs e)
|
||||
{
|
||||
PropertyGroupOverriding?.Invoke(this, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user