This commit is contained in:
7H3LaughingMan 2025-04-29 19:47:30 +00:00 committed by GitHub
commit aed99b43df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 104 additions and 2 deletions

View file

@ -0,0 +1,52 @@
namespace DotTiled.Tests;
public partial class TestData
{
public static Map DefaultMapBase64ZStd() => new Map
{
Class = "",
Orientation = MapOrientation.Orthogonal,
Width = 5,
Height = 5,
TileWidth = 32,
TileHeight = 32,
Infinite = false,
ParallaxOriginX = 0,
ParallaxOriginY = 0,
RenderOrder = RenderOrder.RightDown,
CompressionLevel = -1,
BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 },
Version = "1.10",
TiledVersion = "1.11.2",
NextLayerID = 2,
NextObjectID = 1,
Layers = [
new TileLayer
{
ID = 1,
Name = "Tile Layer 1",
Width = 5,
Height = 5,
Data = new Data
{
Encoding = DataEncoding.Base64,
Compression = DataCompression.ZStd,
GlobalTileIDs = new Optional<uint[]>([
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0
]),
FlippingFlags = new Optional<FlippingFlags[]>([
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None,
FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None, FlippingFlags.None
])
}
}
]
};
}

View file

@ -0,0 +1,30 @@
{ "compressionlevel":-1,
"height":5,
"infinite":false,
"layers":[
{
"compression":"zstd",
"data":"KLUv\/SBkRQAACAABAIDUCQE=",
"encoding":"base64",
"height":5,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":5,
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.11.2",
"tileheight":32,
"tilesets":[],
"tilewidth":32,
"type":"map",
"version":"1.10",
"width":5
}

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.2" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
<layer id="1" name="Tile Layer 1" width="5" height="5">
<data encoding="base64" compression="zstd">
KLUv/SBkRQAACAABAIDUCQE=
</data>
</layer>
</map>

View file

@ -37,6 +37,7 @@ public static partial class TestData
[GetMapPath("default-map-base64"), (string f) => DefaultMapBase64(), Array.Empty<ICustomTypeDefinition>()], [GetMapPath("default-map-base64"), (string f) => DefaultMapBase64(), Array.Empty<ICustomTypeDefinition>()],
[GetMapPath("default-map-base64-gzip"), (string f) => DefaultMapBase64GZip(), Array.Empty<ICustomTypeDefinition>()], [GetMapPath("default-map-base64-gzip"), (string f) => DefaultMapBase64GZip(), Array.Empty<ICustomTypeDefinition>()],
[GetMapPath("default-map-base64-zlib"), (string f) => DefaultMapBase64ZLib(), Array.Empty<ICustomTypeDefinition>()], [GetMapPath("default-map-base64-zlib"), (string f) => DefaultMapBase64ZLib(), Array.Empty<ICustomTypeDefinition>()],
[GetMapPath("default-map-base64-zstd"), (string f) => DefaultMapBase64ZStd(), Array.Empty<ICustomTypeDefinition>()],
[GetMapPath("map-duplicate-object-id-bug"), (string f) => MapDuplicateObjectIdBug(f), Array.Empty<ICustomTypeDefinition>()], [GetMapPath("map-duplicate-object-id-bug"), (string f) => MapDuplicateObjectIdBug(f), Array.Empty<ICustomTypeDefinition>()],
[GetMapPath("map-with-common-props"), (string f) => MapWithCommonProps(), Array.Empty<ICustomTypeDefinition>()], [GetMapPath("map-with-common-props"), (string f) => MapWithCommonProps(), Array.Empty<ICustomTypeDefinition>()],
[GetMapPath("map-with-custom-type-props"), (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()], [GetMapPath("map-with-custom-type-props"), (string f) => MapWithCustomTypeProps(), MapWithCustomTypePropsCustomTypeDefinitions()],

View file

@ -26,4 +26,8 @@
<None Include="../../LICENSE" Pack="true" PackagePath="" /> <None Include="../../LICENSE" Pack="true" PackagePath="" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="ZstdSharp.Port" Version="0.8.5" />
</ItemGroup>
</Project> </Project>

View file

@ -46,6 +46,12 @@ internal static partial class Helpers
return ReadMemoryStreamAsInt32Array(decompressedStream); return ReadMemoryStreamAsInt32Array(decompressedStream);
} }
internal static uint[] DecompressZStd(MemoryStream stream)
{
using var decompressedStream = new ZstdSharp.DecompressionStream(stream);
return ReadMemoryStreamAsInt32Array(decompressedStream);
}
internal static uint[] ReadBytesAsInt32Array(byte[] bytes) internal static uint[] ReadBytesAsInt32Array(byte[] bytes)
{ {
var intArray = new uint[bytes.Length / 4]; var intArray = new uint[bytes.Length / 4];

View file

@ -61,7 +61,7 @@ public abstract partial class TmjReaderBase
{ {
DataCompression.GZip => Helpers.DecompressGZip(stream), DataCompression.GZip => Helpers.DecompressGZip(stream),
DataCompression.ZLib => Helpers.DecompressZLib(stream), DataCompression.ZLib => Helpers.DecompressZLib(stream),
DataCompression.ZStd => throw new NotSupportedException("ZStd compression is not supported."), DataCompression.ZStd => Helpers.DecompressZStd(stream),
_ => throw new InvalidOperationException($"Unsupported compression '{compression}'.") _ => throw new InvalidOperationException($"Unsupported compression '{compression}'.")
}; };

View file

@ -16,6 +16,7 @@ public abstract partial class TmjReaderBase
{ {
"zlib" => DataCompression.ZLib, "zlib" => DataCompression.ZLib,
"gzip" => DataCompression.GZip, "gzip" => DataCompression.GZip,
"zstd" => DataCompression.ZStd,
"" => Optional.Empty, "" => Optional.Empty,
_ => throw new JsonException($"Unsupported compression '{s}'.") _ => throw new JsonException($"Unsupported compression '{s}'.")
}); });

View file

@ -77,7 +77,7 @@ public abstract partial class TmxReaderBase
{ {
DataCompression.GZip => Helpers.DecompressGZip(bytes), DataCompression.GZip => Helpers.DecompressGZip(bytes),
DataCompression.ZLib => Helpers.DecompressZLib(bytes), DataCompression.ZLib => Helpers.DecompressZLib(bytes),
DataCompression.ZStd => throw new NotSupportedException("ZStd compression is not supported."), DataCompression.ZStd => Helpers.DecompressZStd(bytes),
_ => throw new XmlException("Invalid compression") _ => throw new XmlException("Invalid compression")
}; };