1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Profiles - Fixed LEDs of devices that are missing being removed from layers (#733)

This commit is contained in:
RobertBeekman 2022-10-01 11:40:09 +02:00 committed by GitHub
parent 3f1eaeda29
commit b83f1f0102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 23 deletions

View File

@ -11,6 +11,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>ArtemisRGB.Core</PackageId> <PackageId>ArtemisRGB.Core</PackageId>
<PluginApiVersion>1</PluginApiVersion> <PluginApiVersion>1</PluginApiVersion>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -19,8 +20,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Artemis.Storage\Artemis.Storage.csproj"/> <ProjectReference Include="..\Artemis.Storage\Artemis.Storage.csproj" />
<ProjectReference Condition="'$(BuildingNuget)' == 'True'" Update="..\Artemis.Storage\Artemis.Storage.csproj" PrivateAssets="All"/> <ProjectReference Condition="'$(BuildingNuget)' == 'True'" Update="..\Artemis.Storage\Artemis.Storage.csproj" PrivateAssets="All" />
<!-- <!--
Include Artemis.Storage directly in the NuGet package instead of expecting it as an external dependency Include Artemis.Storage directly in the NuGet package instead of expecting it as an external dependency

View File

@ -16,12 +16,13 @@ namespace Artemis.Core;
/// </summary> /// </summary>
public sealed class Layer : RenderProfileElement public sealed class Layer : RenderProfileElement
{ {
private readonly List<Layer> _renderCopies; private readonly List<Layer> _renderCopies = new();
private LayerGeneralProperties _general; private LayerGeneralProperties _general = new();
private LayerTransformProperties _transform = new();
private BaseLayerBrush? _layerBrush; private BaseLayerBrush? _layerBrush;
private LayerShape? _layerShape; private LayerShape? _layerShape;
private List<ArtemisLed> _leds; private List<ArtemisLed> _leds = new();
private LayerTransformProperties _transform; private List<LedEntity> _missingLeds = new();
/// <summary> /// <summary>
/// Creates a new instance of the <see cref="Layer" /> class and adds itself to the child collection of the provided /// Creates a new instance of the <see cref="Layer" /> class and adds itself to the child collection of the provided
@ -37,16 +38,9 @@ public sealed class Layer : RenderProfileElement
Profile = Parent.Profile; Profile = Parent.Profile;
Name = name; Name = name;
Suspended = false; Suspended = false;
// TODO: move to top
_renderCopies = new List<Layer>();
_general = new LayerGeneralProperties();
_transform = new LayerTransformProperties();
_leds = new List<ArtemisLed>();
Leds = new ReadOnlyCollection<ArtemisLed>(_leds); Leds = new ReadOnlyCollection<ArtemisLed>(_leds);
Adapter = new LayerAdapter(this); Adapter = new LayerAdapter(this);
Initialize(); Initialize();
} }
@ -63,16 +57,9 @@ public sealed class Layer : RenderProfileElement
Profile = profile; Profile = profile;
Parent = parent; Parent = parent;
// TODO: move to top
_renderCopies = new List<Layer>();
_general = new LayerGeneralProperties();
_transform = new LayerTransformProperties();
_leds = new List<ArtemisLed>();
Leds = new ReadOnlyCollection<ArtemisLed>(_leds); Leds = new ReadOnlyCollection<ArtemisLed>(_leds);
Adapter = new LayerAdapter(this); Adapter = new LayerAdapter(this);
Load(); Load();
Initialize(); Initialize();
} }
@ -327,6 +314,7 @@ public sealed class Layer : RenderProfileElement
// LEDs // LEDs
LayerEntity.Leds.Clear(); LayerEntity.Leds.Clear();
SaveMissingLeds();
foreach (ArtemisLed artemisLed in Leds) foreach (ArtemisLed artemisLed in Leds)
{ {
LedEntity ledEntity = new() LedEntity ledEntity = new()
@ -786,6 +774,8 @@ public sealed class Layer : RenderProfileElement
a.RgbLed.Id.ToString() == ledEntity.LedName); a.RgbLed.Id.ToString() == ledEntity.LedName);
if (match != null) if (match != null)
leds.Add(match); leds.Add(match);
else
_missingLeds.Add(ledEntity);
} }
_leds = leds; _leds = leds;
@ -793,6 +783,11 @@ public sealed class Layer : RenderProfileElement
CalculateRenderProperties(); CalculateRenderProperties();
} }
private void SaveMissingLeds()
{
LayerEntity.Leds.AddRange(_missingLeds.Except(LayerEntity.Leds, LedEntity.LedEntityComparer));
}
#endregion #endregion
#region Brush management #region Brush management

View File

@ -1,7 +1,37 @@
namespace Artemis.Storage.Entities.Profile; using System;
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Profile;
public class LedEntity public class LedEntity
{ {
#region LedEntityEqualityComparer
private sealed class LedEntityEqualityComparer : IEqualityComparer<LedEntity>
{
public bool Equals(LedEntity x, LedEntity y)
{
if (ReferenceEquals(x, y))
return true;
if (ReferenceEquals(x, null))
return false;
if (ReferenceEquals(y, null))
return false;
if (x.GetType() != y.GetType())
return false;
return x.LedName == y.LedName && x.DeviceIdentifier == y.DeviceIdentifier && x.PhysicalLayout == y.PhysicalLayout;
}
public int GetHashCode(LedEntity obj)
{
return HashCode.Combine(obj.LedName, obj.DeviceIdentifier, obj.PhysicalLayout);
}
}
public static IEqualityComparer<LedEntity> LedEntityComparer { get; } = new LedEntityEqualityComparer();
#endregion
public string LedName { get; set; } public string LedName { get; set; }
public string DeviceIdentifier { get; set; } public string DeviceIdentifier { get; set; }