Skip to content

Commit 308ce6b

Browse files
committed
Add support for TiledJSON with base64 encoding
Tiled 0.13.0 added support for layer data compression when exporting as LUA or JSON. This means that any .tmx stored unsing base64 encoding will start exporting layer data as a base64 encoded string rather than a native array. Phaser would try to load the level anyway without emitting any errors, resulting in a corrupted level while playing. This PR adds detection and support for base64 encoded levels as long as they don't use compression.
1 parent 816bcac commit 308ce6b

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/tilemap/TilemapParser.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,19 @@ Phaser.TilemapParser = {
232232
}
233233

234234
var curl = json.layers[i];
235+
236+
// Base64 decode data if necessary
237+
// NOTE: uncompressed base64 only.
238+
if (!curl.compression && curl.encoding && curl.encoding === "base64") {
239+
var binary_string = window.atob(curl.data);
240+
var len = binary_string.length;
241+
var bytes = new Array( len );
242+
for (var i = 0; i < len; i+=4) {
243+
bytes[i/4] = binary_string.charCodeAt(i);
244+
}
245+
curl.data = bytes;
246+
}
247+
235248

236249
var layer = {
237250

0 commit comments

Comments
 (0)