Posted January 30, 2019 by Thorbjørn Lindeijer
#Snapshot
This month Tiled development had a slow start as I was spending the first two weeks on renovation work. I cought up in the third week and ended up making a few big steps towards a scriptable Tiled. I also managed to squeeze in some fixes and improvements for the recent Tiled 1.2.2 release.
Actually the first thing I worked on this month wasn't scripting-related. It was a priority request from a patron to add the list of objects to the Tile Collision Editor. They sometimes had a lot of objects on a tile, in which case having the list helps a lot.
The list can be hidden (default) or shown on the right or at the bottom.
Initial support was added for defining export formats in JavaScript. Currently this works only for maps, and only to text-based formats, but that can already be quite useful. The easiest format to export to is of course JSON, but you can always put together the string manually. You can find an example in the documentation.
Being able to associate custom properties to all data types is part of what makes Tiled so versatile. So I think it's noteworthy that they can now also be inspected and changed from scripts!
In the last snapshot, scripts were limited to changing around existing objects. Now they can create objects, layers and even maps and tilesets (though you can't do anything useful yet with the latter two).
Support was added for accessing the tiles in a tileset and the tiles on a tile layer. Last but not least, those tiles can now be used to modify tile layers! For performance reasons, tile layers edits are done through an "edit object". This is illustrated by the following example:
function fillFirstLayerWithFirstTile() { var tileLayer = tiled.activeAsset.layerAt(0) var tile = tileLayer.tileAt(0, 0) var e = tileLayer.edit() for (var y = 0; y < tileLayer.height; y++) for (var x = 0; x < tileLayer.width; x++) e.setTile(x, y, tile) e.apply() }
Check out the documentation for more information. Of course the class will be expanded with more functionality in the future.
Here is the full list of noteworthy changes since the last development snapshot.
A big thanks to everybody who's making it possible for me to spend time on a big feature like the support for scripting! Thanks to your purchases and support on Patreon and Liberapay I'm able to keep spending two full days/week on Tiled development!