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.14 kB
JavaScript
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(n||self).tiledKaboom=r()}(this,function(){var n="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function r(n,e,i){if(!n.s){if(i instanceof t){if(!i.s)return void(i.o=r.bind(null,n,e));1&e&&(e=i.s),i=i.v}if(i&&i.then)return void i.then(r.bind(null,n,e),r.bind(null,n,2));n.s=e,n.v=i;var o=n.o;o&&o(n)}}var t=function(){function n(){}return n.prototype.then=function(t,e){var i=new n,o=this.s;if(o){var u=1&o?t:e;if(u){try{r(i,1,u(this.v))}catch(n){r(i,2,n)}return i}return this}return this.o=function(n){try{var o=n.v;1&n.s?r(i,1,t?t(o):o):e?r(i,1,e(o)):r(i,2,o)}catch(n){r(i,2,n)}},i},n}();function e(n){return n instanceof t&&1&n.s}var i=[].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 o(i,o,u){if("function"==typeof i[n]){var a,f,c,h=i[n]();if(function n(i){try{for(;!((a=h.next()).done||u&&u());)if((i=o(a.value))&&i.then){if(!e(i))return void i.then(n,c||(c=r.bind(null,f=new t,2)));i=i.v}f?r(f,1,i):f=i}catch(n){r(f||(f=new t),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 i))throw new TypeError("Object is not iterable");for(var l=[],d=0;d<i.length;d++)l.push(i[d]);return function(n,i,o){var u,a,f=-1;return function c(h){try{for(;++f<n.length&&(!o||!o());)if((h=i(f))&&h.then){if(!e(h))return void h.then(c,a||(a=r.bind(null,u=new t,2)));h=h.v}u?r(u,1,h):u=h}catch(n){r(u||(u=new t),2,n)}}(),u}(l,function(n){return o(l[n])},u)}function u(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 a(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}return function(n){var r=window.pako;return{verifyTiledMap:u,loadTiledMap:function(t,e){void 0===e&&(e="");try{var f=function(){function f(){function n(){return c.mapObj=t,c}var e=o(t.layers,function(n){var t=function(){if("tilelayer"===n.type&&n.visible){var t=function(){for(var r=[].concat(new Array(o)).map(function(){return new Array(e+1).fill(" ")}),t=0;t<e;t++)for(var u=0;u<o;u++){var a=u*e+t;0!==n.data[a]&&(r[u][t]=i[n.data[a]])}c.levels.push(r.map(function(n){return n.join("")}))},e=n.width,o=n.height,u=function(){if("base64"===n.encoding){var t=function(){if(n.compression&&""!==n.compression){var t=function(){var t=Uint8Array.from(atob(n.data).split("").map(function(n){return n.charCodeAt(0)}));n.data=a(String.fromCharCode.apply(String,r.inflate(t)))},e=function(){if(void 0===r)return Promise.resolve(import("pako")).then(function(n){r=n})}();return e&&e.then?e.then(t):t()}n.data=a(atob(n.data))}();if(t&&t.then)return t.then(function(){})}}();return u&&u.then?u.then(t):t()}}();if(t&&t.then)return t.then(function(){})});return e&&e.then?e.then(n):n()}u(t);var c={sprites:[],levels:[],key:{}},h=o(t.tilesets,function(r){function t(){for(var t=function(t){c.key[i[t]]=function(){return[n.sprite(r.name,{frame:t-1})]}},e=r.firstgid;e<r.firstgid+r.tilecount;e++)t(e)}if(0===r.margin){if(0===r.spacing){var o=r.imagewidth/r.tilewidth,u=r.imageheight/r.tileheight,a=function(){if(r.image){var t=c.sprites,i=t.push;return Promise.resolve(n.loadSprite(r.name,""+e+r.image,{sliceX:o,sliceY:u})).then(function(n){i.call(t,n)})}}();return a&&a.then?a.then(t):t()}console.error(r.name+" uses spacing. That is currently unsupported. Skipping.")}else console.error(r.name+" uses margins. That is currently unsupported. Skipping.")});return h&&h.then?h.then(f):f()},c=function(){if("string"==typeof t)return Promise.resolve(fetch(t).then(function(n){return n.json()})).then(function(n){t=n})}();return Promise.resolve(c&&c.then?c.then(f):f())}catch(n){return Promise.reject(n)}}}}});
//# sourceMappingURL=tiled-kaboom.umd.js.map