/// <summary> /// Initializes the toy. /// </summary> /// <param name="Cabinet"><see cref="Cabinet" /> object to which the <see cref="IToy" /> belongs.</param> public override void Init(Cabinet Cabinet) { int ColCnt = 0; int RowCnt = ToyNames.Count; if (RowCnt > 0) { ColCnt = ToyNames.Max(X => X.Count).Limit(1, int.MaxValue); } else { ToyNames.Add(new List <string>(new [] { "" })); RowCnt = 1; ColCnt = 1; } Toys = new ILayerToy <MatrixElementType> [ColCnt, RowCnt]; for (int y = 0; y < RowCnt; y++) { for (int x = 0; x < ColCnt; x++) { if (ToyNames[y].Count > x) { if (Cabinet.Toys.Contains(ToyNames[y][x]) && Cabinet.Toys[ToyNames[y][x]] is ILayerToy <MatrixElementType> ) { Toys[x, y] = (ILayerToy <MatrixElementType>)Cabinet.Toys[ToyNames[y][x]]; } else { Toys[x, y] = null; } } } } Layers = new MatrixDictionaryBase <MatrixElementType>() { Width = Width, Height = Height }; }
/// <summary> /// Finished the toy, releases references to toys and layers. /// </summary> public override void Finish() { base.Finish(); Layers = null; Toys = null; }