1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00
Robert 248d4c8e18 Storage - Use nullable reference types
Core - Fix build warnings
2024-02-23 17:35:06 +01:00

58 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.LayerBrushes;
namespace Artemis.Core.Services;
internal class LayerBrushService : ILayerBrushService
{
private readonly ISettingsService _settingsService;
public LayerBrushService(ISettingsService settingsService)
{
_settingsService = settingsService;
}
public LayerBrushRegistration RegisterLayerBrush(LayerBrushDescriptor descriptor)
{
if (descriptor == null)
throw new ArgumentNullException(nameof(descriptor));
return LayerBrushStore.Add(descriptor);
}
public void RemoveLayerBrush(LayerBrushRegistration registration)
{
if (registration == null)
throw new ArgumentNullException(nameof(registration));
LayerBrushStore.Remove(registration);
}
public List<LayerBrushDescriptor> GetLayerBrushes()
{
return LayerBrushStore.GetAll().Select(r => r.LayerBrushDescriptor).ToList();
}
public LayerBrushDescriptor? GetDefaultLayerBrush()
{
PluginSetting<LayerBrushReference> defaultReference = _settingsService.GetSetting("ProfileEditor.DefaultLayerBrushDescriptor", new LayerBrushReference
{
LayerBrushProviderId = "Artemis.Plugins.LayerBrushes.Color.ColorBrushProvider-92a9d6ba",
BrushType = "SolidBrush"
});
defaultReference.Value ??= new LayerBrushReference();
defaultReference.Value.LayerBrushProviderId ??= "Artemis.Plugins.LayerBrushes.Color.ColorBrushProvider-92a9d6ba";
defaultReference.Value.BrushType ??= "SolidBrush";
return LayerBrushStore.Get(defaultReference.Value.LayerBrushProviderId, defaultReference.Value.BrushType)?.LayerBrushDescriptor;
}
/// <inheritdoc />
public void ApplyDefaultBrush(Layer layer)
{
LayerBrushDescriptor? brush = GetDefaultLayerBrush();
if (brush != null)
layer.ChangeLayerBrush(brush.CreateInstance(layer, null));
}
}