@@ -4,6 +4,11 @@ import { getResPath, stringifyKeyValue, stringifyNode, splitCommaSeparated, getT
44class GodotTilemapExporter {
55
66 // noinspection DuplicatedCode
7+ /**
8+ * Constructs a new instance of the tilemap exporter
9+ * @param {TileMap } map the tilemap to export
10+ * @param {string } fileName path of the file the tilemap should be exported to
11+ */
712 constructor ( map , fileName ) {
813 this . map = map ;
914 this . fileName = fileName ;
@@ -62,11 +67,8 @@ class GodotTilemapExporter {
6267
6368 /**
6469 * Generate a string with all tilesets in the map.
65- * Godot allows only one tileset per tilemap so if you use more than one tileset per layer it's not going to work.
6670 * Godot supports several image textures per tileset but Tiled Editor doesn't.
67- * Tiled editor supports only one tile
68- * sprite image per tileset.
69- * @returns {string }
71+ * Tiled editor supports only one tile sprite image per tileset.
7072 */
7173 setTilesetsString ( ) {
7274
@@ -98,6 +100,12 @@ class GodotTilemapExporter {
98100 }
99101 }
100102
103+ /**
104+ * Handle exporting a single layer
105+ * @param {Layer } layer the target layer
106+ * @param {number } mode the layer mode
107+ * @param {string } layer_parent path of the parent of the layer
108+ */
101109 handleLayer ( layer , mode , layer_parent ) {
102110 // noinspection JSUnresolvedVariable
103111 if ( layer . isTileLayer ) {
@@ -246,6 +254,12 @@ class GodotTilemapExporter {
246254 }
247255 }
248256
257+ /**
258+ * Prepare properties for a Godot node
259+ * @param {TiledObjectProperties } object_props Properties from the layer
260+ * @param {TiledObjectProperties } set_props The base properties for the node
261+ * @returns {TiledObjectProperties } the merged property set for the node
262+ */
249263 merge_properties ( object_props , set_props ) {
250264 for ( const [ key , value ] of Object . entries ( object_props ) ) {
251265 if ( key . startsWith ( "godot:node:" ) ) {
@@ -255,7 +269,12 @@ class GodotTilemapExporter {
255269
256270 return set_props ;
257271 }
258-
272+
273+ /**
274+ * Prepare the meta properties for a Godot node
275+ * @param {TiledObjectProperties } object_props
276+ * @returns {object } the meta properties
277+ */
259278 meta_properties ( object_props ) {
260279 let results = { } ;
261280 for ( const [ key , value ] of Object . entries ( object_props ) ) {
@@ -276,11 +295,23 @@ class GodotTilemapExporter {
276295 }
277296
278297 /**
279- * Creates all the tiles coordinate for the current layer and picks the first tileset which is used.
280- * It's important to not use more than one tileset for a layer.
281- * Otherwise the tiles from the second layer are going to be displayed incorrectly as tiles form the first
282- * or with a wrong index leading to crash on export.
283- * @returns {{tilesetID: *, poolIntArrayString: string, layerName: *} }
298+ * @typedef {{
299+ * tileset: Tileset,
300+ * tilesetID: number?,
301+ * tilesetColumns: number,
302+ * layer: Layer,
303+ * isEmpty: boolean,
304+ * poolIntArrayString: string,
305+ * parent: string
306+ * }} LayerData
307+ */
308+
309+ /**
310+ * Creates all the tiles coordinates for a layer.
311+ * Each element in the retuned array corresponds to the tile coordinates for each of
312+ * the tilesets used in the layer.
313+ * @param {TileLayer } layer the target layer
314+ * @returns {LayerData[] } the data about the tilesets used in the target layer
284315 */
285316 getLayerData ( layer ) {
286317 // noinspection JSUnresolvedVariable
@@ -370,10 +401,20 @@ class GodotTilemapExporter {
370401 return tilesetList ;
371402 }
372403
404+ /**
405+ * Find the id of a tileset by its name
406+ * @param {Tileset } tileset The tileset to find the id of
407+ * @returns {string|undefined } the id of the tileset if found, undefined otherwise
408+ */
373409 getTilesetIDByTileset ( tileset ) {
374410 return this . tilesetsIndex . get ( tileset . name ) ;
375411 }
376412
413+ /**
414+ * Calculate the second parameter for the given cell
415+ * @param {cell } cell the target cell
416+ * @returns {number } the second parameter
417+ */
377418 getSecondParam ( cell ) {
378419 /**
379420 * no rotation or flips
@@ -523,6 +564,12 @@ ${this.tileMapsString}
523564
524565 /**
525566 * Template for a tilemap node
567+ * @param {string } tileMapName
568+ * @param {number } mode
569+ * @param {number } tilesetID
570+ * @param {string } poolIntArrayString
571+ * @param {Layer } layer
572+ * @param {string } parent
526573 * @returns {string }
527574 */
528575 getTileMapTemplate ( tileMapName , mode , tilesetID , poolIntArrayString , layer , parent = "." ) {
@@ -563,9 +610,16 @@ const customTileMapFormat = {
563610 name : "Godot Tilemap format" ,
564611 extension : "tscn" ,
565612
613+ /**
614+ * Map exporter function
615+ * @param {TileMap } map the map to export
616+ * @param {string } fileName path of the file where to export the map
617+ * @returns {undefined }
618+ */
566619 write : function ( map , fileName ) {
567620 const exporter = new GodotTilemapExporter ( map , fileName ) ;
568621 exporter . write ( ) ;
622+ return undefined ;
569623 }
570624} ;
571625
0 commit comments