Devices - Reimplemented LED images

This commit is contained in:
Robert committed 2021-02-11 22:49:51 +01:00
1 parent 956ebd3313
commit c70e7d0c00
6 files changed
+114 -69

No files matched your search

@@ -334,11 +334,11 @@ namespace Artemis.Core
if (layout.IsValid)
layout.RgbLayout!.ApplyTo(RgbDevice);
Layout = layout;
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
Layout = layout;
Layout.ApplyDevice(this);
Leds = Layout.Leds.Select(l => l.Led);
}
internal void ApplyToEntity()
+8 -12
View File
@@ -1,5 +1,4 @@
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Core;
using SkiaSharp;
namespace Artemis.Core
@@ -17,9 +16,6 @@ namespace Artemis.Core
RgbLed = led;
Device = device;
CalculateRectangles();
Layout = Device.Layout?.Leds.FirstOrDefault(l => l.RgbLayout.Id == led.Id.ToString());
}
/// <summary>
@@ -50,13 +46,7 @@ namespace Artemis.Core
private set => SetAndNotify(ref _absoluteRectangle, value);
}
public ArtemisLedLayout? Layout { get; }
internal void CalculateRectangles()
{
Rectangle = RgbLed.Boundary.ToSKRect();
AbsoluteRectangle = RgbLed.AbsoluteBoundary.ToSKRect();
}
public ArtemisLedLayout? Layout { get; internal set; }
/// <inheritdoc />
public override string ToString()
@@ -72,5 +62,11 @@ namespace Artemis.Core
{
return RgbLed.Color.DivideRGB(Device.RedScale, Device.GreenScale, Device.BlueScale);
}
internal void CalculateRectangles()
{
Rectangle = RgbLed.Boundary.ToSKRect();
AbsoluteRectangle = RgbLed.AbsoluteBoundary.ToSKRect();
}
}
}
@@ -34,11 +34,11 @@ namespace Artemis.Core
if (IsValid)
Leds.AddRange(RgbLayout.Leds.Select(l => new ArtemisLedLayout(this, l)));
LayoutCustomDeviceData = (LayoutCustomDeviceData?) RgbLayout.CustomData ?? new LayoutCustomDeviceData();
ApplyCustomDeviceData();
}
/// <summary>
/// Gets the file path the layout was (attempted to be) loaded from
/// </summary>
@@ -60,10 +60,10 @@ namespace Artemis.Core
public bool IsValid { get; }
/// <summary>
/// Gets or sets the image of the device
/// Gets the image of the device
/// </summary>
public Uri? Image { get; set; }
public Uri? Image { get; private set; }
public List<ArtemisLedLayout> Leds { get; }
internal LayoutCustomDeviceData LayoutCustomDeviceData { get; set; }
@@ -71,7 +71,7 @@ namespace Artemis.Core
internal void ApplyDevice(ArtemisDevice artemisDevice)
{
Device = artemisDevice;
foreach (ArtemisLedLayout artemisLedLayout in Leds)
foreach (ArtemisLedLayout artemisLedLayout in Leds)
artemisLedLayout.ApplyDevice(Device);
}
@@ -7,17 +7,20 @@ namespace Artemis.Core
{
public class ArtemisLedLayout
{
internal ArtemisLedLayout(ArtemisLayout layout, ILedLayout led)
internal ArtemisLedLayout(ArtemisLayout deviceLayout, ILedLayout led)
{
Layout = layout;
DeviceLayout = deviceLayout;
RgbLayout = led;
LayoutCustomLedData = (LayoutCustomLedData?) led.CustomData ?? new LayoutCustomLedData();
}
public ArtemisLayout Layout { get; }
/// <summary>
/// Gets the device layout of this LED layout
/// </summary>
public ArtemisLayout DeviceLayout { get; }
/// <summary>
/// Gets the RGB.NET LED Layout of this Artemis LED layout
/// Gets the RGB.NET LED Layout of this LED layout
/// </summary>
public ILedLayout RgbLayout { get; }
@@ -38,18 +41,29 @@ namespace Artemis.Core
internal LayoutCustomLedData LayoutCustomLedData { get; set; }
public void ApplyDevice(ArtemisDevice device)
internal void ApplyDevice(ArtemisDevice device)
{
Led = device.Leds.FirstOrDefault(d => d.RgbLed.Id.ToString() == RgbLayout.Id);
ApplyCustomLedData();
if (Led != null)
Led.Layout = this;
ApplyCustomLedData(device);
}
private void ApplyCustomLedData()
private void ApplyCustomLedData(ArtemisDevice artemisDevice)
{
if (Led == null)
if (LayoutCustomLedData.LogicalLayouts == null || !LayoutCustomLedData.LogicalLayouts.Any())
return;
Uri layoutDirectory = new(Path.GetDirectoryName(Layout.FilePath)! + "\\", UriKind.Absolute);
Uri layoutDirectory = new(Path.GetDirectoryName(DeviceLayout.FilePath)! + "\\", UriKind.Absolute);
// Prefer a matching layout or else a default layout (that has no name)
LayoutCustomLedDataLogicalLayout logicalLayout = LayoutCustomLedData.LogicalLayouts
.OrderBy(l => l.Name == artemisDevice.LogicalLayout)
.ThenBy(l => l.Name == null)
.First();
LogicalName = logicalLayout.Name;
Image = new Uri(layoutDirectory, logicalLayout.Image);
}
}
}