[Scripting API] It's hard to export several tiledmaps

I need to export some tiledmap to different files, but after pressing ctrl+e, the selected file location is global one. It results in exporting different tiledmaps to the same file location after pressing Ctrl+E. it this a bug?

BTW: I can’t get the file name of tiledmap in tiled.registerMapFormat.

tiled.registerMapFormat("Custom Export", {
    name: "Custom Export",
    extension: "json2",

    write: function(map, fileName) {
        tiled.log("map.fileName = " + map.fileName)
    }
});

1 Like

I don’t understand the first part of your post. Are you perhaps clicking “Export” (which repeats the last export if possible) when you mean to use “Export As” to set up a new export?

The map that’s passed into write() is a (currently read-only) clone that doesn’t have a fileName, Undo/Redo, etc, this is intentional. You’re supposed to only care about the destination filename given to you.
Of course, in practice, it is useful to know the current location sometimes, so it would be nice if there was a sourceFileName parameter to write() as well.

2 Likes

About my first post, I meaning that I have multiple .tmx files. The map[1-10].tmx which will be export to map[1-10].json, respectively.

Yes, as you say. It repeats the last export.
My workflow is:

  1. edit map1 then export it to map1.json.
  2. edit map2 then export it to map2.json.
  3. edit map1 then export it to map1.json.
  4. edit map2 then export it to map2.json.
  5. edit map1 then export it to map1.json.

So, I have to choose the filename each time. Maybe it could be repeats the last export respectively for each .tmx file?

1 Like

Oh, no, I meant you have to do that if you need to export the same map to multiple files (e.g. multiple formats or something). The last export name is saved for each map IIRC, so you should be able to

  1. edit map1 then export to map1.json
  2. edit map2 then export to map2.json
  3. edit map1 then export, and it should automatically export to map1.json
  4. edit map2 then export, and it should automatically export to map2.json

If that’s not the behaviour you’re seeing, then you’ve probably found a bug, or I’m misremembering (but it’d be pretty silly for it to work any other way).

2 Likes

OK, I’ll try again. Maybe something went wrong, and maybe I’m wrong.

1 Like

Oh, I try to reproduce it with my colleague.
Yes, your are right. Sorry for my mistake.

1 Like

BTW, I’ll issue a new feature request for the map.fileName with tiled.registerMapFormat.

1 Like