Skip to content

Commit

Permalink
adding tile custom data to tiled export custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMalitz committed Oct 26, 2023
1 parent dc348af commit 382f91d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/electron.renderer/exporter/Tiled.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package exporter;

import haxe.Json;
import ldtk.Json;


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

if (td.hasAnyTileCustomData()) {
for (tileId in 0...count) {
var tileData = td.getTileCustomData(tileId);
if (tileData != null) {
var tile = Xml.createElement("tile");
tile.set("id", "" + tileId);
var properties = Xml.createElement("properties");
var dataFields = Json.parse(tileData);
for (key in Reflect.fields(dataFields)) {
var value = Reflect.field(dataFields, key);
if (value is Array) continue;
var property = Xml.createElement("property");
property.set("name", key);
switch (Type.typeof(value)) {
case TBool:
property.set("type", "bool");
case TInt:
property.set("type", "int");
case TFloat:
property.set("type", "float");
case TObject:
property = null;
case _:
}
if ( property != null ) {
property.set("value", ""+value);
properties.addChild(property);
}
}
if (properties.firstChild() != null) {
log.add("tileset", ' Adding custom properties for tile: ${tileId}');
tile.addChild(properties);
tileset.addChild(tile);
}
}
}
}

tilesetGids.set(td.uid, gid);
gid+=count;
}
Expand Down

0 comments on commit 382f91d

Please sign in to comment.