Skip to content

Commit e9cefbf

Browse files
committed
Added base64 polyfill for new Tiled export support.
1 parent 1c7b331 commit e9cefbf

3 files changed

Lines changed: 72 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
263263
* Group.getFirstDead, Group.getFirstAlive and Group.getFirstExists all have new optional arguments: `createIfNull`, `x`, `y`, `key` and `frame`. If the method you call cannot find a matching child (i.e. getFirstDead cannot find any dead children) then the optional `createIfNull` allows you to instantly create a new child in the group using the position and texture arguments to do so. This allows you to always get a child back from the Group and remove the need to do null checks and Group inserts from your game code. The same arguments can also be used in a different way: if `createIfNull` is false AND you provide the extra arguments AND a child is found then it will be passed to the new `Group.resetChild` method. This allows you to retrieve a child from the Group and have it reset and instantly ready for use in your game without any extra code.
264264
* P2.Body.removeCollisionGroup allows you to remove the given CollisionGroup, or array of CollisionGroups, from the list of groups that a body will collide with and updates the collision masks (thanks @Garbanas #2047)
265265
* Filter.addToWorld allows you to quickly create a Phaser.Image object at the given position and size, with the Filter ready applied to it. This can eliminate lots of duplicate code.
266+
* Tiled 0.13.0 added support for layer data compression when exporting as JSON. This means that any .tmx stored using base64 encoding will start exporting layer data as a base64 encoded string rather than a native array. This update adds in automatic support for this as long as the data isn't compressed. For IE9 support you'll need to use the new polyfill found in the resources folder (thanks @noidexe #2084)
266267

267268
### Updates
268269

resources/IE9 Polyfill/base64.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
;
2+
(function() {
3+
4+
var object = typeof exports != 'undefined' ? exports : this; // #8: web workers
5+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
6+
7+
function InvalidCharacterError(message) {
8+
this.message = message;
9+
}
10+
InvalidCharacterError.prototype = new Error;
11+
InvalidCharacterError.prototype.name = 'InvalidCharacterError';
12+
13+
// encoder
14+
// [https://gist.github.com/999166] by [https://github.com/nignag]
15+
object.btoa || (
16+
object.btoa = function(input) {
17+
var str = String(input);
18+
for (
19+
// initialize result and counter
20+
var block, charCode, idx = 0, map = chars, output = '';
21+
// if the next str index does not exist:
22+
// change the mapping table to "="
23+
// check if d has no fractional digits
24+
str.charAt(idx | 0) || (map = '=', idx % 1);
25+
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
26+
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
27+
) {
28+
charCode = str.charCodeAt(idx += 3 / 4);
29+
if (charCode > 0xFF) {
30+
throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
31+
}
32+
block = block << 8 | charCode;
33+
}
34+
return output;
35+
});
36+
37+
// decoder
38+
// [https://gist.github.com/1020396] by [https://github.com/atk]
39+
object.atob || (
40+
object.atob = function(input) {
41+
var str = String(input).replace(/=+$/, '');
42+
if (str.length % 4 == 1) {
43+
throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");
44+
}
45+
for (
46+
// initialize result and counters
47+
var bc = 0, bs, buffer, idx = 0, output = '';
48+
// get next character
49+
buffer = str.charAt(idx++);
50+
// character found in table? initialize bit storage and add its ascii value;
51+
~ buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,
52+
// and if not first of each 4 characters,
53+
// convert the first 8 bits to one ascii character
54+
bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0
55+
) {
56+
// try to find character in table (0-63, not found => -1)
57+
buffer = chars.indexOf(buffer);
58+
}
59+
return output;
60+
});
61+
62+
}());

resources/IE9 Polyfill/readme.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
The polyfill found in this folder provides ArrayBuffer and DataView support for IE9, required by P2 Physics.
1+
There are 2 polyfills in this folder:
2+
3+
ArrayBuffer and DataView support for IE9, required by P2 Physics.
24

35
You do not need this polyfill unless:
46

57
1) You are using P2 Physics in Phaser AND
68
2) You need to support IE9 specifically
79

8-
Ensure the polyfill is required before the Phaser library.
10+
Base64 Encoding and Decoding (adds window.atob and window.btoa support)
11+
12+
You only need this polyfill if you wish to load Base64 encoded Tile Map data in IE9, as exported by Tiled 0.13.0+
13+
14+
15+
Ensure any polyfills are required before the Phaser library.

0 commit comments

Comments
 (0)