mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Devices - Reworking layout loading
This commit is contained in:
1 parent
9393bf2b68
commit
e8590abd61
57 files changed
+824
-349
No files matched your search
@@ -0,0 +1,28 @@
|
||||
using RGB.NET.Layout;
|
||||
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class CustomPathLayoutProvider : ILayoutProvider
|
||||
{
|
||||
public static string LayoutType = "CustomPath";
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
if (device.LayoutSelection.Parameter == null)
|
||||
return null;
|
||||
return new ArtemisLayout(device.LayoutSelection.Parameter);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ApplyLayout(ArtemisDevice device, ArtemisLayout layout)
|
||||
{
|
||||
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMatch(ArtemisDevice device)
|
||||
{
|
||||
return device.LayoutSelection.Type == LayoutType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class DefaultLayoutProvider : ILayoutProvider
|
||||
{
|
||||
public static string LayoutType = "Default";
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
// Look for a layout provided by the plugin
|
||||
ArtemisLayout layout = device.DeviceProvider.LoadLayout(device);
|
||||
|
||||
// Finally fall back to a default layout
|
||||
return layout.IsValid ? layout : ArtemisLayout.GetDefaultLayout(device);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ApplyLayout(ArtemisDevice device, ArtemisLayout layout)
|
||||
{
|
||||
if (layout.IsDefaultLayout)
|
||||
device.ApplyLayout(layout, false, false);
|
||||
else
|
||||
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMatch(ArtemisDevice device)
|
||||
{
|
||||
return device.LayoutSelection.Type == LayoutType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a class that can provide Artemis layouts for devices.
|
||||
/// </summary>
|
||||
public interface ILayoutProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// If available, loads an Artemis layout for the provided device.
|
||||
/// </summary>
|
||||
/// <param name="device">The device to load the layout for.</param>
|
||||
/// <returns>The resulting layout if one was available; otherwise <see langword="null"/>.</returns>
|
||||
ArtemisLayout? GetDeviceLayout(ArtemisDevice device);
|
||||
|
||||
void ApplyLayout(ArtemisDevice device, ArtemisLayout layout);
|
||||
bool IsMatch(ArtemisDevice device);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class NoneLayoutProvider : ILayoutProvider
|
||||
{
|
||||
public static string LayoutType = "None";
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ApplyLayout(ArtemisDevice device, ArtemisLayout layout)
|
||||
{
|
||||
device.ApplyLayout(null, false, false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMatch(ArtemisDevice device)
|
||||
{
|
||||
return device.LayoutSelection.Type == LayoutType;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user