mapeditor/tiled

Do you want to work on this issue?

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

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

justgook posted onGitHub

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

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.

posted by eishiya 3 months ago

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

posted by justgook 2 months ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests