Esempio n. 1
0
        public static bool TryParseTilesetFormat(string format, out TilesetFormat tilesetFormat)
        {
            tilesetFormat = default;
            if (!format.StartsWith("`uct") || !format.EndsWith("`"))
            {
                return(false);
            }
            format = format.Substring(4, format.Length - 5);
            var hintsplit = format.Split("|");

            if (hintsplit.Length > 2)
            {
                return(false);
            }
            format = hintsplit[0];
            string hint = string.Empty;

            if (hintsplit.Length == 2)
            {
                hint = hintsplit[1];
            }
            var split = format.Split("x");

            if (split.Length != 2)
            {
                return(false);
            }
            if (!int.TryParse(split[0], out int bits) || !int.TryParse(split[1], out int tiles))
            {
                return(false);
            }
            tilesetFormat = new TilesetFormat(bits, tiles, hint);
            return(true);
        }
Esempio n. 2
0
        public static bool TryParseTilesetFormat(string format, out TilesetFormat tilesetFormat)
        {
            tilesetFormat = default;
            if (!(format.StartsWith("`lzt") && format.EndsWith("`")))
            {
                return(false);
            }
            format = format.Substring(4, format.Length - 5);

            // parse the paletteHint
            string hint      = null;
            var    pipeIndex = format.IndexOf('|');

            if (pipeIndex != -1)
            {
                hint   = format.Substring(pipeIndex + 1);
                format = format.Substring(0, pipeIndex);
            }

            if (!int.TryParse(format, out int bits))
            {
                return(false);
            }
            tilesetFormat = new TilesetFormat(bits, hint);
            return(true);
        }
Esempio n. 3
0
        public LzTilesetRun(TilesetFormat format, IDataModel data, int start, SortedSpan <int> sources = null) : base(data, start, sources)
        {
            Format = format;
            var tileSize         = format.BitsPerPixel * 8;
            var uncompressedSize = data.ReadMultiByteValue(start + 1, 3);
            var tileCount        = uncompressedSize / tileSize;
            var roughSize        = Math.Sqrt(tileCount);

            Width  = (int)Math.Ceiling(roughSize);
            Height = (int)roughSize;
        }
Esempio n. 4
0
        public static bool TryParseTilesetFormat(string format, out TilesetFormat tilesetFormat)
        {
            tilesetFormat = default;
            if (!(format.StartsWith("`lzt") && format.EndsWith("`")))
            {
                return(false);
            }
            format = format.Substring(4, format.Length - 5);
            bool allowLengthErrors = false;

            if (format.EndsWith("!"))
            {
                format            = format.Substring(0, format.Length - 1);
                allowLengthErrors = true;
            }

            // parse the paletteHint
            string hint      = null;
            var    pipeIndex = format.IndexOf('|');

            if (pipeIndex != -1)
            {
                hint   = format.Substring(pipeIndex + 1);
                format = format.Substring(0, pipeIndex);
            }

            int maxTiles = -1;

            if (format.Contains("x"))
            {
                var parts = format.Split("x");
                format = parts[0];
                if (parts.Length > 2)
                {
                    return(false);
                }
                if (!int.TryParse(parts[1], out maxTiles))
                {
                    return(false);
                }
            }

            if (!int.TryParse(format, out int bits))
            {
                return(false);
            }
            tilesetFormat = new TilesetFormat(bits, -1, maxTiles, hint, allowLengthErrors);
            return(true);
        }
Esempio n. 5
0
 public TilesetRun(TilesetFormat tilesetFormat, IDataModel model, int start, SortedSpan <int> sources = null) : base(start, sources)
 {
     if (tilesetFormat.Tiles == -1)
     {
         var nextRun = model.GetNextAnchor(start + 1);
         if (nextRun.Start <= start)
         {
             nextRun = model.GetNextAnchor(nextRun.Start + nextRun.Length);
         }
         var tiles = (nextRun.Start - start) / (8 * tilesetFormat.BitsPerPixel);
         tilesetFormat = new TilesetFormat(tilesetFormat.BitsPerPixel, tiles, tilesetFormat.PaletteHint);
     }
     TilesetFormat = tilesetFormat;
     this.model    = model;
 }