예제 #1
0
        /// <summary>
        /// Reads the windowstyle from a filestream.
        /// </summary>
        /// <param name="binread">The System.IO.BinaryReader to use.</param>
        public void Open(BinaryReader binread)
        {
            _sig            = new string(binread.ReadChars(4));
            _version        = binread.ReadInt16();
            _edgeWidth      = binread.ReadByte();
            _backgroundMode = binread.ReadByte();
            for (int i = 0; i < _edgeColors.Length; ++i)
            {
                _edgeColors[i] = new RGBA();
                _edgeColors[i].ReadData(binread);
            }
            for (int i = 0; i < _edgeOffset.Length; ++i)
            {
                _edgeOffset[1] = binread.ReadByte();
            }
            binread.ReadBytes(36); // reserved

            switch (_version)
            {
            case 2:
                for (int i = 0; i < _images.Length; ++i)
                {
                    short        width  = binread.ReadInt16();
                    short        height = binread.ReadInt16();
                    BitmapLoader loader = new BitmapLoader(width, height);
                    _images[i] = loader.LoadFromStream(binread, width * height * 4);
                    loader.Close();
                }
                break;
            }
        }
예제 #2
0
        public Character(BinaryReader stream, short version)
        {
            _width  = stream.ReadInt16();
            _height = stream.ReadInt16();
            stream.ReadBytes(28);

            int          size   = _width * _height * 4;
            BitmapLoader loader = new BitmapLoader(_width, _height);

            if (version >= 1)
            {
                _image = loader.LoadFromStream(stream, size);
            }
            loader.Close();
        }
예제 #3
0
        /// <summary>
        /// Loads a tileset from a filestream.
        /// </summary>
        /// <param name="reader">The System.IO.BinrayReader to use.</param>
        /// <returns>A tileset object.</returns>
        public static Tileset FromBinary(BinaryReader reader)
        {
            Tileset ts = new Tileset();

            reader.ReadChars(4);              // sign
            ts._version = reader.ReadInt16(); // version
            short numTiles = reader.ReadInt16();

            ts.TileWidth  = reader.ReadInt16();
            ts.TileHeight = reader.ReadInt16();
            reader.ReadInt16(); // tile_bpp
            ts._compression = reader.ReadByte();
            ts._hasObstruct = reader.ReadByte();
            reader.ReadBytes(240);

            using (BitmapLoader loader = new BitmapLoader(ts.TileWidth, ts.TileHeight))
            {
                int bitSize = ts.TileWidth * ts.TileHeight * 4;

                while (numTiles-- > 0)
                {
                    Tile newTile = new Tile(ts.TileWidth, ts.TileHeight);
                    newTile.Graphic = loader.LoadFromStream(reader, bitSize);
                    ts.Tiles.Add(newTile);
                }
            }

            foreach (Tile t in ts.Tiles)
            {
                reader.ReadByte();
                t.Animated = reader.ReadBoolean();
                t.NextAnim = reader.ReadInt16();
                t.Delay    = reader.ReadInt16();
                reader.ReadByte();
                t.Blocked = reader.ReadByte();
                int segs = reader.ReadInt16();
                int amt  = reader.ReadInt16();
                reader.ReadBytes(20);
                t.Name = new string(reader.ReadChars(amt));
                while (segs-- > 0)
                {
                    Line l = new Line(reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16());
                    t.Obstructions.Add(l);
                }
            }

            return(ts);
        }
예제 #4
0
        public void ReadFromStream(BinaryReader stream)
        {
            // Read Header //
            string sign = new string(stream.ReadChars(4));

            version = stream.ReadInt16();
            short num_tiles = stream.ReadInt16();

            SetTileSize(stream.ReadInt16(), stream.ReadInt16());

            tile_bpp         = stream.ReadInt16();
            compression      = stream.ReadByte();
            has_obstructions = stream.ReadByte();
            stream.ReadBytes(240);

            // data preallocated for the loop:
            int          bit_size = tile_width * tile_height * (tile_bpp / 8);
            BitmapLoader loader   = new BitmapLoader(tile_width, tile_height);
            Tile         new_tile;

            while (num_tiles-- > 0)
            {
                new_tile         = new Tile(tile_width, tile_height);
                new_tile.Graphic = loader.LoadFromStream(stream, bit_size);
                tiles.Add(new_tile);
            }

            // Read Tile Info Block: //
            foreach (Tile t in tiles)
            {
                stream.ReadByte();
                t.Animated = stream.ReadBoolean();
                t.NextAnim = stream.ReadInt16();
                t.Delay    = stream.ReadInt16();
                stream.ReadByte();
                t.Blocked = stream.ReadByte();
                int segments = stream.ReadInt16();
                int amt      = stream.ReadInt16();
                stream.ReadBytes(20);
                t.Name = new string(stream.ReadChars(amt));
                while (segments-- > 0)
                {
                    Line l = new Line(stream.ReadInt16(), stream.ReadInt16(), stream.ReadInt16(), stream.ReadInt16());
                    t.Obstructions.Add(l);
                }
            }
            loader.Close();
        }
