mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 20:06:33 +00:00
Core - Added stores for the different register-able types
Profiles - Refactored large parts of the profile structure to use these stores
This commit is contained in:
1 parent
80d7d37f40
commit
ea9c6526d8
75 files changed
+1526
-934
No files matched your search
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Core.LayerEffects;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
internal class LayerEffectStore
|
||||
{
|
||||
private static readonly List<LayerEffectRegistration> Registrations = new List<LayerEffectRegistration>();
|
||||
|
||||
public static LayerEffectRegistration Add(LayerEffectDescriptor descriptor)
|
||||
{
|
||||
LayerEffectRegistration registration;
|
||||
lock (Registrations)
|
||||
{
|
||||
if (Registrations.Any(r => r.LayerEffectDescriptor == descriptor))
|
||||
throw new ArtemisCoreException($"Store already contains layer brush '{descriptor.DisplayName}'");
|
||||
|
||||
registration = new LayerEffectRegistration(descriptor, descriptor.LayerEffectProvider.PluginInfo.Instance) { IsInStore = true };
|
||||
Registrations.Add(registration);
|
||||
}
|
||||
|
||||
OnLayerEffectAdded(new LayerEffectStoreEvent(registration));
|
||||
return registration;
|
||||
}
|
||||
|
||||
public static void Remove(LayerEffectRegistration registration)
|
||||
{
|
||||
lock (Registrations)
|
||||
{
|
||||
if (!Registrations.Contains(registration))
|
||||
throw new ArtemisCoreException($"Store does not contain layer brush '{registration.LayerEffectDescriptor.DisplayName}'");
|
||||
|
||||
Registrations.Remove(registration);
|
||||
registration.IsInStore = false;
|
||||
}
|
||||
|
||||
OnLayerEffectRemoved(new LayerEffectStoreEvent(registration));
|
||||
}
|
||||
|
||||
public static List<LayerEffectRegistration> GetAll()
|
||||
{
|
||||
lock (Registrations)
|
||||
{
|
||||
return new List<LayerEffectRegistration>(Registrations);
|
||||
}
|
||||
}
|
||||
|
||||
public static LayerEffectRegistration Get(Guid pluginGuid, string typeName)
|
||||
{
|
||||
lock (Registrations)
|
||||
{
|
||||
return Registrations.FirstOrDefault(d => d.Plugin.PluginInfo.Guid == pluginGuid && d.LayerEffectDescriptor.LayerEffectType.Name == typeName);
|
||||
}
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
public static event EventHandler<LayerEffectStoreEvent> LayerEffectAdded;
|
||||
public static event EventHandler<LayerEffectStoreEvent> LayerEffectRemoved;
|
||||
|
||||
private static void OnLayerEffectAdded(LayerEffectStoreEvent e)
|
||||
{
|
||||
LayerEffectAdded?.Invoke(null, e);
|
||||
}
|
||||
|
||||
private static void OnLayerEffectRemoved(LayerEffectStoreEvent e)
|
||||
{
|
||||
LayerEffectRemoved?.Invoke(null, e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user