tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Add support for merging tilesets

Open stefanbeller opened this issue 12 years ago • 5 comments

It would be great if we could merge tilesets (remove unused tiles from all tilesets, store the remaining tiles into a single tileset and apply that to the map).

This project aims at doing that (or something very similar): https://github.com/falanxia/tileset_baker/wiki

(creating this to close the issue at the old bugtracker https://sourceforge.net/apps/mantisbt/tiled/view.php?id=36 )

stefanbeller avatar Mar 19 '12 13:03 stefanbeller

I have created a java tool to merge map tilesets: http://devnewton.bci.im/projects/tiledmerge/home

I made it for my own usage, but if someone need to use it, I can improve it.

ghost avatar Feb 19 '13 20:02 ghost

This would be great, some kind of "save as"/"export" that allow to save the TMX file and only one optimized tileset image. Or it can be other application like tmxrasterizer that optimize all tilesets and generate a new tmx and png image.

Not like tileset_baker but more like tmxOptimizer

rmarku avatar Jan 21 '15 00:01 rmarku

Given that there is now support of external tilesets, my requirement for this feature is to merge the embedded <tileset>s of multiple maps into an external one.

I am going to make some a for this, the logic will basically go like:

  • load in memory all embedded tilesets of the map files + the rotated/flipped version of each tile (hashes)
  • de-duplicate and create a list of replacements <old id> -> <new id> (with needed flags etc)
  • update the maps by running them the list of replacements
  • remove the embedded <tileset>s from the maps and replace with the new compact external one

gdm85 avatar Nov 12 '16 14:11 gdm85

My problem is that by copying tiles from another .tmx file, Tiled creates a copy of the tileset into the tmx file you're copying to, even if the exact same tileset was already there. I think the reason for this is because the tileset has another image source.

I created a console app to deduplicate tilesets to fix the above scenario: https://github.com/TomONeill/tmx-tileset-deduplicator/releases

Sorry, I'm a lazy developer, don't know C++ and felt it was too hard to add this into Tiled itself. But feel free to take inspiration from my project to add it to Tiled.

TomONeill avatar Aug 23 '23 19:08 TomONeill

@TomONeill Thanks for sharing your tool!

I think the reason for this is because the tileset has another image source.

Hmm, if they do then it's not the same tileset, which is why it gets duplicated. Tiled does not do a deep comparison of the tileset image to see if it is the same image.

I think in general for this scenario the fix would be to use external tilesets (.tsx files). Use the "Export Tileset" action to turn an embedded tileset into an external one or the "Replace Tileset" action (either of which you can find below the tileset view) to replace each duplicated tileset with the external one.

bjorn avatar Aug 23 '23 20:08 bjorn