|
1 | 1 | package exporter;
|
2 | 2 |
|
| 3 | +import haxe.Json; |
3 | 4 | import ldtk.Json;
|
4 | 5 |
|
5 | 6 |
|
@@ -146,6 +147,44 @@ class Tiled extends Exporter {
|
146 | 147 | image.set("width", ""+td.pxWid);
|
147 | 148 | image.set("height", ""+td.pxHei);
|
148 | 149 |
|
| 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 | + |
149 | 188 | tilesetGids.set(td.uid, gid);
|
150 | 189 | gid+=count;
|
151 | 190 | }
|
|
0 commit comments