WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
ToyGroupBase.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Xml.Serialization;
7 
8 namespace DirectOutput.Cab.Toys.Virtual
9 {
15  public abstract class ToyGroupBase<MatrixElementType> : ToyBaseUpdatable, IToy, IMatrixToy<MatrixElementType>
16  where MatrixElementType:new()
17  {
18  private List<List<string>> _ToyNames = new List<List<string>>();
19 
26  [XmlArrayItem("Row")]
27  [XmlArrayItem("Column",NestingLevel=1)]
28  public List<List<string>> ToyNames
29  {
30  get { return _ToyNames; }
31  set { _ToyNames = value; }
32  }
33 
34  [XmlIgnore]
36 
37  private int _LayerOffset;
38 
46  public int LayerOffset
47  {
48  get { return _LayerOffset; }
49  set { _LayerOffset = value; }
50  }
51 
52 
56  public override void UpdateOutputs()
57  {
58  foreach (KeyValuePair<int, MatrixElementType[,]> Layer in Layers)
59  {
60  int LayerNr = Layer.Key+LayerOffset;
61 
62  int Height = Toys.GetUpperBound(1) + 1;
63  int Width=Toys.GetUpperBound(0) + 1;
64 
65  for (int y = 0; y < Height; y++)
66  {
67  for (int x = 0; x < Width; x++)
68  {
69  if (Toys[x, y] != null)
70  {
71  Toys[x, y].Layers[LayerNr] = Layer.Value[x, y];
72  }
73  }
74  }
75  }
76  }
81  public override void Init(Cabinet Cabinet)
82  {
83  int ColCnt = 0;
84  int RowCnt = ToyNames.Count;
85  if (RowCnt > 0)
86  {
87  ColCnt = ToyNames.Max(X => X.Count).Limit(1, int.MaxValue);
88  }
89  else
90  {
91  ToyNames.Add(new List<string>(new []{""}));
92  RowCnt = 1;
93  ColCnt = 1;
94  }
95 
96  Toys = new ILayerToy<MatrixElementType>[ColCnt, RowCnt];
97 
98  for (int y = 0; y < RowCnt ; y++)
99  {
100  for (int x = 0; x < ColCnt ; x++)
101  {
102  if (ToyNames[y].Count > x)
103  {
104  if (Cabinet.Toys.Contains(ToyNames[y][x]) && Cabinet.Toys[ToyNames[y][x]] is ILayerToy<MatrixElementType>)
105  {
106  Toys[x, y] = (ILayerToy<MatrixElementType>)Cabinet.Toys[ToyNames[y][x]];
107  }
108  else
109  {
110  Toys[x, y] = null;
111  }
112  }
113  }
114  }
115 
116  Layers = new MatrixDictionaryBase<MatrixElementType>() { Width = Width, Height = Height };
117 
118  }
119 
123  public override void Reset()
124  {
125  Layers = new MatrixDictionaryBase<MatrixElementType>() { Width = Width, Height = Height };
126  }
127 
131  public override void Finish()
132  {
133  base.Finish();
134  Layers = null;
135  Toys = null;
136  }
137 
138 
139 
146  [XmlIgnore]
147  public MatrixDictionaryBase<MatrixElementType> Layers { get; private set; }
148 
149 
150  #region IMatrix Member
151 
160  public MatrixElementType[,] GetLayer(int LayerNr)
161  {
162  return Layers[LayerNr];
163  }
164 
171  public int Height
172  {
173  get
174  {
175  return Toys.GetUpperBound(1) + 1;
176  }
177 
178  }
179 
186  public int Width
187  {
188  get
189  {
190  return Toys.GetUpperBound(0) + 1;
191  }
192  }
193 
194  #endregion
195  }
196 }
Sorted dictionary of layers for the matrix toys.
override void Reset()
Resets the state of the IToy to its default state.
This toys allows the grouping of several toys into a matrix, which can be controlled by matrix effect...
Definition: ToyGroupBase.cs:15
The Cabinet object describes the parts of a pinball cabinet (toys, outputcontrollers, outputs and more).
Definition: Cabinet.cs:17
The namespace DirectOutput.Cab.Toys contains all toy related classes.
Interface for toys having a matrix of elements (e.g. ledstrips)
Definition: IMatrixToy.cs:12
override void Init(Cabinet Cabinet)
Initializes the toy.
Definition: ToyGroupBase.cs:81
DirectOutput.Cab.Toys.ToyList Toys
List of IToy objects describing the toys in the cabinet.
Definition: Cabinet.cs:107
Common interface for all toy implementations. The abstract class ToyBase implements this interface...
Definition: IToy.cs:9
override void Finish()
Finished the toy, releases references to toys and layers.
The namespace DirectOutput.Cab contains all cabinet related classes like the Cabinet class itself...
Definition: Cab.cs:16
LayerDictionary< LayerElementType > Layers
Definition: ILayerToy.cs:7
override void UpdateOutputs()
Updates the toys specified in the toy names array with the values from the layers of this toy...
Definition: ToyGroupBase.cs:56
MatrixElementType[,] GetLayer(int LayerNr)
Gets the 2 dimensional data array for the specified layer.
Namespace for objects dealing with layers
Base class for toys which need update calls to update the state of their assigned outputs...