tiled.dart icon indicating copy to clipboard operation
tiled.dart copied to clipboard

Json tile map parsing null

Open natebot13 opened this issue 2 years ago • 4 comments
trafficstars

https://github.com/flame-engine/tiled.dart/blob/d71d0c89f9be69593ac730483dc772b30d611363/packages/tiled/lib/src/layer.dart#L144

Is this line supposed to return null? This seems to make tileData for the layer be null, causing a null assertion failure in flame_tiled that assumes tileData is not null.

natebot13 avatar Mar 17 '23 03:03 natebot13

No idea, can you check who wrote that line and we can tag them? :)

spydon avatar Mar 17 '23 07:03 spydon

@luanpotter The blame gods have mentioned your name.

natebot13 avatar Mar 21 '23 04:03 natebot13

There's very limited documentation or testing of the parser code. Flame-engine only deals with XML files, so this looks like an oversite.

Tiled Map Editor does document this field as being either a list of ints or base64 encoded for JSON. There is no example of this in their codebase (or I'm just bad at search this early in the morning) but the XML format has the documentation for why there's a compression/encoding field. In JSON format:

Array of unsigned int (GIDs) or base64-encoded data. tilelayer only.

and

The data of a tile layer can be stored as a native JSON array or as base64-encoded and optionally compressed binary data, the same as done in the TMX format. The tiles are referenced using Global Tile IDs.

Further down in this code we call "parseLayerData" - but since this will ALWAYS be null for json, it'll never actually attempt to parse it.

This file needs a little love and testing.

jtmcdole avatar Mar 22 '23 14:03 jtmcdole

Probably an oversight on my part. I think i didn't have many/any JSON examples and thought that field was not set for the JSON format. Def open to PRs!

luanpotter avatar Mar 22 '23 15:03 luanpotter