Adding custom tags on TMX

(Luciano Ciccariello) #1

I am developing a custom map editor for my specifics needs and I need to write custom tags into the TMX file. The problem is that Tiled deletes those custom tags on saving, nullifying my map editor changes.

I know that I can use Properties, but it is not enough to store big objects.
There is some best practice to do what I need? Am I missing something from documentation?

(Thorbjørn Lindeijer) #2

Since Tiled does not use an XML DOM to keep the file in memory, it has no way to keep custom tags intact. The only way to get custom data to be loaded and saved by Tiled is to use the custom property system.

But why are the properties not enough to store big objects? If you need more structured data, you could always store JSON or (escaped) XML as the property value. Note that Tiled also supports multi-line string properties.

(Luciano Ciccariello) #3

I tried using JSON too but it does not save custom tags too.

Yes, my needs is to store additional structured data. I can add a support file with my additional data, but I wished to have everything on tmx/tsx files.

(Thorbjørn Lindeijer) #4

It’s the same problem as with XML. Tiled does not keep the JSON document in-memory but rather has its own data structures, so there is no place to store arbitrary JSON data apart from the custom properties.

Even if Tiled would keep the original XML or JSON documents in-memory, I’m not sure how it could keep unknown sections intact in general. If you have some solution in mind for this you could always try patching it in. It’s probably easier with JSON than with XML, but either way I think you’d have to litter all existing data structures with custom JSON / XML data holders or handles.

(Darkhog) #5

Dunno if it would be a valid solution for you, but how about having map as XML, then in either map or object properties having a string property that would contain JSON data? It’s a hack, yes, but it should work. All you’d need then is to extract the string property containing JSON, unescape it from any characters that you might’ve escape to make it possible to store in XML and process as a JSON.

Here you have some of the common characters that you need to escape in XML:

//edit: To further clarify, I’m talking about something like this:

<property name="JSON" value="{CatLikesPies: true; NameOfYourFavFood:&quot;french fries&quot;;}"/>

(Thorbjørn Lindeijer) #6

It’s a perfectly valid approach.

There is no need to escape anything, because Tiled will already do any needed escaping when writing custom property values (as appropriate for JSON, XML or Lua).

(Darkhog) #7

Yes, but the OP had stated that he’s also use his custom tools and in that case he’d need to do his own escaping.