1 using System.Collections.Generic;
3 using DirectOutput.Cab;
4 using DirectOutput.Cab.Out;
5 using DirectOutput.Cab.Toys;
6 using DirectOutput.Cab.Toys.Layer;
7 using DirectOutput.Cab.Toys.LWEquivalent;
9 using DirectOutput.FX.AnalogToyFX;
10 using DirectOutput.FX.RGBAFX;
11 using DirectOutput.FX.TimmedFX;
12 using DirectOutput.LedControl.Loader;
13 using DirectOutput.Cab.Color;
15 namespace DirectOutput.LedControl.Setup
25 public int EffectMinDurationMs = 60;
29 public int EffectRGBMinDurationMs = 120;
42 Dictionary<int, Dictionary<int, IToy>> ToyAssignments = SetupCabinet(TableConfigDict, Cabinet);
44 SetupTable(Table, TableConfigDict, ToyAssignments);
49 private void SetupTable(Table.Table Table, Dictionary<int, TableConfig> TableConfigDict, Dictionary<
int, Dictionary<int, IToy>> ToyAssignments)
51 foreach (KeyValuePair<int, TableConfig> KV
in TableConfigDict)
53 int LedWizNr = KV.Key;
54 if (ToyAssignments.ContainsKey(LedWizNr))
62 if (ToyAssignments[LedWizNr].ContainsKey(TCC.
Number))
64 IToy Toy = ToyAssignments[LedWizNr][TCC.
Number];
66 int SettingNumber = 0;
72 int Layer = (TCS.
Layer.HasValue ? TCS.
Layer.Value : SettingNumber);
93 Log.
Warning(
"Skipped setting {0} in column {1} for LedWizEqivalent number {2} since {3} is not a valid color specification.".Build(
new object[] { SettingNumber, TCC.Number, LedWizNr, TCS.
ColorName }));
98 Log.Warning(
"Skipped setting {0} in column {1} for LedWizEqivalent number {2} since {3} is not a valid color specification.".Build(
new object[] { SettingNumber, TCC.Number, LedWizNr, TCS.
ColorName }));
103 Log.Warning(
"Skipped setting {0} in column {1} for LedWizEqivalent number {2} since it does not contain a color specification.".Build(SettingNumber, TCC.Number, LedWizNr));
106 if (ActiveColor != null)
111 Effect =
new RGBAFadeOnOffEffect() { ToyName = Toy.
Name, Layer = Layer, FadeActiveDurationMs = TCS.
FadingUpDurationMs, FadeInactiveDurationMs = TCS.
FadingDownDurationMs, RetriggerBehaviour =
RetriggerBehaviourEnum.IgnoreRetrigger, FadeMode =
FadeModeEnum.CurrentToDefined, ActiveColor = ActiveColor, InactiveColor =
new RGBAColor(0, 0, 0, 0) };
117 Effect =
new RGBAOnOffEffect() { ToyName = Toy.
Name, Layer = Layer, ActiveColor = ActiveColor, InactiveColor =
new RGBAColor(0, 0, 0, 0) };
123 else if (Toy is IAnalogAlphaToy)
138 Effect.
Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} {3}".Build(
new object[] { LedWizNr, TCC.Number, SettingNumber, Effect.GetType().
Name });
139 MakeEffectNameUnique(Effect, Table);
141 Table.Effects.Add(Effect);
145 Effect =
new BlinkEffect() { Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} BlinkEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.
Name, DurationActiveMs = TCS.
BlinkIntervalMs, DurationInactiveMs = TCS.
BlinkIntervalMs };
146 MakeEffectNameUnique(Effect, Table);
147 Table.Effects.Add(Effect);
153 Effect =
new DurationEffect() { Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} DurationEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.
Name, DurationMs = Duration, RetriggerBehaviour =
RetriggerBehaviourEnum.RestartEffect };
154 MakeEffectNameUnique(Effect, Table);
155 Table.Effects.Add(Effect);
157 if (TCS.
MinDurationMs > 0 || (Toy is IRGBAToy && EffectRGBMinDurationMs > 0) || (!(Toy is IRGBAToy) && EffectMinDurationMs > 0))
159 string N = (TCS.
MinDurationMs > 0 ?
"MinDuratonEffect" :
"DefaultMinDurationEffect");
161 Effect =
new MinDurationEffect() { Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} {3}".Build(
new object[] { LedWizNr, TCC.Number, SettingNumber, N }), TargetEffectName = Effect.
Name, MinDurationMs = Min };
162 MakeEffectNameUnique(Effect, Table);
163 Table.Effects.Add(Effect);
169 Effect =
new DelayEffect() { Name =
"Ledwiz {0:00} Column {1:00} Setting {2:00} DelayEffect".Build(LedWizNr, TCC.Number, SettingNumber), TargetEffectName = Effect.
Name, DelayMs = TCS.
WaitDurationMs };
170 MakeEffectNameUnique(Effect, Table);
171 Table.Effects.Add(Effect);
202 private void MakeEffectNameUnique(
IEffect Effect, Table.Table Table)
204 if (Table.Effects.Contains(Effect.
Name))
207 while (Table.Effects.Contains(
"{0} {1}".Build(Effect.
Name, Cnt)))
211 Effect.
Name =
"{0} {1}".Build(Effect.
Name, Cnt);
219 private Dictionary<int, Dictionary<int, IToy>> SetupCabinet(Dictionary<int, TableConfig> TableConfigDict,
Cabinet Cabinet)
221 Dictionary<int, Dictionary<int, IToy>> ToyAssignments =
new Dictionary<int, Dictionary<int, IToy>>();
223 Dictionary<int, LedWizEquivalent> LedWizEquivalentDict =
new Dictionary<int, LedWizEquivalent>();
226 LedWizEquivalentDict.Add(((LedWizEquivalent)T).LedWizNumber, (LedWizEquivalent)T);
229 foreach (KeyValuePair<int, TableConfig> KV
in TableConfigDict)
231 int LedWizNr = KV.Key;
232 ToyAssignments.Add(LedWizNr,
new Dictionary<int, IToy>());
235 if (LedWizEquivalentDict.ContainsKey(LedWizNr))
237 LedWizEquivalent LWE = LedWizEquivalentDict[LedWizNr];
241 IToy TargetToy = null;
259 string ToyName =
"LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.
Number);
260 if (Cabinet.
Toys.Contains(ToyName))
263 while (Cabinet.
Toys.Contains(
"{0} {1}".Build(ToyName, Cnt)))
267 ToyName =
"{0} {1}".Build(ToyName, Cnt);
270 Cabinet.
Toys.Add(TargetToy);
273 ToyAssignments[LedWizNr].Add(TCC.
Number, TargetToy);
285 TargetToy = Cabinet.
Toys.First(Toy => Toy is IAnalogAlphaToy && ((IAnalogAlphaToy)Toy).OutputName == LWE.
Outputs.First(
Output =>
Output.LedWizEquivalentOutputNumber == TCC.
FirstOutputNumber).OutputName);
290 string ToyName =
"LedWiz {0:00} Column {1:00}".Build(LedWizNr, TCC.
Number);
292 if (Cabinet.
Toys.Contains(ToyName))
295 while (Cabinet.
Toys.Contains(
"{0} {1}".Build(ToyName, Cnt)))
299 ToyName =
"{0} {1}".Build(ToyName, Cnt);
302 Cabinet.
Toys.Add(TargetToy);
304 ToyAssignments[LedWizNr].Add(TCC.
Number, TargetToy);
313 Log.Warning(
"A illegal number ({0}) of required outputs has been found in a table config colum {0} for ledcontrol nr. {2}. Cant configure toy.".Build(TCC.
RequiredOutputCount, TCC.
Number, LedWizNr));
320 return ToyAssignments;