예제 #1
0
        ///<summary>Decode, decompress, and reorder rows of global tile IDs</summary>
        uint[] ParseGIDs(string encoding, string compression, string data, int width, GridLayout.CellLayout layout)
        {
            // Decoding
            byte[] input;
            switch (encoding)
            {
            case "base64": input = Convert.FromBase64String(data); break;

            default: throw new NotImplementedException("Encoding: " + (encoding ?? "xml"));
            }

            // Decompression
            byte[] output;
            switch (compression)
            {
            case null:   output = input;             break;

            case "gzip": output = CompressionHelper.DecompressGZip(input); break;

            case "zlib": output = CompressionHelper.DecompressZlib(input); break;

            default: throw new NotImplementedException("Compression: " + compression);
            }

            // Parse bytes as uint32 gids
            var gids = new uint[output.Length / 4];

            Buffer.BlockCopy(output, 0, gids, 0, output.Length);
            if (layout == GridLayout.CellLayout.Rectangle)
            {
                return(ArrayHelper.Reverse(gids, stride: width));
            }
            else if (layout == GridLayout.CellLayout.Isometric)
            {
                return(ArrayHelper.Swizzle(gids, stride: width).Reverse().ToArray());
            }
            else
            {
                return(gids);
            }
        }