using System.Collections.Generic; using RGB.NET.Core; namespace RGB.NET.Devices.CoolerMaster; /// /// /// Represents a CoolerMaster keyboard. /// public sealed class CoolerMasterKeyboardRGBDevice : CoolerMasterRGBDevice, IKeyboard { #region Properties & Fields IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo; #endregion #region Constructors /// /// /// Initializes a new instance of the class. /// /// The specific information provided by CoolerMaster for the keyboard /// The update trigger used to update this device. internal CoolerMasterKeyboardRGBDevice(CoolerMasterKeyboardRGBDeviceInfo info, IDeviceUpdateTrigger updateTrigger) : base(info, updateTrigger) { InitializeLayout(); } #endregion #region Methods private void InitializeLayout() { if (!CoolerMasterKeyboardLedMappings.Mapping.TryGetValue(DeviceInfo.DeviceIndex, out Dictionary>? deviceMappings)) throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex}"); if (!deviceMappings.TryGetValue(DeviceInfo.PhysicalLayout, out Dictionary? mapping)) throw new RGBDeviceException($"Failed to find a CoolerMasterKeyboardLedMapping for device index {DeviceInfo.DeviceIndex} with physical layout {DeviceInfo.PhysicalLayout}"); foreach ((LedId ledId, (int row, int column)) in mapping) AddLed(ledId, new Point(column * 19, row * 19), new Size(19, 19)); } /// protected override object GetLedCustomData(LedId ledId) => CoolerMasterKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId]; #endregion }