2 using System.Collections.Generic;
5 using System.Xml.Serialization;
6 using DirectOutput.Cab.Toys.Layer;
8 namespace DirectOutput.Cab.Toys.Virtual
15 public abstract class ToyGroupBase<MatrixElementType> :
ToyBaseUpdatable,
IToy, IMatrixToy<MatrixElementType>
16 where MatrixElementType:new()
18 private List<List<string>> _ToyNames =
new List<List<string>>();
27 [XmlArrayItem(
"Column",NestingLevel=1)]
28 public List<List<string>> ToyNames
30 get {
return _ToyNames; }
31 set { _ToyNames = value; }
35 private ILayerToy<MatrixElementType>[,] Toys =
new ILayerToy<MatrixElementType>[0, 0];
37 private int _LayerOffset;
46 public int LayerOffset
48 get {
return _LayerOffset; }
49 set { _LayerOffset = value; }
56 public override void UpdateOutputs()
58 foreach (KeyValuePair<
int, MatrixElementType[,]> Layer
in Layers)
60 int LayerNr = Layer.Key+LayerOffset;
62 int Height = Toys.GetUpperBound(1) + 1;
63 int Width=Toys.GetUpperBound(0) + 1;
65 for (
int y = 0; y < Height; y++)
67 for (
int x = 0; x < Width; x++)
69 if (Toys[x, y] != null)
71 Toys[x, y].Layers[LayerNr] = Layer.Value[x, y];
84 int RowCnt = ToyNames.Count;
87 ColCnt = ToyNames.Max(X => X.Count).Limit(1,
int.MaxValue);
91 ToyNames.Add(
new List<string>(
new []{
""}));
96 Toys =
new ILayerToy<MatrixElementType>[ColCnt, RowCnt];
98 for (
int y = 0; y < RowCnt ; y++)
100 for (
int x = 0; x < ColCnt ; x++)
102 if (ToyNames[y].Count > x)
104 if (Cabinet.
Toys.Contains(ToyNames[y][x]) && Cabinet.
Toys[ToyNames[y][x]] is ILayerToy<MatrixElementType>)
106 Toys[x, y] = (ILayerToy<MatrixElementType>)Cabinet.
Toys[ToyNames[y][x]];
123 public override void Reset()
131 public override void Finish()
150 #region IMatrix Member
160 public MatrixElementType[,] GetLayer(
int LayerNr)
162 return Layers[LayerNr];
175 return Toys.GetUpperBound(1) + 1;
190 return Toys.GetUpperBound(0) + 1;