UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 4.03 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexgridcutimageplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(o=n.key,i=void 0,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(o,"string"))?i:String(i)),n);}var o,i;}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function n(t,e){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},n(t,e)}function o(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function i(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var n,i=r(t);if(e){var c=r(this).constructor;n=Reflect.construct(i,arguments,c);}else n=i.apply(this,arguments);return o(this,n)}}var c=function(e,r,n,o,i,c){var u,a;null==n&&(n="__BASE"),c||(a=c,"object"===t(u=n)&&(u=u.name),void 0===a&&(a=","),c="__BASE"===u?function(t,e){return "".concat(t).concat(a).concat(e)}:function(t,e){return "".concat(u,"_").concat(t).concat(a).concat(e)});for(var f,l,s,p=e.sys.textures.get(r),y="object"===t(n)?n:p.get(n),b=y.width/o,d=y.height/i,h=y.cutX,m=y.cutY,v=0,g=0,j=0;j<i;j++){v=0;for(var P=0;P<o;P++)s=c(P,j),f=v+h,l=g+m,p.add(s,0,f,l,b,d),v+=b;g+=d;}return {getFrameNameCallback:c,cellWidth:b,cellHeight:d,columns:o,rows:i}},u=Phaser.Utils.Objects.GetValue,a=Phaser.GameObjects.Image,f=Phaser.Utils.Objects.IsPlainObject,l=Phaser.Math.RotateAround;return function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&n(t,e);}(y,Phaser.Plugins.BasePlugin);var r,o,p=i(y);function y(t){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,y),p.call(this,t)}return r=y,(o=[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"gridCut",value:function(t,e,r,n){return function(t,e,r,n){f(e)&&(e=u(n=e,"columns",1),r=u(n,"rows",1));var o=u(n,"createImageCallback");if(!o){var i=u(n,"ImageClass",a);o=function(t,e,r){return new i(t,0,0,e,r)};}for(var s=u(n,"originX",.5),p=u(n,"originY",.5),y=u(n,"add",!0),b=u(n,"align",y),d=u(n,"objectPool",void 0),h=t.scene,m=t.texture,v=t.frame,g=c(h,m,v,e,r),j=g.getFrameNameCallback,P=t.scaleX,O=t.scaleY,w=t.rotation,_=t.getTopLeft(),S=_.x,x=_.y,R=[],T=g.cellWidth*P,E=g.cellHeight*O,k=0;k<r;k++)for(var C=0;C<e;C++){var B,I=j(C,k);if(B=d&&d.length>0?d.pop().setTexture(m,I):o(h,m,I),y&&h.add.existing(B),b){var A=S+T*C+s*T,N=x+E*k+p*E;B.setOrigin(s,p).setPosition(A,N).setScale(P,O).setRotation(w),l(B,S,x,w);}R.push(B);}return R}(t,e,r,n)}}])&&e(r.prototype,o),Object.defineProperty(r,"prototype",{writable:!1}),y}()}));