예제 #5
0
        public void ReadFromStream(BinaryReader stream)
        {
            // Read Header //
            string sign = new string(stream.ReadChars(4));
            version = stream.ReadInt16();
            short num_tiles = stream.ReadInt16();

            SetTileSize(stream.ReadInt16(), stream.ReadInt16());

            tile_bpp = stream.ReadInt16();
            compression = stream.ReadByte();
            has_obstructions = stream.ReadByte();
            stream.ReadBytes(240);

            // data preallocated for the loop:
            int bit_size = tile_width * tile_height * (tile_bpp / 8);
            BitmapLoader loader = new BitmapLoader(tile_width, tile_height);
            Tile new_tile;

            while (num_tiles-- > 0)
            {
                new_tile = new Tile(tile_width, tile_height);
                new_tile.Graphic = loader.LoadFromStream(stream, bit_size);
                tiles.Add(new_tile);
            }

            // Read Tile Info Block: //
            foreach (Tile t in tiles)
            {
                stream.ReadByte();
                t.Animated = stream.ReadBoolean();
                t.NextAnim = stream.ReadInt16();
                t.Delay = stream.ReadInt16();
                stream.ReadByte();
                t.Blocked = stream.ReadByte();
                int segments = stream.ReadInt16();
                int amt = stream.ReadInt16();
                stream.ReadBytes(20);
                t.Name = new string(stream.ReadChars(amt));
                while (segments-- > 0)
                {
                    Line l = new Line(stream.ReadInt16(), stream.ReadInt16(), stream.ReadInt16(), stream.ReadInt16());
                    t.Obstructions.Add(l);
                }
            }
            loader.Close();
        }
예제 #6
0
        /// <summary>
        /// Attempts to load the spriteset from the given filename.
        /// </summary>
        /// <param name="filename">The filename of the Spriteset to load.</param>
        /// <returns>True if successful.</returns>
        public bool Load(String filename)
        {
            if (!File.Exists(filename))
            {
                return(false);
            }
            using (BinaryReader stream = new BinaryReader(File.OpenRead(filename)))
            {
                // purge anything already inside this object:
                Purge();

                // start reading the header //
                string sig = new string(stream.ReadChars(4));
                if (sig != ".rss")
                {
                    return(false);
                }

                _version = stream.ReadInt16();
                short numImages = stream.ReadInt16();
                _frameWidth  = stream.ReadInt16();
                _frameHeight = stream.ReadInt16();
                short numDirs = stream.ReadInt16();

                // read sprite base //
                _spriteBase.X1 = stream.ReadInt16();
                _spriteBase.Y1 = stream.ReadInt16();
                _spriteBase.X2 = stream.ReadInt16();
                _spriteBase.Y2 = stream.ReadInt16();

                // reserved //
                stream.ReadBytes(106);
                switch (_version)
                {
                case 3:
                    BitmapLoader loader = new BitmapLoader(_frameWidth, _frameHeight);
                    int          amt    = _frameWidth * _frameHeight * 4;
                    while (numImages-- > 0)
                    {
                        _images.Add(loader.LoadFromStream(stream, amt));
                    }
                    loader.Close();

                    while (numDirs-- > 0)
                    {
                        short numFrames = stream.ReadInt16();
                        stream.ReadBytes(6);
                        short     length = stream.ReadInt16();
                        string    name   = new String(stream.ReadChars(length)).Substring(0, length - 1);
                        Direction dir    = new Direction(name);
                        while (numFrames-- > 0)
                        {
                            Frame f = new Frame {
                                Index = stream.ReadInt16(), Delay = stream.ReadInt16()
                            };
                            dir.Frames.Add(f);
                            stream.ReadBytes(4);
                        }
                        _directions.Add(dir);
                    }
                    break;
                }
            }
            return(true);
        }