Skip to content

Commit ee56afe

Browse files
committed
Add support for zstd compression
1 parent a0470a3 commit ee56afe

File tree

6 files changed

+220
-0
lines changed

6 files changed

+220
-0
lines changed

pytiled_parser/layer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import base64
1212
import gzip
1313
import zlib
14+
import zstd
1415
from pathlib import Path
1516
from typing import Any, Callable, List, Optional, Union
1617
from typing import cast as type_cast
@@ -243,6 +244,8 @@ def _decode_tile_layer_data(
243244
unzipped_data = zlib.decompress(unencoded_data)
244245
elif compression == "gzip":
245246
unzipped_data = gzip.decompress(unencoded_data)
247+
elif compression == "zstd":
248+
unzipped_data = zstd.decompress(unencoded_data)
246249
else:
247250
unzipped_data = unencoded_data
248251

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ setup_requires =
2525
setuptools >= 40.6
2626
pip >= 10
2727
install_requires =
28+
zstd == 1.4.8.1
2829
attrs
2930
typing-extensions
3031

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
from pathlib import Path
2+
3+
from pytiled_parser import common_types, layer, tiled_object
4+
5+
EXPECTED = [
6+
layer.TileLayer(
7+
name="Tile Layer 1",
8+
opacity=1,
9+
visible=True,
10+
id=1,
11+
size=common_types.Size(8, 6),
12+
data=[
13+
[
14+
1,
15+
2,
16+
3,
17+
4,
18+
5,
19+
6,
20+
7,
21+
8,
22+
],
23+
[
24+
9,
25+
10,
26+
11,
27+
12,
28+
13,
29+
14,
30+
15,
31+
16,
32+
],
33+
[
34+
17,
35+
18,
36+
19,
37+
20,
38+
21,
39+
22,
40+
23,
41+
24,
42+
],
43+
[
44+
25,
45+
26,
46+
27,
47+
28,
48+
29,
49+
30,
50+
31,
51+
32,
52+
],
53+
[
54+
33,
55+
34,
56+
35,
57+
36,
58+
37,
59+
38,
60+
39,
61+
40,
62+
],
63+
[
64+
41,
65+
42,
66+
43,
67+
44,
68+
45,
69+
46,
70+
47,
71+
48,
72+
],
73+
],
74+
),
75+
layer.LayerGroup(
76+
name="Group 1",
77+
opacity=1,
78+
visible=True,
79+
id=4,
80+
layers=[
81+
layer.ObjectLayer(
82+
name="Object Layer 1",
83+
opacity=1,
84+
visible=True,
85+
id=2,
86+
draw_order="topdown",
87+
tiled_objects=[
88+
tiled_object.Rectangle(
89+
id=1,
90+
name="",
91+
rotation=0,
92+
size=common_types.Size(69.3333333333333, 52.6666666666667),
93+
coordinates=common_types.OrderedPair(46.3333333333333, 39),
94+
visible=True,
95+
type="",
96+
)
97+
],
98+
),
99+
],
100+
),
101+
layer.ImageLayer(
102+
name="Image Layer 1",
103+
opacity=1,
104+
visible=True,
105+
id=3,
106+
image=Path("../../images/tile_04.png"),
107+
transparent_color=common_types.Color(0, 0, 0, 255),
108+
),
109+
]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{ "compressionlevel":-1,
2+
"editorsettings":
3+
{
4+
"export":
5+
{
6+
"target":"."
7+
}
8+
},
9+
"height":6,
10+
"infinite":false,
11+
"layers":[
12+
{
13+
"compression":"zstd",
14+
"data":"KLUv\/SDAZQIAAgwSDBCw3gwwDFcLT4p0Cv\/c884531zzzDG\/3PLKKZ9c8sghf9zxxhlfXPHEET\/c8MIJH1zwwAH\/7r079+3as2O\/br069enSo0MBAA==",
15+
"encoding":"base64",
16+
"height":6,
17+
"id":1,
18+
"name":"Tile Layer 1",
19+
"opacity":1,
20+
"type":"tilelayer",
21+
"visible":true,
22+
"width":8,
23+
"x":0,
24+
"y":0
25+
},
26+
{
27+
"id":4,
28+
"layers":[
29+
{
30+
"draworder":"topdown",
31+
"id":2,
32+
"name":"Object Layer 1",
33+
"objects":[
34+
{
35+
"height":52.6666666666667,
36+
"id":1,
37+
"name":"",
38+
"rotation":0,
39+
"type":"",
40+
"visible":true,
41+
"width":69.3333333333333,
42+
"x":46.3333333333333,
43+
"y":39
44+
}],
45+
"opacity":1,
46+
"type":"objectgroup",
47+
"visible":true,
48+
"x":0,
49+
"y":0
50+
}],
51+
"name":"Group 1",
52+
"opacity":1,
53+
"type":"group",
54+
"visible":true,
55+
"x":0,
56+
"y":0
57+
},
58+
{
59+
"id":3,
60+
"image":"..\/..\/images\/tile_04.png",
61+
"name":"Image Layer 1",
62+
"opacity":1,
63+
"transparentcolor":"#000000",
64+
"type":"imagelayer",
65+
"visible":true,
66+
"x":0,
67+
"y":0
68+
}],
69+
"nextlayerid":5,
70+
"nextobjectid":3,
71+
"orientation":"orthogonal",
72+
"renderorder":"right-down",
73+
"tiledversion":"1.4.3",
74+
"tileheight":32,
75+
"tilesets":[
76+
{
77+
"firstgid":1,
78+
"source":"..\/all_layer_types\/tileset.json"
79+
}],
80+
"tilewidth":32,
81+
"type":"map",
82+
"version":1.4,
83+
"width":8
84+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{ "columns":8,
2+
"editorsettings":
3+
{
4+
"export":
5+
{
6+
"format":"",
7+
"target":"."
8+
}
9+
},
10+
"image":"..\/..\/images\/tmw_desert_spacing.png",
11+
"imageheight":199,
12+
"imagewidth":265,
13+
"margin":1,
14+
"name":"tile_set_image",
15+
"spacing":1,
16+
"tilecount":48,
17+
"tiledversion":"1.3.5",
18+
"tileheight":32,
19+
"tilewidth":32,
20+
"type":"tileset",
21+
"version":1.2
22+
}

tests/test_layer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
LAYER_TESTS / "b64",
1919
LAYER_TESTS / "b64_gzip",
2020
LAYER_TESTS / "b64_zlib",
21+
LAYER_TESTS / "b64_zstd",
2122
LAYER_TESTS / "no_layers",
2223
LAYER_TESTS / "infinite_map",
2324
LAYER_TESTS / "infinite_map_b64",

0 commit comments

Comments
 (0)