Skip to content

Commit 09ac799

Browse files
authored
Persist tile custom data to Tiled custom properties (#989)
* adding tile custom data to tiled export custom properties * match style
1 parent c9bdfe8 commit 09ac799

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/electron.renderer/exporter/Tiled.hx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package exporter;
22

3+
import haxe.Json;
34
import ldtk.Json;
45

56

@@ -146,6 +147,44 @@ class Tiled extends Exporter {
146147
image.set("width", ""+td.pxWid);
147148
image.set("height", ""+td.pxHei);
148149

150+
if ( td.hasAnyTileCustomData() ) {
151+
for ( tileId in 0...count ) {
152+
var tileData = td.getTileCustomData(tileId);
153+
if ( tileData != null ) {
154+
var tile = Xml.createElement("tile");
155+
tile.set("id", "" + tileId);
156+
var properties = Xml.createElement("properties");
157+
var dataFields = Json.parse(tileData);
158+
for ( key in Reflect.fields(dataFields) ) {
159+
var value = Reflect.field(dataFields, key);
160+
if ( value is Array ) continue;
161+
var property = Xml.createElement("property");
162+
property.set("name", key);
163+
switch ( Type.typeof(value) ) {
164+
case TBool:
165+
property.set("type", "bool");
166+
case TInt:
167+
property.set("type", "int");
168+
case TFloat:
169+
property.set("type", "float");
170+
case TObject:
171+
property = null;
172+
case _:
173+
}
174+
if ( property != null ) {
175+
property.set("value", ""+value);
176+
properties.addChild(property);
177+
}
178+
}
179+
if ( properties.firstChild() != null ) {
180+
log.add("tileset", ' Adding custom properties for tile: ${tileId}');
181+
tile.addChild(properties);
182+
tileset.addChild(tile);
183+
}
184+
}
185+
}
186+
}
187+
149188
tilesetGids.set(td.uid, gid);
150189
gid+=count;
151190
}

0 commit comments

Comments
 (0)