Esempio n. 1
0
        private void ProcessLvlFiles(IEnumerable <string> files, Dictionary <string, MyBitmap> newMap, Dictionary <string, MyBitmap> oldMap)
        {
            // Create the mapping.
            var mapping = new Dictionary <string, string>();

            foreach (var tileOld in oldMap)
            {
                var tileNew = newMap.FirstOrDefault(t => t.Value.Equals(tileOld.Value));
                mapping.Add(tileOld.Key, tileNew.Key); // tileNew.Key will be null if not found
            }

            foreach (var file in files)
            {
                var level = Level.Read(file);
                for (var x = 0; x < level.Tiles.Length; x++)
                {
                    for (var y = 0; y < level.Tiles[x].Length; y++)
                    {
                        var id    = TileIds.ParsePaletteId(level.Tiles[x][y]);
                        var newId = mapping[id.Item2];

                        if (newId == null)
                        {
                            throw new Exception($"Removed tile in level {file}");
                        }

                        level.Tiles[x][y] = TileIds.PaletteTileId(id.Item1, newId);
                    }
                }

                level.Write(file);
            }
        }