Different tileset formats?

I’m working on an importer and wrote one years ago for the XML (csv and base64) format. Now I’m trying to implement JSON support and had a question about the tilesets. I get some maps that store tileset info in the map json file and others will write a TSX file with xml instead. Why is this? Is there a setting to embed the tileset data into the map versus a separate file? it just bugs me to see that while the XML map format was deprecated, it still uses xml for the TSX files.

1 Like

There is an option to embed tilesets, yes. This can be done manually by clicking the “embed tileset” button in the Tilesets panel in the Map Editor, or automatically with the “embed tilesets” export option. Embedding tilesets is generally not recommended, but some engines require it, and some people prefer it in cases where a tileset is only used by one map.

The XML tile storage is deprecated for maps, but it has never been deprecated and is a necessity for XML Tilesets. The <tile> element in Tilesets stores completely different data from the deprecated <tile> element in TileMap layers, the two kinds of <tile> elements are completely unrelated.

Also, note that there is also a Tileset JSON format (TSJ). On top of this, any external tileset in any format can be in any supported format. A TMX can have a TSJ tileset, a TMJ can have a TSX tileset, and any other combination of Tiled’s supported formats. It’s normal for an importer to support only a subset of these, but you should keep in mind that people do mix and match formats and that if possible, you should support this.

1 Like

Embedding tilesets is generally not recommended
Why is that?

I wasn’t aware of the embed option, that helps.

The main reason I’m trying to avoid XML altogether is due to the language (AGK), there is no native XML support. And while I’ve written a fairly efficient XML parser, it doesn’t compare to the speed of loading JSON with the native support. So when I learned the xml map was deprecated and json being supported I thought I’d rewrite the importer but got confused when my tilesets were still in XML. It seems like it would make sense if one exports a TMJ then tilesets would by default match it with TSJ.

1 Like

Embedding tilesets is not recommended because it leads to data duplication, you have to rewrite/reread all the tileset data for each map that uses that tileset, instead of just having one copy of it that you reuse. When reading tilesets at runtime, this will increase loading times (unless you also reread the Tileset from scratch every time even if it’s external, in which case embedded tilesets can be a slight speed-up). It also means that if you want to modify the tileset (e.g. to add Terrains, or change some custom properties), you’ll have to perform that change on every single embedded copy that needs that change, instead of being able to modify just the one external Tileset.

The XML format (TMX, TSX) is not deprecated. What’s deprecated is using XML-style storage of Tile Layer Data, which stores each data point within a layer as its own <tile> element.

It’s pretty normal for a Tiled loader/reader to only deal with one set of formats. If you’d rather stick to JSON for both Maps and Tilesets, that’s fine. I just mentioned it because your post seemed to assume that wasn’t possible. Ideally that’s something you should support, but it’s perfectly fine for a library to not be perfect xP

When you export a map with an external tileset, it still references that tileset, wherever it is. It doesn’t also re-export the tileset for you, that’s why your tileset is still TSX. If you want everything to be JSON, the easiest option is to resave your maps in that format instead of relying just on exports for it. TMJ/TSX supports all Tiled features, so you can use it as your working format as well.

That said, I do think Tiled needs an option to make it easier to replace the tileset with an exported version on export, especially if we ever get any export options for Tilesets (for which there’s at least one issue open, to remove terrain data on export).

1 Like