예제 #1
0
        public void Deduplicate(string remappingPath)
        {
            using (TexturePacker levelPacker = new TexturePacker(Level))
            {
                Dictionary <TexturedTile, List <TexturedTileSegment> > allTextures = new Dictionary <TexturedTile, List <TexturedTileSegment> >();
                foreach (TexturedTile tile in levelPacker.Tiles)
                {
                    allTextures[tile] = new List <TexturedTileSegment>(tile.Rectangles);
                }

                TextureRemapGroup remapGroup = JsonConvert.DeserializeObject <TextureRemapGroup>(File.ReadAllText(remappingPath));

                _deduplicator.SegmentMap           = allTextures;
                _deduplicator.PrecompiledRemapping = remapGroup.Remapping;
                _deduplicator.Deduplicate();

                levelPacker.AllowEmptyPacking = true;
                levelPacker.Pack(true);

                // Now we want to go through every IndexedTexture and see if it's
                // pointing to the same thing - so tile, position, and point direction
                // have to be equal. See IndexedTRObjectTexture
                Dictionary <int, int> indexMap = new Dictionary <int, int>();
                foreach (TexturedTile tile in allTextures.Keys)
                {
                    foreach (TexturedTileSegment segment in allTextures[tile])
                    {
                        TidySegment(segment, indexMap);
                    }
                }

                Level.ReindexTextures(indexMap);
                Level.ResetUnusedTextures();
            }
        }
예제 #2
0
        private void ExportDuplicateLevelTextures(string lvlPath)
        {
            TR2Level level = _reader.ReadLevel(lvlPath);

            using (TexturePacker levelPacker = new TexturePacker(level))
            {
                Dictionary <TexturedTile, List <TexturedTileSegment> > allTextures = new Dictionary <TexturedTile, List <TexturedTileSegment> >();
                foreach (TexturedTile tile in levelPacker.Tiles)
                {
                    allTextures[tile] = new List <TexturedTileSegment>(tile.Rectangles);
                }

                _deduplicator.SegmentMap = allTextures;
                _deduplicator.Deduplicate();

                if (_levelRemap.ContainsKey(_currentLevel))
                {
                    if (_outputTileImages)
                    {
                        string dir = Path.Combine(_outputDirectory, _currentLevel);
                        Directory.CreateDirectory(dir);
                        foreach (TexturedTile tile in allTextures.Keys)
                        {
                            tile.BitmapGraphics.Bitmap.Save(Path.Combine(dir, tile.Index.ToString() + ".png"), ImageFormat.Png);
                        }
                    }

                    File.WriteAllText(Path.Combine(_outputDirectory, _currentLevel + "-TextureRemap.json"), JsonConvert.SerializeObject(_levelRemap[_currentLevel], Formatting.Indented));
                }
            }
        }