public void WriteCustomTileset()
        {
            MemoryStream writer = new MemoryStream();

            BitmapFile tileset1 = new BitmapFile(8, 32, -32, new Color[] { DiscreteColor.Red });

            TilesetLoader.WriteCustomTileset(writer, tileset1);
            writer.Position = 0;

            // Read just written tileset to ensure it was well formed
            BitmapFile tileset2 = TilesetLoader.ReadTileset(writer);

            Assert.AreEqual(tileset1, tileset2);
        }
        public void ReadTileset()
        {
            // Well formed standard bitmap
            BitmapFile   tileset = new BitmapFile(8, 32, 32, new Color[] { DiscreteColor.Red });
            MemoryStream writer  = new MemoryStream();

            tileset.Serialize(writer);

            writer.Position = 0;
            BitmapFile newTileset = TilesetLoader.ReadTileset(writer);

            Assert.AreEqual(tileset, newTileset);

            // Well formed standard bitmap - Wrong width for a tileset
            tileset = new BitmapFile(8, 20, 32, new Color[] { DiscreteColor.Red });
            tileset.Serialize(writer);
            Assert.ThrowsException <Exception>(() => TilesetLoader.ReadTileset(writer));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the specified tileset texture from cache.
        /// If not found, attempts to load it from the archive directory.
        /// </summary>
        public static Texture2D LoadTileset(string tilesetFileName)
        {
            // Get tile bitmap data
            Texture2D texture;

            if (m_Tilesets.TryGetValue(tilesetFileName, out texture))
            {
                return(texture);
            }

            // Image not found in cache. Fetch from archive.
            Stream tileImageStream = m_ResourceManager.GetResourceStream(tilesetFileName + ".bmp", true);

            if (tileImageStream == null)
            {
                Debug.LogError("Could not find resource: " + tilesetFileName);
                return(null);
            }

            // Convert image into standard bmp byte data
            byte[] tileImageData;
            OP2UtilityDotNet.Bitmap.BitmapFile bmpFile = TilesetLoader.ReadTileset(tileImageStream);
            using (MemoryStream memStream = new MemoryStream())
            {
                if (bmpFile.GetScanLineOrientation() == OP2UtilityDotNet.Bitmap.ScanLineOrientation.TopDown)
                {
                    bmpFile.InvertScanLines();
                }
                bmpFile.Serialize(memStream);
                tileImageData = memStream.ToArray();
            }

            texture = GetTextureFromBMP(tileImageData);
            if (texture == null)
            {
                return(null);
            }
            texture.filterMode = FilterMode.Point;
            texture.wrapMode   = TextureWrapMode.Clamp;
            m_Tilesets.Add(tilesetFileName, texture);

            return(texture);
        }
Ejemplo n.º 4
0
        private void OnExtractFileSavePathSelected(ArchiveFile archive, string fileName, string destPath)
        {
            interactable = true;
            try
            {
                if (Path.GetExtension(fileName).ToLowerInvariant() == ".bmp")
                {
                    // Special processing to convert tileset to a standard bmp format
                    BitmapFile bitmapFile = TilesetLoader.ReadTileset(archive.ExtractFileToMemory(fileName));
                    bitmapFile.Serialize(destPath);
                }
                else
                {
                    archive.ExtractFile(fileName, destPath);
                }
            }
            finally
            {
                archive.Dispose();
            }

            Debug.Log(Path.GetFileName(destPath) + " extracted successfully.");
        }