mapeditor/tiled

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Add map.fileName in tiled.registerMapFormat -> write #3911

cupen posted onGitHub

Is your feature request related to a problem? Please describe. Sometimes I need to get the file name of tiledmap when export.

Describe the solution you'd like

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

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

Could you please provide some examples of scenarios where you need the file name? I also think it would be nice to have the source filename, but actual examples are more likely to get this feature implemented.

My own use case is to keep relative paths the same between the source directory and the destination directory. For example, if my working files are in wip and wip/map.tmx points to wip/tilesets/tiles.tsx (with a relative path that's just tilesets/tiles.tsx), I'd want to be able to determine the relative path and write the tileset reference in my custom export as tilesets/tiles.something, instead of writing a reference to the original tileset.

As I mentioned on the forum, I'd be happy to get a sourceFileName as a third parameter to write(), I don't think map.fileName is strictly necessary. The map you get in write() is a copy of the original map, so it having a filename would be misleading.

P.S. You don't have to give your custom format a unique extension, you can have it be json if you want. Using a unique extension can be helpful with filtering the list of files in the file picker, though.

posted by eishiya about 1 year ago

@eishiya Hello, Thank you for your help on the forum, and sorry for delay.

My usecase is similar to yours, but mainly focusing on multi-person cooperation. For examples, put the source file name into the exported file, for tracking that what it from. Also push a log to CI (webhook) for tell someone the .tmx file is exported. ...

BTW, sorry I already mistook map for the map. As a user, I don't care it's the map or not. It's just a read-only map for me,
no matter fileName or sourceFileName, also no matter if the property name is same, it's still a read-only map for me. :D So I would like the short one. :smile:

p.s. Yes, I get it. My custom format is a json object with different data structures, it's smaller and readable for difftools with version control (git, svn). Finally it'will be converted into a binary file. :D

posted by cupen about 1 year ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests