using System; using System.Collections.Generic; using System.Linq; using Artemis.Storage.Entities.Profile.AdaptionHints; using RGB.NET.Core; namespace Artemis.Core { /// /// Represents a hint that adapts layers to a certain region of keyboards /// public class KeyboardSectionAdaptionHint : IAdaptionHint { private static readonly Dictionary> RegionLedIds = new() { {KeyboardSection.MacroKeys, Enum.GetValues().Where(l => l >= LedId.Keyboard_Programmable1 && l <= LedId.Keyboard_Programmable32).ToList()}, {KeyboardSection.LedStrips, Enum.GetValues().Where(l => l >= LedId.LedStripe1 && l <= LedId.LedStripe128).ToList()}, {KeyboardSection.Extra, Enum.GetValues().Where(l => l >= LedId.Keyboard_Custom1 && l <= LedId.Keyboard_Custom64).ToList()} }; public KeyboardSectionAdaptionHint() { } internal KeyboardSectionAdaptionHint(KeyboardSectionAdaptionHintEntity entity) { Section = (KeyboardSection) entity.Section; } /// /// Gets or sets the section this hint will apply LEDs to /// public KeyboardSection Section { get; set; } #region Implementation of IAdaptionHint /// public void Apply(Layer layer, List devices) { // Only keyboards should have the LEDs we care about foreach (ArtemisDevice keyboard in devices.Where(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard)) { List ledIds = RegionLedIds[Section]; layer.AddLeds(keyboard.Leds.Where(l => ledIds.Contains(l.RgbLed.Id))); } } /// public IAdaptionHintEntity GetEntry() { return new KeyboardSectionAdaptionHintEntity {Section = (int) Section}; } /// public override string ToString() { return $"Keyboard section adaption - {nameof(Section)}: {Section}"; } #endregion } /// /// Represents a section of LEDs on a keyboard /// public enum KeyboardSection { /// /// A region containing the macro keys of a keyboard /// MacroKeys, /// /// A region containing the LED strips of a keyboard /// LedStrips, /// /// A region containing extra non-standard LEDs of a keyboard /// Extra } }