Skip to content

Commit 7ab4ab1

Browse files
authored
Allow setting per-tile z index in tileset (#44)
1 parent c336ea5 commit 7ab4ab1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ if Input.is_action_just_pressed("reload_scene"):
108108
```
109109
Don't forget to add key/mouse/controller mapping for the "reload_scene" action ;)
110110

111-
### Tile layer z index
111+
### Z index for tile layer and single tile
112112

113-
Can set the z-index for the tilelayer by adding a custom property `z_index`, this will set the z-index of the tile layer in the scene file.
113+
You can set the z-index for the whole tilelayer by adding a custom property `z_index`. This will set the z-index of the tile layer in the scene file.
114+
115+
You can also set the z-index for tiles in a tileset by adding a custom float property `godot:z_index` to the tile. This is stored in the exported tileset file.
114116

115117
### Tileset objects for collisions & navigation
116118

export_to_godot_tileset.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class GodotTilesetExporter {
1414
this.shapesResources = "";
1515
this.shapes = "";
1616
this.navpolyMap = [];
17+
this.zIndexMap = [];
1718
this.firstShapeID = "0";
1819
};
1920

@@ -52,6 +53,13 @@ class GodotTilesetExporter {
5253
autotileCoordinates.y += 1;
5354
}
5455

56+
const zIndex = tile.property('godot:z_index');
57+
if (zIndex !== undefined) {
58+
const zIndexFloat = parseFloat(zIndex);
59+
if (isNaN(zIndexFloat)) tiled.warn(`Skipping export of godot:z_index on tile with id ${tile.id} because it can not be converted to float. value: ${zIndex}`);
60+
else this.zIndexMap.push([autotileCoordinates.x, autotileCoordinates.y, zIndexFloat]);
61+
}
62+
5563
// noinspection JSUnresolvedVariable
5664
if (tile.objectGroup !== null) {
5765

@@ -60,7 +68,6 @@ class GodotTilesetExporter {
6068

6169
// noinspection JSUnresolvedVariable
6270
if (tileObjects.length > 0) {
63-
6471
// noinspection JSUnresolvedVariable
6572
for (let oIndex = 0; oIndex < tileObjects.length; oIndex++) {
6673

@@ -79,7 +86,6 @@ class GodotTilesetExporter {
7986
}
8087

8188
autotileCoordinates.x += 1;
82-
8389
}
8490

8591
this.shapes = this.shapes.replace(/,\s*$/, "");
@@ -141,7 +147,7 @@ ${this.shapesResources}[resource]
141147
0/autotile/occluder_map = [ ]
142148
0/autotile/navpoly_map = [ ${this.navpolyMap.join(', ')} ]
143149
0/autotile/priority_map = [ ]
144-
0/autotile/z_index_map = [ ]
150+
0/autotile/z_index_map = [ ${this.zIndexMap.map(item => `Vector3( ${item.join(', ')} )`).join(', ')} ]
145151
0/occluder_offset = Vector2( 0, 0 )
146152
0/navigation_offset = Vector2( 0, 0 )
147153
0/shape_offset = Vector2( 0, 0 )

0 commit comments

Comments
 (0)