public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache) { var ledCount = cache.GetDeviceConfig(port).LedCount; if (ledCount == colors.Count) { return; } if (Config.LerpType == LerpType.Smooth) { var newColors = new List <LedColor>(); var gradient = new LedColorGradient(colors, ledCount - 1); for (var i = 0; i < ledCount; i++) { newColors.Add(gradient.GetColor(i)); } colors = newColors; } else if (Config.LerpType == LerpType.Nearest) { var newColors = new List <LedColor>(); for (var i = 0; i < ledCount; i++) { var idx = (int)Math.Round((i / (ledCount - 1d)) * (colors.Count - 1d)); newColors.Add(colors[idx]); } colors = newColors; } }
public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache) { if (Config.Reverse != null) { Apply(ref colors); } else { var offset = 0; var newColors = new List <LedColor>(); var zones = cache.GetDeviceConfig(port).Zones; for (int i = 0; i < zones.Length; i++) { var zoneColors = colors.Skip(offset).Take(zones[i]); if (i < Config.ZoneReverse?.Length && Config.ZoneReverse[i]) { zoneColors = zoneColors.Reverse(); } offset += zones[i]; newColors.AddRange(zoneColors); } if (newColors.Count < colors.Count) { newColors.AddRange(colors.Skip(offset)); } colors = newColors; } }
public override void Run(string part) { var input = FileReader.ReadFile(2017, 12); var portIdentifier = new PortIdentifier(input); if (part == "A") { Console.WriteLine(portIdentifier.GetConnectionsToRoot().Count); } else { Console.WriteLine(portIdentifier.GetGroups()); } }
public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache) { if (Config.Rotation != null) { Apply(ref colors); } else { var offset = 0; var newColors = new List <LedColor>(); var zones = cache.GetDeviceConfig(port).Zones; for (int i = 0; i < zones.Length; i++) { var zoneColors = colors.Skip(offset).Take(zones[i]); if (i < Config.ZoneRotation?.Length) { var rotate = Config.ZoneRotation[i]; if (rotate > 0) { zoneColors = zoneColors.RotateLeft(rotate); } else if (rotate < 0) { zoneColors = zoneColors.RotateRight(rotate); } } offset += zones[i]; newColors.AddRange(zoneColors); } if (newColors.Count < colors.Count) { newColors.AddRange(colors.Skip(offset)); } colors = newColors; } }
public override void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache) { var ledCount = cache.GetDeviceConfig(port).LedCount; if (ledCount <= colors.Count) { return; } if (Config.WrapRemainder) { var wrapCount = (int)Math.Floor(colors.Count / (double)ledCount); var startOffset = (wrapCount - 1) * ledCount; var remainder = colors.Count - wrapCount * ledCount; colors = colors.Skip(colors.Count - remainder) .Concat(colors.Skip(startOffset + remainder).Take(ledCount - remainder)) .ToList(); } else { colors.RemoveRange(ledCount, colors.Count - ledCount); } }
public PortConfig GetPortConfig(PortIdentifier port) => _portConfigCache.TryGetValue(port, out var config) ? config : null;
public void StorePortConfig(PortIdentifier port, PortConfig config) => _portConfigCache[port] = config;
public PortData GetPortData(PortIdentifier port) => _portDataCache.TryGetValue(port, out var data) ? data : null;
public void StorePortData(PortIdentifier port, PortData data) => _portDataCache[port] = data;
public IControllerProxy GetController(PortIdentifier port) => Controllers?.FirstOrDefault(c => c.IsValidPort(port)) ?? null;
public DeviceConfig GetDeviceConfig(PortIdentifier port) => _provider.GetDeviceConfig(port);
public List <LedColor> GetPortColors(PortIdentifier port) => _portColorCache.TryGetValue(port, out var colors) ? colors : null;
public void StorePortData(PortIdentifier port, PortData data) => _collector.StorePortData(port, data);
public byte?GetPortSpeed(PortIdentifier port) => _portSpeedCache.TryGetValue(port, out var speed) ? speed : (byte?)null;
public void StorePortSpeed(PortIdentifier port, byte speed) => _portSpeedCache[port] = speed;
public void StoreDeviceConfig(PortIdentifier port, DeviceConfig data) => _collector.StoreDeviceConfig(port, data);
public void StorePortColors(PortIdentifier port, List <LedColor> colors) => _collector.StorePortColors(port, colors);
public void StorePortSpeed(PortIdentifier port, byte speed) => _collector.StorePortSpeed(port, speed);
public PortData GetPortData(PortIdentifier port) => _provider.GetPortData(port);
public override bool IsValidPort(PortIdentifier port) => port.ControllerProductId == Device.ProductId && port.ControllerVendorId == Device.VendorId && port.Id >= 1 && port.Id <= Definition.PortCount;
public PortConfig GetPortConfig(PortIdentifier port) => _provider.GetPortConfig(port);
public byte?GetPortSpeed(PortIdentifier port) => _provider.GetPortSpeed(port);
public void StorePortConfig(PortIdentifier port, PortConfig config) => _collector.StorePortConfig(port, config);
public abstract void Apply(ref List <LedColor> colors, PortIdentifier port, ICacheProvider cache);
public void StorePortColors(PortIdentifier port, List <LedColor> colors) => _portColorCache[port] = colors;
public List <LedColor> GetPortColors(PortIdentifier port) => _provider.GetPortColors(port);
public override bool IsValidPort(PortIdentifier port) => port.ControllerProductId == Device.ProductId && port.ControllerVendorId == Device.VendorId && port.Id == 0;
public DeviceConfig GetDeviceConfig(PortIdentifier port) => _deviceConfigCache.TryGetValue(port, out var data) ? data : null;
public abstract bool IsValidPort(PortIdentifier port);
public void StoreDeviceConfig(PortIdentifier port, DeviceConfig data) => _deviceConfigCache[port] = data;