public AreaMap( int level, Func <IAreaMapCellInternal> cellFactory, int width, int height, IMapLightLevelProcessor mapLightLevelProcessor = null) { this.mapLightLevelProcessor = mapLightLevelProcessor ?? new MapLightLevelProcessor(); objectPositionCache = new Dictionary <Type, Point>(); destroyableObjects = new Dictionary <string, IDestroyableObject>(); Level = level; Width = width; Height = height; cells = new IAreaMapCellInternal[height][]; for (var y = 0; y < height; y++) { cells[y] = new IAreaMapCellInternal[width]; for (var x = 0; x < width; x++) { cells[y][x] = cellFactory(); } } }
public AreaMap(SaveData dataBuilder) { mapLightLevelProcessor = new MapLightLevelProcessor(); objectPositionCache = new Dictionary <Type, Point>(); destroyableObjects = new Dictionary <string, IDestroyableObject>(); Level = dataBuilder.GetIntValue(SaveKeyLevel); Width = dataBuilder.GetIntValue(SaveKeyWidth); Height = dataBuilder.GetIntValue(SaveKeyHeight); cells = dataBuilder.GetObject <GridSaveable>(SaveKeyCells).Rows.Select(row => row.Cast <IAreaMapCellInternal>().ToArray()).ToArray(); for (var y = 0; y < Height; y++) { for (var x = 0; x < Width; x++) { var cell = cells[y][x]; foreach (var destroyable in cell.ObjectsCollection.OfType <IDestroyableObject>()) { destroyableObjects.Add(destroyable.Id, destroyable); } } } }