private static EnemyCellViewModel[] CreateEnemyCells( MapInfo mi, IReadOnlyDictionary <MapInfo, Dictionary <MapCell, Dictionary <string, FleetData> > > mapEnemies, IReadOnlyDictionary <MapCell, CellType> cellTypes) { return(MapResource.HasMapSwf(mi) ? MapResource.GetMapCellPoints(mi) //マップSWFがあったらそれを元に作る //外部結合 .GroupJoin( CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes), outer => outer.Key, inner => inner.Key, (o, ie) => new { point = o, cells = ie }) .SelectMany( x => x.cells.DefaultIfEmpty(), (x, y) => new { x.point, cells = y }) //座標マージ .GroupBy(x => x.point.Value) .Select(x => new EnemyCellViewModel { Key = x.Min(y => y.point.Key), //若い番号を採用 EnemyFleets = x.Where(y => y.cells != null) //敵データをEnemyIdでマージ .SelectMany(y => y.cells.EnemyFleets) .SelectMany(y => y.Fleets) .MergeEnemies(), ColorNo = x.Where(y => y.cells != null).Select(y => y.cells.ColorNo).FirstOrDefault(), CellType = x.Where(y => y.cells != null).Select(y => y.cells.CellType).FirstOrDefault(), }) //敵データのないセルは除外 .Where(x => x.EnemyFleets.Any()) .ToArray() : CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes).ToArray()); //なかったら敵データだけ(重複るが仕方ない) }
public EnemyWindowViewModel( Dictionary <MapInfo, Dictionary <MapCell, Dictionary <int, FleetData> > > mapEnemies, Dictionary <MapCell, CellType> cellTypes, Dictionary <int, List <MapCellData> > cellDatas) { this.EnemyMaps = Master.Current.MapInfos .Select(mi => new EnemyMapViewModel { Info = mi.Value, CellDatas = cellDatas.ContainsKey(mi.Key) ? cellDatas[mi.Key] : new List <MapCellData>(), //セルポイントデータに既知の敵データを外部結合して座標でマージ EnemyCells = MapResource.HasMapSwf(mi.Value) ? MapResource.GetMapCellPoints(mi.Value) //マップSWFがあったらそれを元に作る //外部結合 .GroupJoin( CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes), outer => outer.Key, inner => inner.Key, (o, ie) => new { point = o, cells = ie }) .SelectMany( x => x.cells.DefaultIfEmpty(), (x, y) => new { x.point, cells = y }) //座標マージ .GroupBy(x => x.point.Value) .Select(x => new EnemyCellViewModel { Key = x.Min(y => y.point.Key), //若い番号を採用 EnemyFleets = x.Where(y => y.cells != null) //敵データをEnemyIdでマージ .SelectMany(y => y.cells.EnemyFleets) .GroupBy(y => y.Key) .OrderBy(y => y.Key) .Select(y => y.First()) .Distinct(new FleetComparer()) //同一編成の敵を除去 .ToArray(), ColorNo = x.Where(y => y.cells != null).Select(y => y.cells.ColorNo).FirstOrDefault(), CellType = x.Where(y => y.cells != null).Select(y => y.cells.CellType).FirstOrDefault(), }) //敵データのないセルは除外 .Where(x => x.EnemyFleets.Any()) .ToArray() : CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes) //なかったら敵データだけ(重複るが仕方ない) .OrderBy(cell => cell.Key) .ToArray(), }) .OrderBy(info => info.Info.Id) .ToArray(); }