Devices - Add device layout loading

This commit is contained in:
Robert committed 2021-02-10 22:45:28 +01:00
1 parent 7792b662e0
commit e1121afdf9
6 files changed
+107 -80

No files matched your search

@@ -5,6 +5,7 @@ using System.Linq;
using Artemis.Core.DeviceProviders;
using Artemis.Storage.Entities.Surface;
using RGB.NET.Core;
using RGB.NET.Layout;
using SkiaSharp;
namespace Artemis.Core
@@ -31,14 +32,13 @@ namespace Artemis.Core
GreenScale = 1;
BlueScale = 1;
IsEnabled = true;
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
LayoutPath = layoutPath;
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
LoadBestLayout();
ApplyToEntity();
CalculateRenderProperties();
}
@@ -49,16 +49,14 @@ namespace Artemis.Core
RgbDevice = rgbDevice;
DeviceProvider = deviceProvider;
Surface = surface;
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
LayoutPath = layoutPath;
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
LoadBestLayout();
}
/// <summary>
@@ -227,11 +225,6 @@ namespace Artemis.Core
}
}
/// <summary>
/// Gets the path to where the layout of the device was (attempted to be) loaded from
/// </summary>
public string? LayoutPath { get; internal set; }
/// <summary>
/// Gets the layout of the device expanded with Artemis-specific data
/// </summary>
@@ -266,6 +259,15 @@ namespace Artemis.Core
return artemisLed;
}
public void LoadBestLayout()
{
ArtemisLayout artemisLayout = DeviceProvider.LoadLayout(RgbDevice);
if (artemisLayout.IsValid)
artemisLayout.DeviceLayout!.ApplyTo(RgbDevice);
Layout = artemisLayout;
}
internal void ApplyToEntity()
{
// Other properties are computed
@@ -1,10 +1,57 @@
using System;
using RGB.NET.Layout;
namespace Artemis.Core
{
/// <summary>
/// Represents a device layout decorated with extra Artemis-specific data
/// </summary>
public class ArtemisLayout
{
public ArtemisDevice Device { get; set; }
public Uri Image { get; set; }
/// <summary>
/// Creates a new instance of the <see cref="ArtemisLayout" /> class
/// </summary>
/// <param name="filePath">The path of the layout XML file</param>
public ArtemisLayout(string filePath)
{
FilePath = filePath;
DeviceLayout = DeviceLayout.Load(FilePath);
IsValid = DeviceLayout != null;
}
/// <summary>
/// Gets the file path the layout was (attempted to be) loaded from
/// </summary>
public string FilePath { get; }
/// <summary>
/// Gets the RGB.NET device layout
/// </summary>
public DeviceLayout? DeviceLayout { get; }
/// <summary>
/// Gets a boolean indicating whether a valid layout was loaded
/// </summary>
public bool IsValid { get; }
/// <summary>
/// Gets the device this image is applied to
/// </summary>
public ArtemisDevice? Device { get; internal set; }
/// <summary>
/// Gets or sets the physical layout of the device. Only applicable to keyboards
/// </summary>
public string? PhysicalLayout { get; set; }
/// <summary>
/// Gets or sets the logical layout of the device. Only applicable to keyboards
/// </summary>
public string? LogicalLayout { get; set; }
/// <summary>
/// Gets or sets the image of the device
/// </summary>
public Uri? Image { get; set; }
}
}