From 7dfa200738293c9a03d522102504c25de28895e2 Mon Sep 17 00:00:00 2001 From: Sarah Hart Date: Sat, 13 Jun 2020 21:44:38 -0500 Subject: [PATCH 1/3] Take into account tile spacing (padding between tiles) --- export_to_godot_tilemap.js | 2 +- export_to_godot_tileset.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/export_to_godot_tilemap.js b/export_to_godot_tilemap.js index 23b2344..eb8ad98 100644 --- a/export_to_godot_tilemap.js +++ b/export_to_godot_tilemap.js @@ -193,7 +193,7 @@ class GodotTilemapExporter { **/ getTilesetColumns(tileset) { // noinspection JSUnresolvedVariable - return Math.floor(tileset.imageWidth / tileset.tileWidth); + return Math.ceil(tileset.imageWidth / (tileset.tileWidth + tileset.tileSpacing)); } /** diff --git a/export_to_godot_tileset.js b/export_to_godot_tileset.js index 421e867..6a5b140 100644 --- a/export_to_godot_tileset.js +++ b/export_to_godot_tileset.js @@ -121,7 +121,7 @@ ${this.shapesResources}[resource] 0/tile_mode = 2 0/autotile/icon_coordinate = Vector2( 0, 0 ) 0/autotile/tile_size = Vector2( ${this.tileset.tileWidth}, ${this.tileset.tileHeight} ) -0/autotile/spacing = 0 +0/autotile/spacing = ${this.tileset.tileSpacing} 0/autotile/occluder_map = [ ] 0/autotile/navpoly_map = [ ] 0/autotile/priority_map = [ ] From 28c28109e7d73e9a336839e6a32065a2d0aff9fd Mon Sep 17 00:00:00 2001 From: Sarah Hart Date: Sun, 14 Jun 2020 08:33:04 -0500 Subject: [PATCH 2/3] Adjust column count calculation and take tileset margin into account. --- export_to_godot_tilemap.js | 13 ++++++++++--- export_to_godot_tileset.js | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/export_to_godot_tilemap.js b/export_to_godot_tilemap.js index eb8ad98..611d7d2 100644 --- a/export_to_godot_tilemap.js +++ b/export_to_godot_tilemap.js @@ -188,12 +188,19 @@ class GodotTilemapExporter { /** * Tileset should expose columns ... but didn't at the moment so we - * calculate them base on the image width and tileWidth - * return {number} + * calculate them base on the image width and tileWidth. + * Takes into account margin (extra space around the image edges) and + * tile spacing (padding between individual tiles). + * @returns {number} **/ getTilesetColumns(tileset) { // noinspection JSUnresolvedVariable - return Math.ceil(tileset.imageWidth / (tileset.tileWidth + tileset.tileSpacing)); + const imageWidth = tileset.imageWidth + tileset.tileSpacing - (tileset.margin * 2) + const tileWidth = tileset.tileWidth + tileset.tileSpacing + const calculatedColumnCount = imageWidth / tileWidth + // Tiled ignores "partial" tiles (extra unaccounted for pixels in the image), + // so we need to return as Math.floor to avoid throwing off the tile indices. + return Math.floor(calculatedColumnCount); } /** diff --git a/export_to_godot_tileset.js b/export_to_godot_tileset.js index 6a5b140..cfa72a5 100644 --- a/export_to_godot_tileset.js +++ b/export_to_godot_tileset.js @@ -117,7 +117,7 @@ ${this.shapesResources}[resource] 0/texture = ExtResource( 1 ) 0/tex_offset = Vector2( 0, 0 ) 0/modulate = Color( 1, 1, 1, 1 ) -0/region = Rect2( 0, 0, ${this.tileset.imageWidth}, ${this.tileset.imageHeight} ) +0/region = Rect2( ${this.tileset.margin}, ${this.tileset.margin}, ${this.tileset.imageWidth}, ${this.tileset.imageHeight} ) 0/tile_mode = 2 0/autotile/icon_coordinate = Vector2( 0, 0 ) 0/autotile/tile_size = Vector2( ${this.tileset.tileWidth}, ${this.tileset.tileHeight} ) From 149923ca1a9e595b6714a7fcc82ee5acd32d9cf3 Mon Sep 17 00:00:00 2001 From: Sarah Hart Date: Sun, 14 Jun 2020 18:58:15 -0500 Subject: [PATCH 3/3] Adjust margin handling. --- export_to_godot_tilemap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/export_to_godot_tilemap.js b/export_to_godot_tilemap.js index 611d7d2..164cbdb 100644 --- a/export_to_godot_tilemap.js +++ b/export_to_godot_tilemap.js @@ -195,7 +195,7 @@ class GodotTilemapExporter { **/ getTilesetColumns(tileset) { // noinspection JSUnresolvedVariable - const imageWidth = tileset.imageWidth + tileset.tileSpacing - (tileset.margin * 2) + const imageWidth = tileset.imageWidth + tileset.tileSpacing - tileset.margin const tileWidth = tileset.tileWidth + tileset.tileSpacing const calculatedColumnCount = imageWidth / tileWidth // Tiled ignores "partial" tiles (extra unaccounted for pixels in the image),