Exemplo n.º 1
0
        public void WriteToFile(string path, IAssetPathProvider assetPathProvider)
        {
            // Write out textures...
            ImageWriter imageWriter = new ImageWriter();

            this.RegisterImages(imageWriter, assetPathProvider);
            string texturePath = System.IO.Path.ChangeExtension(path, ".tex");

#if false // OLD FORMAT
            using (var stream = File.Create(texturePath))
            {
                using (var zip = new GZipStream(stream, CompressionMode.Compress, true))
                {
                    using (var bw = new BinaryWriter(zip))
                    {
                        imageWriter.WriteOutAllImagesOLD(bw);
                    }
                }
            }
#else
            MemoryStream ms = new MemoryStream();
            ms.WriteByte(0); // <- version
            imageWriter.WriteOutAllImages(ms);
            ms.Position = 0;
            File.WriteAllBytes(texturePath, ms.ToArray());
#endif

            // Write out Level:
            using (var stream = File.Create(path))
            {
                using (var zip = new GZipStream(stream, CompressionMode.Compress, true))
                {
                    using (var bw = new BinaryWriter(zip))
                    {
                        Serialize(new LevelSerializeContext(bw, imageWriter, assetPathProvider));
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void WriteToFile(this AnimationSet animationSet, string path)
        {
            var imageWriter = new ImageWriter();

            animationSet.RegisterImages(imageWriter);
            var texturePath = Path.ChangeExtension(path, ".tex");

#if false // OLD FORMAT
            using (var stream = File.Create(texturePath))
            {
                using (var zip = new GZipStream(stream, CompressionMode.Compress, true))
                {
                    using (var bw = new BinaryWriter(zip))
                    {
                        imageWriter.WriteOutAllImagesOLD(bw);
                    }
                }
            }
#else
            var ms = new MemoryStream();
            ms.WriteByte(0);             // <- version
            imageWriter.WriteOutAllImages(ms);
            ms.Position = 0;
            File.WriteAllBytes(texturePath, ms.ToArray());
#endif

            using (var stream = File.Create(path))
            {
                using (var zip = new GZipStream(stream, CompressionMode.Compress, true))
                {
                    using (var bw = new BinaryWriter(zip))
                    {
                        animationSet.Serialize(new AnimationSerializeContext(bw, imageWriter));
                    }
                }
            }
        }