Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zstd compression support #152

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Then enable the plugin on the Project Settings.
* Both `.tmx` (XML) and `.json` formats for maps.
* Both `.tsx` (XML) and `.json` formats for tilesets.
* Support for Base64 encoded map.
* Support for layer compression, both `zlib` and `gzip` are supported.
* Support for layer compression, `zlib`, `gzip`, and `zstd` are supported.
* Object templates.
* Orthogonal, isometric, staggered, and hexagonal maps.
* Import visibility and opacity from layers.
Expand Down
20 changes: 13 additions & 7 deletions addons/vnen.tiled_importer/tiled_map_reader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1055,13 +1055,19 @@ func is_convex(vertices):
return true

# Decompress the data of the layer
# Compression argument is a string, either "gzip" or "zlib"
# Compression argument is a string, either "gzip", "zlib", or "zstd"
func decompress_layer_data(layer_data, compression, map_size):
if compression != "gzip" and compression != "zlib":
print_error("Unrecognized compression format: %s" % [compression])
return ERR_INVALID_DATA

var compression_type = File.COMPRESSION_DEFLATE if compression == "zlib" else File.COMPRESSION_GZIP
var compression_type = -1
match compression:
"zlib":
compression_type = File.COMPRESSION_DEFLATE
"gzip":
compression_type = File.COMPRESSION_GZIP
"zstd":
compression_type = File.COMPRESSION_ZSTD
_:
print_error("Unrecognized compression format: %s" % [compression])
return ERR_INVALID_DATA
var expected_size = int(map_size.x) * int(map_size.y) * 4
var raw_data = Marshalls.base64_to_raw(layer_data).decompress(expected_size, compression_type)

Expand Down Expand Up @@ -1236,7 +1242,7 @@ func validate_layer(layer):
print_error("Invalid data layer property.")
return ERR_INVALID_DATA
if "compression" in layer:
if layer.compression != "gzip" and layer.compression != "zlib":
if layer.compression != "gzip" and layer.compression != "zlib" and layer.compression != "zstd":
print_error("Invalid compression type.")
return ERR_INVALID_DATA
"imagelayer":
Expand Down