WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ColorConfigList.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using DirectOutput.Cab.Toys;
5 
6 namespace DirectOutput.LedControl.Loader
7 {
11  public class ColorConfigList : List<ColorConfig>
12  {
13 
19  public ColorConfig this[string Name]
20  {
21  get
22  {
23  foreach (ColorConfig CC in this)
24  {
25  if (CC.Name == Name)
26  {
27  return CC;
28  }
29 
30  }
31  return null;
32  }
33  }
34 
40  {
41  ColorList CL = new ColorList();
42  foreach (ColorConfig CC in this)
43  {
44  CL.Add(CC.GetCabinetColor());
45  }
46  return CL;
47  }
48 
54  public void ParseLedControlData(IEnumerable<string> LedControlData, bool ThrowExceptions = true)
55  {
56  foreach (string Data in LedControlData)
57  {
58  if (!Data.IsNullOrWhiteSpace())
59  {
60  ParseLedControlData(Data, ThrowExceptions);
61  }
62  }
63  }
64 
65 
76  public void ParseLedControlData(string LedControlData, bool ThrowExceptions = true)
77  {
78  ColorConfig CC = null;
79 
80  try
81  {
82  CC = new ColorConfig(LedControlData, ThrowExceptions);
83 
84  }
85  catch (Exception E)
86  {
87  Log.Exception("Could not parse color config data {0}.".Build(LedControlData),E);
88  if (ThrowExceptions)
89  {
90  throw new Exception("Could not parse color config data {0}.".Build(LedControlData),E);
91  }
92  }
93  if (CC != null)
94  {
95  if (Contains(CC.Name))
96  {
97  Log.Exception("Color {0} has already been defined.".Build(CC.Name));
98  if (ThrowExceptions)
99  {
100  throw new Exception("Color {0} has already been defined.".Build(CC.Name));
101  }
102  }
103  else
104  {
105 
106  Add(CC);
107  }
108  }
109  }
110 
118  public bool Contains(string ColorName)
119  {
120  foreach (ColorConfig CC in this)
121  {
122  if (CC.Name.Equals(ColorName, StringComparison.InvariantCultureIgnoreCase))
123  {
124  return true;
125  }
126  }
127  return false;
128  }
129 
130 
131 
132 
133  }
134 }
void ParseLedControlData(string LedControlData, bool ThrowExceptions=true)
Parses the led control data.
string Name
Gets or sets the name of the color.
Definition: ColorConfig.cs:29
The namespace DirectOutput.Cab.Toys contains all toy related classes.
List of color configurations from a ledcontrol.ini file.
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
void ParseLedControlData(IEnumerable< string > LedControlData, bool ThrowExceptions=true)
Parses the led control data.
RGBAColorNamed GetCabinetColor()
Gets a cabinet RGBAColor object representing the values in the ColorConfig object-.
Definition: ColorConfig.cs:18
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
Definition: Cab.cs:16
Color configuration from a LedControl file.
Definition: ColorConfig.cs:12
bool Contains(string ColorName)
Determines whether the list contains the specified color name.
ColorList GetCabinetColorList()
Gets a cabinet color list for the config colors contained in this list.
List for Color objects
Definition: ColorList.cs:12
The namespace DirectOutput.General contains classes for general use.
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.
Definition: Log.cs:144