Skip to content

Commit d966024

Browse files
committed
Add missing getTilesetColumns method
1 parent 6c261c9 commit d966024

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

export_to_godot_tilemap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class GodotTilemapExporter {
181181
/**
182182
* Tileset should expose columns ... but didn't at the moment so we
183183
* calculate them base on the image width and tileWidth
184-
* return {String}
184+
* return {number}
185185
**/
186186
getTilesetColumns(tileset) {
187187
// noinspection JSUnresolvedVariable

export_to_godot_tileset.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class GodotTilesetExporter {
4242

4343
let tile = tiles[index];
4444

45+
const tilesetColumns = this.getTilesetColumns();
46+
if ((autotileCoordinates.x + 1) > tilesetColumns) {
47+
autotileCoordinates.x = 0;
48+
autotileCoordinates.y += 1;
49+
}
50+
4551
// noinspection JSUnresolvedVariable
4652
if (tile.objectGroup !== null) {
4753

@@ -64,9 +70,6 @@ class GodotTilesetExporter {
6470
}
6571

6672
autotileCoordinates.x += 1;
67-
if ((index) < this.tileset.columns) {
68-
autotileCoordinates.y += 1;
69-
}
7073

7174
}
7275

@@ -96,6 +99,16 @@ class GodotTilesetExporter {
9699
);
97100
}
98101

102+
/**
103+
* Tileset should expose columns ... but didn't at the moment so we
104+
* calculate them base on the image width and tileWidth
105+
* return {number}
106+
**/
107+
getTilesetColumns() {
108+
// noinspection JSUnresolvedVariable
109+
return Math.floor(this.tileset.imageWidth / this.tileset.tileWidth);
110+
}
111+
99112
getTilesetTemplate() {
100113
// noinspection JSUnresolvedVariable
101114
return `[gd_resource type="TileSet" load_steps=3 format=2]

0 commit comments

Comments
 (0)