mapeditor/tiled

Do you want to work on this issue?

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

Signal: assetAboutToBeExported #3984

ninovanhooff posted onGitHub

Is your feature request related to a problem? Please describe. I've got an extension that listens to assetAboutToBeSaved to do last-minute corrections. Examples:

  • ensuring that polygon vertices are in counter-clockwise winding order
  • ensuring that vertices are snapped to the nearest pixel coordinate
  • apply rotation and offset

This works well, but the signal is not triggered when exporting. Thus, when changes are made since the last save and a user then hits export, an invalid file can be generated

Describe the solution you'd like A new signal assetAboutToBeExported that works the same way as assetAboutToBeSaved. For consistency perhaps assetExported as well

Describe alternatives you've considered

  • An objectEdited signal emitted whenever anything about an object changes. But there are usecases for layers, tilesets etc. too.
  • Doing the corrections to the map in the write function of a map format. Not allowed; the map is read-only.
  • Completely parsing the map and writing it to a custom format, doing checks and fixes along the way. Lots of work, plus the result is not visible to the user since it is only applied to the exported file; not the map
  • Doing the checks in the write function of a map format and returning an error message "please save before exporting" when issues are found. That seems a bit annoying when the issues could be fixed automatically.

I think making the map in write() not be read-only would be a good idea in general. There's no need for it to be read-only, since it's a copy anyway, modifying it would not modify the original map and should be harmless.

However, a signal that fires on export and which has the to-be-exported copy (also not read-only) as payload would still be useful, allowing last-second tweaks of maps that are saved using the built-in formats, without employing the hacky solution of using a proxy format. Having the original map would also work, though of course scripts would need to be mindful of which asset they have and what they're doing with it. If the original map is sent with this signal, then there should also be a signal for after the export, so that the changes can be undone if need be. If the export copy is sent, then there should be no need for an after-export signal.

posted by eishiya 10 months ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests