Skip to content

Commit 34a9897

Browse files
committed
Added support for Isometric tile layers
This implements part of mapeditor#26. It does not cover the positioning or transforming of objects.
1 parent 021b0e6 commit 34a9897

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

export_to_godot_tilemap.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ class GodotTilemapExporter {
8686
* Creates the Tilemap nodes. One Tilemap per one layer from Tiled.
8787
*/
8888
setTileMapsString() {
89+
const mode = this.map.orientation === TileMap.Isometric ? 1 : undefined
90+
8991
// noinspection JSUnresolvedVariable
9092
for (let i = 0; i < this.map.layerCount; ++i) {
9193

@@ -100,7 +102,7 @@ class GodotTilemapExporter {
100102
if (!ld.isEmpty) {
101103
const tileMapName = idx === 0 ? layer.name || "TileMap " + i : ld.tileset.name || "TileMap " + i + "_" + idx;
102104
this.mapLayerToTileset(layer.name, ld.tilesetID);
103-
this.tileMapsString += this.getTileMapTemplate(tileMapName, ld.tilesetID, ld.poolIntArrayString, layer, ld.parent);
105+
this.tileMapsString += this.getTileMapTemplate(tileMapName, mode, ld.tilesetID, ld.poolIntArrayString, layer, ld.parent);
104106
}
105107
}
106108
} else if (layer.isObjectLayer) {
@@ -446,7 +448,7 @@ ${this.tileMapsString}
446448
* Template for a tilemap node
447449
* @returns {string}
448450
*/
449-
getTileMapTemplate(tileMapName, tilesetID, poolIntArrayString, layer, parent = ".") {
451+
getTileMapTemplate(tileMapName, mode, tilesetID, poolIntArrayString, layer, parent = ".") {
450452
const tileWidth = layer.map.tileWidth === undefined ? 16 : layer.map.tileWidth;
451453
const tileHeight = layer.map.tileHeight === undefined ? 16 : layer.map.tileHeight;
452454
const groups = splitCommaSeparated(layer.property("groups"));
@@ -460,7 +462,8 @@ ${this.tileMapsString}
460462
tile_set: `ExtResource( ${tilesetID} )`,
461463
cell_size: `Vector2( ${tileWidth}, ${tileHeight} )`,
462464
cell_custom_transform: `Transform2D( 16, 0, 0, 16, 0, 0 )`,
463-
format: "1",
465+
format: 1,
466+
mode: mode,
464467
tile_data: `PoolIntArray( ${poolIntArrayString} )`,
465468
z_index: typeof zIndex === 'number' && !isNaN(zIndex) ? zIndex : undefined
466469
});

utils.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,7 @@ function splitCommaSeparated(str) {
5959
}
6060

6161
/**
62-
* Removes any undefined value with its key from an object
63-
* @param {object} obj
64-
*/
65-
function removeUndefined(obj) {
66-
Object.keys(obj).forEach(key => obj[key] === undefined && delete obj[key])
67-
}
68-
69-
70-
/**
71-
* Translates key values defining a godot scene node to the expected TSCN format output
62+
* Translates key values defining a Godot scene node to the expected TSCN format output.
7263
* Passed keys must be strings. Values can be arrays (e.g. for groups)
7364
*
7465
* @param {object} nodeProperties pair key/values for the "node" properties
@@ -80,14 +71,12 @@ function removeUndefined(obj) {
8071
* ```
8172
*/
8273
function stringifyNode(nodeProperties, contentProperties = {}) {
83-
// remove undefined values from objects
84-
removeUndefined(nodeProperties);
85-
removeUndefined(contentProperties);
86-
8774
let str = '\n';
8875
str += '[node';
8976
for (const [key, value] of Object.entries(nodeProperties)) {
90-
str += ' ' + this.stringifyKeyValue(key, value, true, false);
77+
if (value !== undefined) {
78+
str += ' ' + this.stringifyKeyValue(key, value, true, false);
79+
}
9180
}
9281
str += ']\n';
9382
for (const [key, value] of Object.entries(contentProperties)) {

0 commit comments

Comments
 (0)