private bool BuildLightConfig(List <CLight> lights, List <CDevice> devices, List <CColor> colors) { for (int i = 0; i < m_lightlines.Count; i++) { CLight light = new CLight(); if (!SetLightName(light, m_lightlines[i].lines, i)) { return(false); } SetLightScanRange(light, m_lightlines[i].lines); //check the colors on a light for (int j = 0; j < m_lightlines[i].lines.Count; j++) { string line = m_lightlines[i].lines[j].line; string key; Util.GetWord(ref line, out key); if (key != "color") { continue; } //we already checked these in the syntax check string colorname, devicename, devicechannel; Util.GetWord(ref line, out colorname); Util.GetWord(ref line, out devicename); Util.GetWord(ref line, out devicechannel); bool colorfound = false; for (int k = 0; k < colors.Count; k++) { if (colors[k].Name == colorname) { colorfound = true; light.AddColor(colors[k]); break; } } if (!colorfound) //this color doesn't exist { Util.LogError($"{m_filename} line {m_lightlines[i].lines[j].linenr}: no color with name {colorname}"); return(false); } int ichannel; ichannel = int.Parse(devicechannel); //loop through the devices, check if one with this name exists and if the channel on it exists bool devicefound = false; for (int k = 0; k < devices.Count; k++) { if (devices[k].Name == devicename) { if (ichannel > devices[k].NrChannels) { Util.LogError($"{m_filename} line {m_lightlines[i].lines[j].linenr}: channel {ichannel} wanted but device {devices[k].Name} has {devices[k].NrChannels} channels"); return(false); } devicefound = true; CChannel channel = new CChannel(); channel.Color = (light.NrColors - 1); channel.Light = i; devices[k].SetChannel(channel, ichannel - 1); break; } } if (!devicefound) { Util.LogError($"{m_filename} line {m_lightlines[i].lines[j].linenr}: no device with name {devicename}"); return(false); } } lights.Add(light); } return(true); }