Esempio n. 1
0
        public override void Write(BinaryWriter writer, PSSFile file)
        {
            if (file.Tiles.Count == 0)
            {
                return;
            }

            writer.Write(file.Tiles.Count);

            foreach (var tile in file.Tiles.OrderBy(t => t.Index))
            {
                writer.Write((byte)(tile.Label?.Length ?? 0));

                if (!string.IsNullOrEmpty(tile.Label))
                {
                    writer.Write(Encoding.ASCII.GetBytes(tile.Label));
                }

                if (file.Platform == PSSFile.TargetPlatform.Gameboy)
                {
                    writer.Write(tile.TileImage.ToGameboyBytes());
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Esempio n. 2
0
        public static PSSFile Load(string filename)
        {
            using (var fileStream = File.OpenRead(filename))
                using (var reader = new BinaryReader(fileStream))
                {
                    var fileTag = Encoding.ASCII.GetString(reader.ReadBytes(3));

                    if (fileTag != "PSS")
                    {
                        throw new Exception("not a PSS File");
                    }

                    var formatVersion = reader.ReadByte();
                    var platform      = reader.ReadByte();

                    var loadedFile = new PSSFile()
                    {
                        Version = formatVersion, Platform = (TargetPlatform)platform, VersionMismatch = formatVersion != MaxVersion
                    };

                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        loadedFile.ReadLump(reader);
                    }

                    reader.Close();
                    fileStream.Close();
                    return(loadedFile);
                }
        }
Esempio n. 3
0
        public override void Read(BinaryReader reader, PSSFile file)
        {
            var tileCount = reader.ReadInt32();

            for (var i = 0; i < tileCount; i++)
            {
                var tile = new Tile();

                tile.Index = i;

                var labelLength = reader.ReadByte();
                tile.Label = labelLength > 0 ? Encoding.ASCII.GetString(reader.ReadBytes(labelLength)) : string.Empty;

                if (file.Platform == PSSFile.TargetPlatform.Gameboy)
                {
                    var imageData = reader.ReadBytes(16);
                    tile.TileImage = Tile.Empty().FromGameboyBytes(imageData);
                }
                else
                {
                    throw new NotImplementedException();
                }

                file.Tiles.Add(tile);
            }
        }
Esempio n. 4
0
        public override void Read(BinaryReader reader, PSSFile file)
        {
            var mapCount = reader.ReadInt32();

            for (var i = 0; i < mapCount; i++)
            {
                var width       = reader.ReadInt32();
                var height      = reader.ReadInt32();
                var labelLength = reader.ReadByte();
                var name        = labelLength > 0 ? Encoding.ASCII.GetString(reader.ReadBytes(labelLength)) : string.Empty;
                var mapFlags    = reader.ReadByte();

                var mapData = reader.ReadBytes(width * height);

                byte[] blocks = null;

                if (mapFlags == 1)
                {
                    blocks = reader.ReadBytes(width * height);
                }

                var map = new TileMap(name, width, height, mapData, blocks)
                {
                    Index = i
                };

                file.Maps.Add(map);
            }
        }
Esempio n. 5
0
        public override void Write(BinaryWriter writer, PSSFile file)
        {
            writer.Write(file.Maps.Count);

            foreach (var map in file.Maps.OrderBy(t => t.Index))
            {
                writer.Write(map.Width);
                writer.Write(map.Height);
                writer.Write((byte)map.Name.Length);
                writer.Write(Encoding.ASCII.GetBytes(map.Name));
                writer.Write(map.Blocks == null ? (byte)0 : (byte)1);

                writer.Write(map.Tiles);

                if (map.Blocks != null)
                {
                    writer.Write(map.Blocks);
                }
            }
        }
Esempio n. 6
0
 public abstract void Read(BinaryReader reader, PSSFile file);
Esempio n. 7
0
 public abstract void Write(BinaryWriter writer, PSSFile file);