Parse entity layer in ldtk script
parent
62703c0317
commit
87c415d52c
|
@ -19,6 +19,10 @@ ENUMIDS_TILETYPE_MAPPING = {
|
||||||
'Water': 2
|
'Water': 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ENTID_MAPPING = {
|
||||||
|
'Player': 1
|
||||||
|
}
|
||||||
|
|
||||||
# First go to tilesets and find Simple_tiles identifier, then find enumTags to identifier which tile type is what tileid
|
# First go to tilesets and find Simple_tiles identifier, then find enumTags to identifier which tile type is what tileid
|
||||||
ids_tiletype_map = {}
|
ids_tiletype_map = {}
|
||||||
tileset_defs = level_pack_data["defs"]["tilesets"]
|
tileset_defs = level_pack_data["defs"]["tilesets"]
|
||||||
|
@ -57,11 +61,12 @@ with open(converted_filename, 'wb+') as out_file:
|
||||||
|
|
||||||
|
|
||||||
level_layout = {}
|
level_layout = {}
|
||||||
|
entity_layout = {}
|
||||||
for layer in level['layerInstances']:
|
for layer in level['layerInstances']:
|
||||||
if layer["__identifier"] != "Tiles":
|
if layer["__identifier"] == "Tiles":
|
||||||
continue
|
|
||||||
|
|
||||||
level_layout = layer
|
level_layout = layer
|
||||||
|
elif layer["__identifier"] == "Entities":
|
||||||
|
entity_layout = layer
|
||||||
|
|
||||||
# Dimensions of each level is obtained via __cWid and __cHei. Get the __gridSize as well
|
# Dimensions of each level is obtained via __cWid and __cHei. Get the __gridSize as well
|
||||||
width = level_layout["__cWid"]
|
width = level_layout["__cWid"]
|
||||||
|
@ -74,6 +79,11 @@ with open(converted_filename, 'wb+') as out_file:
|
||||||
for tile in level_layout["gridTiles"]:
|
for tile in level_layout["gridTiles"]:
|
||||||
tiles_info[tile["d"][0]][0] = ids_tiletype_map[tile["t"]]
|
tiles_info[tile["d"][0]][0] = ids_tiletype_map[tile["t"]]
|
||||||
|
|
||||||
|
for ent in entity_layout["entityInstances"]:
|
||||||
|
if ent["__identifier"] in ENTID_MAPPING:
|
||||||
|
x,y = ent["__grid"]
|
||||||
|
tiles_info[y*width + x][1] = ENTID_MAPPING[ent["__identifier"]]
|
||||||
|
|
||||||
out_file.write(struct.pack("32s2H", level_name.encode('utf-8'), width, height))
|
out_file.write(struct.pack("32s2H", level_name.encode('utf-8'), width, height))
|
||||||
for tile in tiles_info:
|
for tile in tiles_info:
|
||||||
out_file.write(struct.pack("3Bx", *tile))
|
out_file.write(struct.pack("3Bx", *tile))
|
||||||
|
|
Loading…
Reference in New Issue