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

tiled.registerMapFormat - source map missing value of fileName #4172

Open
justgook opened this issue Feb 10, 2025 · 2 comments
Open

tiled.registerMapFormat - source map missing value of fileName #4172

justgook opened this issue Feb 10, 2025 · 2 comments
Labels
bug Broken behavior.

Comments

@justgook
Copy link

Describe the bug
When i create new map format i need access to source map file name (to find word where map belongs, as example)

To Reproduce
register new map format:

tiled.registerMapFormat("world-lut", {
  name: "LUT World(s) image",
  extension: "png *.bin",
  write: function(p_map, p_fileName) {
    console.log(`the fileName: "${p_map.fileName}"`, typeof (p_map.fileName))
  }
})

export, use it to export map - and look at console output:

qml: the fileName: "" string

Expected behavior
in console you see

qml: the fileName: "path_to_map_file.tmj" string

Specifications:

  • OS: MacOs
  • Tiled Version: 1.11.2
@justgook justgook added the bug Broken behavior. label Feb 10, 2025
@eishiya
Copy link
Contributor

eishiya commented Feb 10, 2025

I believe this happens for the same reason that the Asset you get in write() is read-only: it may be a copy (e.g. if any export settings are applied) that's not connected to the original file. Because of this, it would often not make sense for it to have a fileName.

Although in theory the original's map file path should never be relevant when writing and only the provided path should be used, in practice it is occasionally useful (to e.g. grab the relative tileset path, get the World for the original map, get some external config in the original directory, etc), so it would be nice to perhaps get a third parameter to write() that has the original map's path, if there is one.

@justgook
Copy link
Author

justgook commented Feb 11, 2025

then why that property fileName exist, and is empty?

just example of my use case - i have some custom map exporter - that requires wold info to safe map. im using patter to collect all maps into world. in same time there could be loaded multiple worlds in Tiled (app) - so i need to find out to what world map that im exporting belongs to - and only way (what i found) is to go over all worlds, use allMaps(): WorldMapEntry[] method, and then based on map path compare with all paths in world.

and based on containsMap code it do exactly same and compares fileName field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Broken behavior.
Projects
None yet
Development

No branches or pull requests

2 participants