flame-engine / tiled.dart

A Dart Tiled library. Parse your TMX files into useful representations. Compatible with Flame.
https://flame-engine.org/
MIT License
50 stars 30 forks source link

Json tile map parsing null #65

Open natebot13 opened 1 year ago

natebot13 commented 1 year ago

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.

spydon commented 1 year ago

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

natebot13 commented 1 year ago

@luanpotter The blame gods have mentioned your name.

jtmcdole commented 1 year ago

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.

luanpotter commented 1 year ago

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!