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.
This commit is contained in:
Lisandro Lorea 2015-09-13 12:07:57 -03:00
parent 816bcaca75
commit 308ce6b57c

View file

@ -233,6 +233,19 @@ Phaser.TilemapParser = {
var curl = json.layers[i]; var curl = json.layers[i];
// Base64 decode data if necessary
// NOTE: uncompressed base64 only.
if (!curl.compression && curl.encoding && curl.encoding === "base64") {
var binary_string = window.atob(curl.data);
var len = binary_string.length;
var bytes = new Array( len );
for (var i = 0; i < len; i+=4) {
bytes[i/4] = binary_string.charCodeAt(i);
}
curl.data = bytes;
}
var layer = { var layer = {
name: curl.name, name: curl.name,