UNPKG

tiled-kaboom

Version:

This is a map-loader for [kaboom](https://kaboomjs.com/) to load [tiled](https://www.mapeditor.org/) JSON maps.

3 lines (2 loc) 5.29 kB
function n(n){if(n&&n.__esModule)return n;var r=Object.create(null);return n&&Object.keys(n).forEach(function(t){if("default"!==t){var e=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(r,t,e.get?e:{enumerable:!0,get:function(){return n[t]}})}}),r.default=n,r}var r="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function t(n,r,i){if(!n.s){if(i instanceof e){if(!i.s)return void(i.o=t.bind(null,n,r));1&r&&(r=i.s),i=i.v}if(i&&i.then)return void i.then(t.bind(null,n,r),t.bind(null,n,2));n.s=r,n.v=i;var o=n.o;o&&o(n)}}var e=function(){function n(){}return n.prototype.then=function(r,e){var i=new n,o=this.s;if(o){var u=1&o?r:e;if(u){try{t(i,1,u(this.v))}catch(n){t(i,2,n)}return i}return this}return this.o=function(n){try{var o=n.v;1&n.s?t(i,1,r?r(o):o):e?t(i,1,e(o)):t(i,2,o)}catch(n){t(i,2,n)}},i},n}();function i(n){return n instanceof e&&1&n.s}var o=[].concat(new Array(4052)).reduce(function(n,r,t){if([92,173,847,888,889,907,909,930,1328,1367,1368,1376,1416,1419,1420,1421,1424,1565,1867,1868,2081,2082,2094,2095,2111,2140,2141,2445,2446,2449,2450,2473,2481,2490,2491,2501,2502,2505,2506,2526,2532,2533,2564,2577,2578,2601,2609,2612,2615,2618,2619,2621,2633,2634,2638,2639,2640,2653,2692,2702,2706,2729,2737,2740,2746,2747,2758,2762,2766,2767,2788,2789,2820,2829,2830,2833,2834,2857,2865,2868,2874,2875,2885,2886,2889,2890,2910,2916,2917,2948,2955,2956,2957,2961,2966,2967,2968,2971,2973,2976,2977,2978,2981,2982,2983,2987,2988,2989].includes(t))return n;if(t<33)return n;for(var e=0,i=[[126,161],[895,900],[1479,1488],[1514,1520],[1524,1536],[1969,1984],[2042,2048],[2142,2207],[2238,2260],[2384,2389],[2482,2486],[2510,2519],[2519,2524],[2555,2561],[2570,2575],[2626,2631],[2641,2649],[2654,2662],[2677,2689],[2768,2784],[2801,2809],[2809,2817],[2893,2902],[2903,2908],[2935,2946]];e<i.length;e++){var o=i[e];if(t>o[0]&&t<o[1])return n}return[].concat(n,[String.fromCharCode(t)])},[]);function u(n,o,u){if("function"==typeof n[r]){var a,f,c,h=n[r]();if(function n(r){try{for(;!((a=h.next()).done||u&&u());)if((r=o(a.value))&&r.then){if(!i(r))return void r.then(n,c||(c=t.bind(null,f=new e,2)));r=r.v}f?t(f,1,r):f=r}catch(n){t(f||(f=new e),2,n)}}(),h.return){var s=function(n){try{a.done||h.return()}catch(n){}return n};if(f&&f.then)return f.then(s,function(n){throw s(n)});s()}return f}if(!("length"in n))throw new TypeError("Object is not iterable");for(var l=[],d=0;d<n.length;d++)l.push(n[d]);return function(n,r,o){var u,a,f=-1;return function c(h){try{for(;++f<n.length&&(!o||!o());)if((h=r(f))&&h.then){if(!i(h))return void h.then(c,a||(a=t.bind(null,u=new e,2)));h=h.v}u?t(u,1,h):u=h}catch(n){t(u||(u=new e),2,n)}}(),u}(l,function(n){return o(l[n])},u)}function a(n){if(!n)throw new Error("Map parameter is required.");if("orthogonal"!==n.orientation)throw new Error("Map is "+n.orientation+". Only orthogonal is currently supported.");if("right-down"!==n.renderorder)throw new Error("Map is "+n.renderorder+". Only right-down is currently supported.")}function f(n){for(var r=n.length,t=new Array(r/4),e=0;e<r;e+=4)t[e/4]=(n.charCodeAt(e)|n.charCodeAt(e+1)<<8|n.charCodeAt(e+2)<<16|n.charCodeAt(e+3)<<24)>>>0;return t}module.exports=function(r){var t=window.pako;return{verifyTiledMap:a,loadTiledMap:function(e,i){void 0===i&&(i="");try{var c=function(){function c(){function r(){return h.mapObj=e,h}var i=u(e.layers,function(r){var e=function(){if("tilelayer"===r.type&&r.visible){var e=function(){for(var n=[].concat(new Array(u)).map(function(){return new Array(i+1).fill(" ")}),t=0;t<i;t++)for(var e=0;e<u;e++){var a=e*i+t;0!==r.data[a]&&(n[e][t]=o[r.data[a]])}h.levels.push(n.map(function(n){return n.join("")}))},i=r.width,u=r.height,a=function(){if("base64"===r.encoding){var e=function(){if(r.compression&&""!==r.compression){var e=function(){var n=Uint8Array.from(atob(r.data).split("").map(function(n){return n.charCodeAt(0)}));r.data=f(String.fromCharCode.apply(String,t.inflate(n)))},i=function(){if(void 0===t)return Promise.resolve(Promise.resolve().then(function(){return n(require("pako"))})).then(function(n){t=n})}();return i&&i.then?i.then(e):e()}r.data=f(atob(r.data))}();if(e&&e.then)return e.then(function(){})}}();return a&&a.then?a.then(e):e()}}();if(e&&e.then)return e.then(function(){})});return i&&i.then?i.then(r):r()}a(e);var h={sprites:[],levels:[],key:{}},s=u(e.tilesets,function(n){function t(){for(var t=function(t){h.key[o[t]]=function(){return[r.sprite(n.name,{frame:t-1})]}},e=n.firstgid;e<n.firstgid+n.tilecount;e++)t(e)}if(0===n.margin){if(0===n.spacing){var e=n.imagewidth/n.tilewidth,u=n.imageheight/n.tileheight,a=function(){if(n.image){var t=h.sprites,o=t.push;return Promise.resolve(r.loadSprite(n.name,""+i+n.image,{sliceX:e,sliceY:u})).then(function(n){o.call(t,n)})}}();return a&&a.then?a.then(t):t()}console.error(n.name+" uses spacing. That is currently unsupported. Skipping.")}else console.error(n.name+" uses margins. That is currently unsupported. Skipping.")});return s&&s.then?s.then(c):c()},h=function(){if("string"==typeof e)return Promise.resolve(fetch(e).then(function(n){return n.json()})).then(function(n){e=n})}();return Promise.resolve(h&&h.then?h.then(c):c())}catch(n){return Promise.reject(n)}}}}; //# sourceMappingURL=tiled-kaboom.cjs.map