Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cupen opened this issue Mar 19, 2024 · 2 comments
Open

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

cupen opened this issue Mar 19, 2024 · 2 comments
Labels
feature It's a feature, not a bug.

Comments

@cupen
Copy link

cupen commented Mar 19, 2024

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)
    }
});
@cupen cupen added the feature It's a feature, not a bug. label Mar 19, 2024
@eishiya
Copy link
Contributor

eishiya commented Mar 19, 2024

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.

@cupen
Copy link
Author

cupen commented Mar 23, 2024

@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. 😄

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature It's a feature, not a bug.
Projects
None yet
Development

No branches or pull requests

2 participants