Add support for zstd compression

This commit is contained in:
Darren Eberly
2021-02-21 04:38:47 -05:00
parent a0470a3d6e
commit ee56afe9dd
6 changed files with 220 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ See:
import base64
import gzip
import zlib
import zstd
from pathlib import Path
from typing import Any, Callable, List, Optional, Union
from typing import cast as type_cast
@@ -243,6 +244,8 @@ def _decode_tile_layer_data(
unzipped_data = zlib.decompress(unencoded_data)
elif compression == "gzip":
unzipped_data = gzip.decompress(unencoded_data)
elif compression == "zstd":
unzipped_data = zstd.decompress(unencoded_data)
else:
unzipped_data = unencoded_data

View File

@@ -25,6 +25,7 @@ setup_requires =
setuptools >= 40.6
pip >= 10
install_requires =
zstd == 1.4.8.1
attrs
typing-extensions

View File

@@ -0,0 +1,109 @@
from pathlib import Path
from pytiled_parser import common_types, layer, tiled_object
EXPECTED = [
layer.TileLayer(
name="Tile Layer 1",
opacity=1,
visible=True,
id=1,
size=common_types.Size(8, 6),
data=[
[
1,
2,
3,
4,
5,
6,
7,
8,
],
[
9,
10,
11,
12,
13,
14,
15,
16,
],
[
17,
18,
19,
20,
21,
22,
23,
24,
],
[
25,
26,
27,
28,
29,
30,
31,
32,
],
[
33,
34,
35,
36,
37,
38,
39,
40,
],
[
41,
42,
43,
44,
45,
46,
47,
48,
],
],
),
layer.LayerGroup(
name="Group 1",
opacity=1,
visible=True,
id=4,
layers=[
layer.ObjectLayer(
name="Object Layer 1",
opacity=1,
visible=True,
id=2,
draw_order="topdown",
tiled_objects=[
tiled_object.Rectangle(
id=1,
name="",
rotation=0,
size=common_types.Size(69.3333333333333, 52.6666666666667),
coordinates=common_types.OrderedPair(46.3333333333333, 39),
visible=True,
type="",
)
],
),
],
),
layer.ImageLayer(
name="Image Layer 1",
opacity=1,
visible=True,
id=3,
image=Path("../../images/tile_04.png"),
transparent_color=common_types.Color(0, 0, 0, 255),
),
]

View File

@@ -0,0 +1,84 @@
{ "compressionlevel":-1,
"editorsettings":
{
"export":
{
"target":"."
}
},
"height":6,
"infinite":false,
"layers":[
{
"compression":"zstd",
"data":"KLUv\/SDAZQIAAgwSDBCw3gwwDFcLT4p0Cv\/c884531zzzDG\/3PLKKZ9c8sghf9zxxhlfXPHEET\/c8MIJH1zwwAH\/7r079+3as2O\/br069enSo0MBAA==",
"encoding":"base64",
"height":6,
"id":1,
"name":"Tile Layer 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":8,
"x":0,
"y":0
},
{
"id":4,
"layers":[
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"height":52.6666666666667,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":69.3333333333333,
"x":46.3333333333333,
"y":39
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"name":"Group 1",
"opacity":1,
"type":"group",
"visible":true,
"x":0,
"y":0
},
{
"id":3,
"image":"..\/..\/images\/tile_04.png",
"name":"Image Layer 1",
"opacity":1,
"transparentcolor":"#000000",
"type":"imagelayer",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":5,
"nextobjectid":3,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.4.3",
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"source":"..\/all_layer_types\/tileset.json"
}],
"tilewidth":32,
"type":"map",
"version":1.4,
"width":8
}

View File

@@ -0,0 +1,22 @@
{ "columns":8,
"editorsettings":
{
"export":
{
"format":"",
"target":"."
}
},
"image":"..\/..\/images\/tmw_desert_spacing.png",
"imageheight":199,
"imagewidth":265,
"margin":1,
"name":"tile_set_image",
"spacing":1,
"tilecount":48,
"tiledversion":"1.3.5",
"tileheight":32,
"tilewidth":32,
"type":"tileset",
"version":1.2
}

View File

@@ -18,6 +18,7 @@ ALL_LAYER_TESTS = [
LAYER_TESTS / "b64",
LAYER_TESTS / "b64_gzip",
LAYER_TESTS / "b64_zlib",
LAYER_TESTS / "b64_zstd",
LAYER_TESTS / "no_layers",
LAYER_TESTS / "infinite_map",
LAYER_TESTS / "infinite_map_b64",