add zstd support and fix a bug

This commit is contained in:
Chris Cromer 2022-04-16 14:19:59 -04:00 committed by Gitea
parent b791768ec1
commit 73e4e442c3
3 changed files with 35 additions and 23 deletions

View File

@ -84,6 +84,11 @@ func get_import_options(preset):
"default_value": 1,
"property_hint": PROPERTY_HINT_LAYERS_2D_PHYSICS
},
{
"name": "collision_mask",
"default_value": 1,
"property_hint": PROPERTY_HINT_LAYERS_2D_PHYSICS
},
{
"name": "embed_internal_images",
"default_value": true if preset == PRESET_PIXEL_ART else false

View File

@ -231,6 +231,7 @@ func make_layer(layer, parent, root, data):
tilemap.cell_y_sort = true
tilemap.cell_tile_origin = TileMap.TILE_ORIGIN_BOTTOM_LEFT
tilemap.collision_layer = options.collision_layer
tilemap.collision_mask = options.collision_mask
tilemap.z_index = z_index
var offset = Vector2()
@ -280,7 +281,7 @@ func make_layer(layer, parent, root, data):
var gid = int_id & ~(FLIPPED_HORIZONTALLY_FLAG | FLIPPED_VERTICALLY_FLAG | FLIPPED_DIAGONALLY_FLAG)
var cell_x = cell_offset.x + chunk.x + (count % int(chunk.width))
var cell_y = cell_offset.y + chunk.y + int(count / chunk.width)
var cell_y = cell_offset.y + chunk.y + int(count / chunk.width) + 1
tilemap.set_cell(cell_x, cell_y, gid, flipped_h, flipped_v, flipped_d)
count += 1
@ -1047,13 +1048,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":
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 compression_type = File.COMPRESSION_DEFLATE if compression == "zlib" else File.COMPRESSION_GZIP
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)
@ -1220,7 +1227,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":