mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 03:19:56 +00:00
Adaption hints - Added single LED adaption hint
Adaption hints - Added more sections to keyboard section adaption hint
This commit is contained in:
1 parent
ca9ce948c5
commit
d96581f11c
21 files changed
+433
-62
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile.AdaptionHints;
|
||||
using RGB.NET.Core;
|
||||
@@ -15,7 +16,12 @@ public class KeyboardSectionAdaptionHint : CorePropertyChanged, IAdaptionHint
|
||||
{
|
||||
{KeyboardSection.MacroKeys, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_Programmable1 && l <= LedId.Keyboard_Programmable32).ToList()},
|
||||
{KeyboardSection.LedStrips, Enum.GetValues<LedId>().Where(l => l >= LedId.LedStripe1 && l <= LedId.LedStripe128).ToList()},
|
||||
{KeyboardSection.Extra, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_Custom1 && l <= LedId.Keyboard_Custom64).ToList()}
|
||||
{KeyboardSection.Extra, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_Custom1 && l <= LedId.Keyboard_Custom64).ToList()},
|
||||
{KeyboardSection.FunctionKeys, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_F1 && l <= LedId.Keyboard_F12).ToList()},
|
||||
{KeyboardSection.NumberKeys, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_1 && l <= LedId.Keyboard_0).ToList()},
|
||||
{KeyboardSection.NumPad, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_NumLock && l <= LedId.Keyboard_NumPeriodAndDelete).ToList()},
|
||||
{KeyboardSection.ArrowKeys, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_PageDown && l <= LedId.Keyboard_ArrowRight).ToList()},
|
||||
{KeyboardSection.MediaKeys, Enum.GetValues<LedId>().Where(l => l >= LedId.Keyboard_MediaMute && l <= LedId.Keyboard_MediaNextTrack).ToList()},
|
||||
};
|
||||
|
||||
private KeyboardSection _section;
|
||||
@@ -46,6 +52,12 @@ public class KeyboardSectionAdaptionHint : CorePropertyChanged, IAdaptionHint
|
||||
/// <inheritdoc />
|
||||
public void Apply(Layer layer, List<ArtemisDevice> devices)
|
||||
{
|
||||
if (Section == KeyboardSection.Movement)
|
||||
{
|
||||
ApplyMovement(layer, devices);
|
||||
return;
|
||||
}
|
||||
|
||||
// Only keyboards should have the LEDs we care about
|
||||
foreach (ArtemisDevice keyboard in devices.Where(d => d.DeviceType == RGBDeviceType.Keyboard))
|
||||
{
|
||||
@@ -54,6 +66,26 @@ public class KeyboardSectionAdaptionHint : CorePropertyChanged, IAdaptionHint
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyMovement(Layer layer, List<ArtemisDevice> devices)
|
||||
{
|
||||
// Only keyboards should have the LEDs we care about
|
||||
foreach (ArtemisDevice keyboard in devices.Where(d => d.DeviceType == RGBDeviceType.Keyboard))
|
||||
{
|
||||
ArtemisLed? qLed = keyboard.Leds.FirstOrDefault(l => l.RgbLed.Id == LedId.Keyboard_Q);
|
||||
ArtemisLed? aLed = keyboard.Leds.FirstOrDefault(l => l.RgbLed.Id == LedId.Keyboard_A);
|
||||
if (qLed == null || aLed == null)
|
||||
continue;
|
||||
|
||||
// AZERTY keyboards will have their A above their Q
|
||||
bool isAzerty = aLed.Rectangle.MidX < qLed.Rectangle.MidX;
|
||||
|
||||
if (isAzerty)
|
||||
layer.AddLeds(keyboard.Leds.Where(l => l.RgbLed.Id is LedId.Keyboard_Z or LedId.Keyboard_Q or LedId.Keyboard_S or LedId.Keyboard_D));
|
||||
else
|
||||
layer.AddLeds(keyboard.Leds.Where(l => l.RgbLed.Id is LedId.Keyboard_W or LedId.Keyboard_A or LedId.Keyboard_S or LedId.Keyboard_D));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IAdaptionHintEntity GetEntry()
|
||||
{
|
||||
@@ -77,15 +109,45 @@ public enum KeyboardSection
|
||||
/// <summary>
|
||||
/// A region containing the macro keys of a keyboard
|
||||
/// </summary>
|
||||
MacroKeys,
|
||||
[Description("Macro Keys")] MacroKeys,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing the LED strips of a keyboard
|
||||
/// </summary>
|
||||
LedStrips,
|
||||
[Description("LED Strips")] LedStrips,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing extra non-standard LEDs of a keyboard
|
||||
/// A region containing the extra non-standard LEDs of a keyboard
|
||||
/// </summary>
|
||||
Extra
|
||||
[Description("Extra LEDs")] Extra,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing the movement keys of a keyboard (WASD for QWERTY and ZQSD for AZERTY)
|
||||
/// </summary>
|
||||
[Description("Movement (WASD/ZQSD)")] Movement,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing the F-keys of a keyboard
|
||||
/// </summary>
|
||||
[Description("F-keys")] FunctionKeys,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing the numeric keys of a keyboard
|
||||
/// </summary>
|
||||
[Description("Numeric keys")] NumberKeys,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing the Numpad of a keyboard
|
||||
/// </summary>
|
||||
[Description("Numpad")] NumPad,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing the arrow keys of a keyboard
|
||||
/// </summary>
|
||||
[Description("Arrow keys")] ArrowKeys,
|
||||
|
||||
/// <summary>
|
||||
/// A region containing the media keys of a keyboard
|
||||
/// </summary>
|
||||
[Description("Media keys")] MediaKeys
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile.AdaptionHints;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a hint that adapts layers to a single LED of one or more devices
|
||||
/// </summary>
|
||||
public class SingleLedAdaptionHint : CorePropertyChanged, IAdaptionHint
|
||||
{
|
||||
private LedId _ledId;
|
||||
private int _skip;
|
||||
private bool _limitAmount;
|
||||
private int _amount;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="SingleLedAdaptionHint" /> class
|
||||
/// </summary>
|
||||
public SingleLedAdaptionHint()
|
||||
{
|
||||
}
|
||||
|
||||
internal SingleLedAdaptionHint(SingleLedAdaptionHintEntity entity)
|
||||
{
|
||||
LedId = (LedId) entity.LedId;
|
||||
Skip = entity.Skip;
|
||||
LimitAmount = entity.LimitAmount;
|
||||
Amount = entity.Amount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the LED ID to apply to.
|
||||
/// </summary>
|
||||
public LedId LedId
|
||||
{
|
||||
get => _ledId;
|
||||
set => SetAndNotify(ref _ledId, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the amount of devices to skip
|
||||
/// </summary>
|
||||
public int Skip
|
||||
{
|
||||
get => _skip;
|
||||
set => SetAndNotify(ref _skip, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether a limited amount of devices should be used
|
||||
/// </summary>
|
||||
public bool LimitAmount
|
||||
{
|
||||
get => _limitAmount;
|
||||
set => SetAndNotify(ref _limitAmount, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the amount of devices to limit to if <see cref="LimitAmount" /> is <see langword="true" />
|
||||
/// </summary>
|
||||
public int Amount
|
||||
{
|
||||
get => _amount;
|
||||
set => SetAndNotify(ref _amount, value);
|
||||
}
|
||||
|
||||
#region Implementation of IAdaptionHint
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Apply(Layer layer, List<ArtemisDevice> devices)
|
||||
{
|
||||
IEnumerable<ArtemisDevice> matches = devices
|
||||
.Where(d => d.Leds.Any(l => l.RgbLed.Id == LedId))
|
||||
.OrderBy(d => d.Rectangle.Top)
|
||||
.ThenBy(d => d.Rectangle.Left)
|
||||
.Skip(Skip);
|
||||
if (LimitAmount)
|
||||
matches = matches.Take(Amount);
|
||||
|
||||
foreach (ArtemisDevice artemisDevice in matches)
|
||||
{
|
||||
ArtemisLed led = artemisDevice.Leds.First(l => l.RgbLed.Id == LedId);
|
||||
layer.AddLed(led);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IAdaptionHintEntity GetEntry()
|
||||
{
|
||||
return new SingleLedAdaptionHintEntity {Amount = Amount, LimitAmount = LimitAmount, Skip = Skip, LedId = (int) LedId};
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Single LED adaption - {nameof(LedId)}: {LedId}, {nameof(Skip)}: {Skip}, {nameof(LimitAmount)}: {LimitAmount}, {nameof(Amount)}: {Amount}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -111,6 +111,15 @@ public class LayerAdapter : IStorageModel
|
||||
newHints.Add(hint);
|
||||
}
|
||||
}
|
||||
|
||||
// A single LED assignment is turned into a hint for one matching LED ID on the same device type
|
||||
if (Layer.Leds.Count == 1)
|
||||
{
|
||||
ArtemisLed led = Layer.Leds.Single();
|
||||
SingleLedAdaptionHint hint = new() {LedId = led.RgbLed.Id, Amount = 1, LimitAmount = true};
|
||||
Add(hint);
|
||||
newHints.Add(hint);
|
||||
}
|
||||
}
|
||||
|
||||
return newHints;
|
||||
@@ -184,6 +193,9 @@ public class LayerAdapter : IStorageModel
|
||||
case KeyboardSectionAdaptionHintEntity entity:
|
||||
Add(new KeyboardSectionAdaptionHint(entity));
|
||||
break;
|
||||
case SingleLedAdaptionHintEntity entity:
|
||||
Add(new SingleLedAdaptionHint(entity));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user