Skip to content

Commit 1dc6c4c

Browse files
committed
fix compatibility with melonJS version 15.2.1 and higher
1 parent dac30b9 commit 1dc6c4c

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [1.1.1] - 2023-05-14
2+
3+
### Fixed
4+
- fix compatibility with melonJS version 15.2.1 and higher
5+
16
## [1.1.0] - 2023-05-13
27

38
### Added

dist/@melonjs/tiled-inflate-plugin.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*!
22
* a melonJS plugin to enable loading and parsing of compressed Tiled maps
3-
* @melonjs/tiled-inflate-plugin - v1.1.0
3+
* @melonjs/tiled-inflate-plugin - v1.1.1
44
* @melonjs/tiled-inflate-plugin is licensed under the MIT License.
55
* http://www.opensource.org/licenses/mit-license
66
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
77
*/
8-
import { plugin, utils } from 'melonjs';
8+
import { plugin, TMXUtils } from 'melonjs';
99

1010
/**
1111
* base64.ts
@@ -7167,23 +7167,27 @@ class TiledInflatePlugin extends plugin.BasePlugin {
71677167
super();
71687168

71697169
// minimum melonJS version expected to run this plugin
7170-
this.version = "15.2.0";
7170+
this.version = "15.2.1";
71717171

71727172
/**
71737173
* decompress and decode zlib/gzip data
71747174
* @param {string} input - base64 encoded and compressed data
71757175
* @param {string} format - compressed data format ("gzip","zlib", "zstd")
71767176
* @returns {Uint32Array} decoded and decompressed data
71777177
*/
7178-
utils.inflateb64 = (data, format) => {
7179-
if (format === "gzip" || format === "zlib") {
7180-
var output = pako.inflate(gBase64.toUint8Array(data));
7181-
return new Uint32Array(output.buffer);
7182-
} else {
7183-
// TODO: ztsd compression (since Tiled 1.3)
7184-
throw new Error(format + " compressed TMX Tile Map not supported!");
7178+
TMXUtils.setInflateFunction((data, format) => {
7179+
let output;
7180+
switch (format) {
7181+
case "gzip":
7182+
case "zlib":
7183+
output = pako.inflate(gBase64.toUint8Array(data));
7184+
break;
7185+
case "zstd":
7186+
default:
7187+
throw new Error(format + " compressed TMX Tile Map not supported!");
71857188
}
7186-
};
7189+
return new Uint32Array(output.buffer);
7190+
});
71877191
}
71887192
}
71897193

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@melonjs/tiled-inflate-plugin",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "a melonJS plugin to enable loading and parsing of compressed Tiled maps",
55
"type": "module",
66
"keywords": [
@@ -40,7 +40,7 @@
4040
"LICENSE"
4141
],
4242
"peerDependencies": {
43-
"melonjs": "^15.2.0"
43+
"melonjs": "^15.2.1"
4444
},
4545
"devDependencies": {
4646
"@babel/eslint-parser": "^7.21.8",
@@ -51,7 +51,7 @@
5151
"del-cli": "^5.0.0",
5252
"eslint": "^8.40.0",
5353
"eslint-plugin-jsdoc": "^44.2.3",
54-
"rollup": "^3.21.6",
54+
"rollup": "^3.21.7",
5555
"rollup-plugin-bundle-size": "^1.0.3",
5656
"typescript": "^5.0.4"
5757
},

src/index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { plugin, utils } from "melonjs";
1+
import { plugin, TMXUtils } from "melonjs";
22
import { Base64 } from "js-base64";
33
import pako from "pako";
44

@@ -13,22 +13,26 @@ export class TiledInflatePlugin extends plugin.BasePlugin {
1313
super();
1414

1515
// minimum melonJS version expected to run this plugin
16-
this.version = "15.2.0";
16+
this.version = "15.2.1";
1717

1818
/**
1919
* decompress and decode zlib/gzip data
2020
* @param {string} input - base64 encoded and compressed data
2121
* @param {string} format - compressed data format ("gzip","zlib", "zstd")
2222
* @returns {Uint32Array} decoded and decompressed data
2323
*/
24-
utils.inflateb64 = (data, format) => {
25-
if (format === "gzip" || format === "zlib") {
26-
var output = pako.inflate(Base64.toUint8Array(data));
27-
return new Uint32Array(output.buffer);
28-
} else {
29-
// TODO: ztsd compression (since Tiled 1.3)
30-
throw new Error(format + " compressed TMX Tile Map not supported!");
24+
TMXUtils.setInflateFunction((data, format) => {
25+
let output;
26+
switch (format) {
27+
case "gzip":
28+
case "zlib":
29+
output = pako.inflate(Base64.toUint8Array(data));
30+
break;
31+
case "zstd":
32+
default:
33+
throw new Error(format + " compressed TMX Tile Map not supported!");
3134
}
32-
};
35+
return new Uint32Array(output.buffer);
36+
});
3337
}
3438
}

0 commit comments

Comments
 (0)