feature/tilesets #9
@ -84,6 +84,11 @@ func get_import_options(preset):
|
|||||||
"default_value": 1,
|
"default_value": 1,
|
||||||
"property_hint": PROPERTY_HINT_LAYERS_2D_PHYSICS
|
"property_hint": PROPERTY_HINT_LAYERS_2D_PHYSICS
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "collision_mask",
|
||||||
|
"default_value": 1,
|
||||||
|
"property_hint": PROPERTY_HINT_LAYERS_2D_PHYSICS
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "embed_internal_images",
|
"name": "embed_internal_images",
|
||||||
"default_value": true if preset == PRESET_PIXEL_ART else false
|
"default_value": true if preset == PRESET_PIXEL_ART else false
|
||||||
|
@ -211,12 +211,12 @@ func make_layer(layer, parent, root, data):
|
|||||||
|
|
||||||
var opacity = float(layer.opacity) if "opacity" in layer else 1.0
|
var opacity = float(layer.opacity) if "opacity" in layer else 1.0
|
||||||
var visible = bool(layer.visible) if "visible" in layer else true
|
var visible = bool(layer.visible) if "visible" in layer else true
|
||||||
|
|
||||||
var z_index = 0
|
var z_index = 0
|
||||||
|
|
||||||
if "properties" in layer and "z_index" in layer.properties:
|
if "properties" in layer and "z_index" in layer.properties:
|
||||||
z_index = layer.properties.z_index
|
z_index = layer.properties.z_index
|
||||||
|
|
||||||
if layer.type == "tilelayer":
|
if layer.type == "tilelayer":
|
||||||
var layer_size = Vector2(int(layer.width), int(layer.height))
|
var layer_size = Vector2(int(layer.width), int(layer.height))
|
||||||
var tilemap = TileMap.new()
|
var tilemap = TileMap.new()
|
||||||
@ -231,6 +231,7 @@ func make_layer(layer, parent, root, data):
|
|||||||
tilemap.cell_y_sort = true
|
tilemap.cell_y_sort = true
|
||||||
tilemap.cell_tile_origin = TileMap.TILE_ORIGIN_BOTTOM_LEFT
|
tilemap.cell_tile_origin = TileMap.TILE_ORIGIN_BOTTOM_LEFT
|
||||||
tilemap.collision_layer = options.collision_layer
|
tilemap.collision_layer = options.collision_layer
|
||||||
|
tilemap.collision_mask = options.collision_mask
|
||||||
tilemap.z_index = z_index
|
tilemap.z_index = z_index
|
||||||
|
|
||||||
var offset = Vector2()
|
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 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_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)
|
tilemap.set_cell(cell_x, cell_y, gid, flipped_h, flipped_v, flipped_d)
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
@ -702,26 +703,26 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
var column = 0
|
var column = 0
|
||||||
|
|
||||||
# Needed to look up textures for animations
|
# Needed to look up textures for animations
|
||||||
var tileRegions = []
|
var tileRegions = []
|
||||||
while i < tilecount:
|
while i < tilecount:
|
||||||
var tilepos = Vector2(x, y)
|
var tilepos = Vector2(x, y)
|
||||||
var region = Rect2(tilepos, tilesize)
|
var region = Rect2(tilepos, tilesize)
|
||||||
|
|
||||||
tileRegions.push_back(region)
|
tileRegions.push_back(region)
|
||||||
|
|
||||||
column += 1
|
column += 1
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
x += int(tilesize.x) + spacing
|
x += int(tilesize.x) + spacing
|
||||||
if (columns > 0 and column >= columns) or x >= int(imagesize.x) - margin or (x + int(tilesize.x)) > int(imagesize.x):
|
if (columns > 0 and column >= columns) or x >= int(imagesize.x) - margin or (x + int(tilesize.x)) > int(imagesize.x):
|
||||||
x = margin
|
x = margin
|
||||||
y += int(tilesize.y) + spacing
|
y += int(tilesize.y) + spacing
|
||||||
column = 0
|
column = 0
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
while i < tilecount:
|
while i < tilecount:
|
||||||
var region = tileRegions[i]
|
var region = tileRegions[i]
|
||||||
|
|
||||||
@ -778,7 +779,7 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
result.tile_set_texture(gid, image)
|
result.tile_set_texture(gid, image)
|
||||||
if options.apply_offset:
|
if options.apply_offset:
|
||||||
result.tile_set_texture_offset(gid, Vector2(0, -image.get_height()))
|
result.tile_set_texture_offset(gid, Vector2(0, -image.get_height()))
|
||||||
|
|
||||||
if "tiles" in ts and rel_id in ts.tiles and "objectgroup" in ts.tiles[rel_id] \
|
if "tiles" in ts and rel_id in ts.tiles and "objectgroup" in ts.tiles[rel_id] \
|
||||||
and "objects" in ts.tiles[rel_id].objectgroup:
|
and "objects" in ts.tiles[rel_id].objectgroup:
|
||||||
for object in ts.tiles[rel_id].objectgroup.objects:
|
for object in ts.tiles[rel_id].objectgroup.objects:
|
||||||
@ -803,10 +804,10 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
result.tile_set_occluder_offset(gid, offset)
|
result.tile_set_occluder_offset(gid, offset)
|
||||||
else:
|
else:
|
||||||
result.tile_add_shape(gid, shape, Transform2D(0, offset), object.type == "one-way")
|
result.tile_add_shape(gid, shape, Transform2D(0, offset), object.type == "one-way")
|
||||||
|
|
||||||
if "properties" in ts and "custom_material" in ts.properties:
|
if "properties" in ts and "custom_material" in ts.properties:
|
||||||
result.tile_set_material(gid, load(ts.properties.custom_material))
|
result.tile_set_material(gid, load(ts.properties.custom_material))
|
||||||
|
|
||||||
if options.custom_properties and options.tile_metadata and "tileproperties" in ts \
|
if options.custom_properties and options.tile_metadata and "tileproperties" in ts \
|
||||||
and "tilepropertytypes" in ts and rel_id in ts.tileproperties and rel_id in ts.tilepropertytypes:
|
and "tilepropertytypes" in ts and rel_id in ts.tileproperties and rel_id in ts.tilepropertytypes:
|
||||||
tile_meta[gid] = get_custom_properties(ts.tileproperties[rel_id], ts.tilepropertytypes[rel_id])
|
tile_meta[gid] = get_custom_properties(ts.tileproperties[rel_id], ts.tilepropertytypes[rel_id])
|
||||||
@ -815,7 +816,7 @@ func build_tileset_for_scene(tilesets, source_path, options):
|
|||||||
if property in ts.tiles[rel_id]:
|
if property in ts.tiles[rel_id]:
|
||||||
if not gid in tile_meta: tile_meta[gid] = {}
|
if not gid in tile_meta: tile_meta[gid] = {}
|
||||||
tile_meta[gid][property] = ts.tiles[rel_id][property]
|
tile_meta[gid][property] = ts.tiles[rel_id][property]
|
||||||
|
|
||||||
gid += 1
|
gid += 1
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
@ -1047,13 +1048,19 @@ func is_convex(vertices):
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
# Decompress the data of the layer
|
# 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):
|
func decompress_layer_data(layer_data, compression, map_size):
|
||||||
if compression != "gzip" and compression != "zlib":
|
var compression_type = -1
|
||||||
print_error("Unrecognized compression format: %s" % [compression])
|
match compression:
|
||||||
return ERR_INVALID_DATA
|
"zlib":
|
||||||
|
compression_type = File.COMPRESSION_DEFLATE
|
||||||
var compression_type = File.COMPRESSION_DEFLATE if compression == "zlib" else File.COMPRESSION_GZIP
|
"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 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)
|
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.")
|
print_error("Invalid data layer property.")
|
||||||
return ERR_INVALID_DATA
|
return ERR_INVALID_DATA
|
||||||
if "compression" in layer:
|
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.")
|
print_error("Invalid compression type.")
|
||||||
return ERR_INVALID_DATA
|
return ERR_INVALID_DATA
|
||||||
"imagelayer":
|
"imagelayer":
|
||||||
|
@ -247,7 +247,7 @@ func parse_tile_data(parser):
|
|||||||
var prop_data = parse_properties(parser)
|
var prop_data = parse_properties(parser)
|
||||||
data["properties"] = prop_data.properties
|
data["properties"] = prop_data.properties
|
||||||
data["propertytypes"] = prop_data.propertytypes
|
data["propertytypes"] = prop_data.propertytypes
|
||||||
|
|
||||||
elif parser.get_node_name() == "animation":
|
elif parser.get_node_name() == "animation":
|
||||||
var frame_list = []
|
var frame_list = []
|
||||||
var err2 = parser.read()
|
var err2 = parser.read()
|
||||||
@ -265,7 +265,7 @@ func parse_tile_data(parser):
|
|||||||
if parser.get_node_name() == "animation":
|
if parser.get_node_name() == "animation":
|
||||||
break
|
break
|
||||||
err2 = parser.read()
|
err2 = parser.read()
|
||||||
|
|
||||||
data["animation"] = frame_list
|
data["animation"] = frame_list
|
||||||
|
|
||||||
err = parser.read()
|
err = parser.read()
|
||||||
|
Loading…
Reference in New Issue
Block a user