Exemple #1
0
        public override ArcFile TryOpen(ArcView file)
        {
            if (!file.Name.HasExtension(".lay"))
            {
                return(null);
            }
            int tile_count  = file.View.ReadInt32(0);
            int coord_count = file.View.ReadInt32(4);

            if (!IsSaneCount(tile_count) || !IsSaneCount(coord_count))
            {
                return(null);
            }
            var base_name = Path.GetFileNameWithoutExtension(file.Name).TrimEnd('_');
            var png_name  = VFS.ChangeFileName(file.Name, base_name + ".png");

            if (!VFS.FileExists(png_name))
            {
                return(null);
            }
            ImageData image;
            var       png_entry = VFS.FindFile(png_name);

            using (var decoder = VFS.OpenImage(png_entry))
                image = decoder.Image;
            using (var input = file.CreateStream())
                using (var index = new BinaryReader(input))
                {
                    input.Position = 8;
                    var dir = new List <Entry> (tile_count);
                    for (int i = 0; i < tile_count; ++i)
                    {
                        uint id    = index.ReadUInt32();
                        int  first = index.ReadInt32();
                        int  count = index.ReadInt32();
                        var  name  = string.Format("{0}#{1:X8}", base_name, id);
                        var  entry = new LayEntry {
                            Name = name, Type = "image", Offset = 0,
                            Id   = id, First = first, Count = count
                        };
                        dir.Add(entry);
                    }
                    var tiles = new List <LayCoord> (coord_count);
                    for (int i = 0; i < coord_count; ++i)
                    {
                        var tile = new LayCoord();
                        tile.TargetX = index.ReadSingle() + 1;
                        tile.TargetY = index.ReadSingle() + 1;
                        tile.SourceX = index.ReadSingle() - 1;
                        tile.SourceY = index.ReadSingle() - 1;
                        tiles.Add(tile);
                    }
                    return(new LayArchive(file, this, dir, image.Bitmap, tiles));
                }
        }
Exemple #2
0
 public IEnumerable <LayCoord> GetTiles(LayEntry layer)
 {
     return(Tiles.Skip(layer.First).Take(layer.Count));
 }