UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 7.37 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).rexcanvasdataplugin=e();}(undefined,(function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(n=i.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(n,"string"))?o:String(o)),i);}var n,o;}function r(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t){return i=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},i(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 u(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 r,n=i(t);if(e){var u=i(this).constructor;r=Reflect.construct(n,arguments,u);}else r=n.apply(this,arguments);return o(this,r)}}function s(){return s="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=i(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(arguments.length<3?t:r):o.value}},s.apply(this,arguments)}var a=Phaser.Math.Linear,f=Phaser.Display.Color,c={rgbaToColor32:function(t,e,r,i){return i<<24|t<<16|e<<8|r},color32ToColorInt:function(t){return 16777215&t},color32ToAlpha:function(t){return t>>>24},color32ToColorObject:function(t,e){var r=t>>16&255,i=t>>8&255,n=255&t,o=t>>24&255;return void 0===e?e=new f(r,n,i,o):e.setTo(r,n,i,o),e},interpolateColor32:function(t,e,r){var i=t>>8&255,n=255&t,o=t>>24&255,u=e>>8&255,s=255&e,f=e>>24&255,c=a(t>>16&255,e>>16&255,r),h=a(i,u,r),l=a(n,s,r);return a(o,f,r)<<24|c<<16|h<<8|l}},h=function(){function e(r,i,n){t(this,e),void 0===i&&(i=0),void 0===n&&(n=i),this.width=i,this.height=n,this.buffer=new r(i*n);}return r(e,[{key:"destroy",value:function(){this.buffer.destroy(),this.buffer=void 0;}},{key:"getOffset",value:function(t,e){return e*this.width+t}},{key:"get",value:function(t,e){var r;return r=2===arguments.length?this.getOffset(t,e):t,this.buffer.get(r)}},{key:"set",value:function(t,e,r){var i;return 3===arguments.length?i=this.getOffset(t,e):(i=t,r=e),this.buffer.set(i,r),this}},{key:"fill",value:function(t,e,r,i,n,o,u){if("number"==typeof t){var s=t;this.buffer.fill(s);}else {void 0===e&&(e=0),void 0===r&&(r=0),void 0===i&&(i=t.width-e),void 0===n&&(n=t.height-r),this.resize(i,n);for(var a,f=t.getContext("2d",{willReadFrequently:!0}).getImageData(e,r,i,n).data,c=0,h=f.length/4;c<h;c++)a=4*c,s=u?o.call(u,f,a):o(f,a),this.set(c,s);}return this}},{key:"clear",value:function(){return this.fill(0),this}},{key:"resize",value:function(t,e){return this.width===t&&this.height===e||(this.width=t,this.height=e,this.buffer.resize(t*e)),this}},{key:"forEach",value:function(t,e,r){var i;void 0===r&&(r=!1);for(var n=0,o=this.height;n<o;n++)for(var u=0,s=this.width;u<s;u++)i=this.get(u,n),(!r||0!==i&&!1!==i)&&(e?t.call(e,i,u,n,this):t(i,u,n,this));return this}},{key:"forEachNonZero",value:function(t,e){return this.forEach(t,e,!0),this}}]),e}();Object.assign(h.prototype,c);var l=function(t,e,r,i,n,o,u,s,a){return void 0===e&&(e=0),void 0===r&&(r=0),void 0===i&&(i=t.width-e),void 0===n&&(n=t.height-r),void 0===a&&(a=new h(o,i,n)),a.fill(t,e,r,i,n,u,s),a},v=function(){function e(r){t(this,e),this.resize(r);}return r(e,[{key:"destroy",value:function(){this._rows=void 0,this._buf=void 0,this._bin=void 0;}},{key:"get",value:function(t){var e=t>>3,r=1<<t%8;return (this._bin[e]&r)>0}},{key:"set",value:function(t,e){var r=t>>3,i=1<<t%8;return e?this._bin[r]|=i:(i^=255,this._bin[r]&=i),this}},{key:"fill",value:function(t){t=t?255:0;for(var e=0,r=this._rows;e<r;e++)this._bin[e]=t;return this}},{key:"resize",value:function(t){var e=1+(t>>3);return e!==this._rows&&(this._rows=e,this._buf=new ArrayBuffer(this._rows),this._bin=new Uint8Array(this._buf)),this}}]),e}(),d=function(t,e){return t[e+3]>0},y=Phaser.Utils.Objects.GetValue,p=function(t,e,r){e instanceof h&&(r=e,e=void 0);var i=y(e,"x",void 0),n=y(e,"y",void 0),o=y(e,"width",void 0),u=y(e,"height",void 0);return l(t.canvas,i,n,o,u,v,d,void 0,r)},b=function(){function e(r){t(this,e),this.resize(r);}return r(e,[{key:"destroy",value:function(){this._rows=void 0,this._buf=void 0,this._colors=void 0;}},{key:"get",value:function(t){return this._colors[t]}},{key:"set",value:function(t,e){return this._colors[t]=e,this}},{key:"fill",value:function(t){for(var e=0,r=this._rows;e<r;e++)this._colors[e]=t;return this}},{key:"resize",value:function(t){return t!==this._rows&&(this._rows=t,this._buf=new ArrayBuffer(4*this._rows),this._colors=new Uint32Array(this._buf)),this}}]),e}(),g=function(t,e){return t[e+3]<<24|t[e+0]<<16|t[e+1]<<8|t[e+2]},w=Phaser.GameObjects.GameObject,_=Phaser.Utils.Objects.GetValue,m=Phaser.Display.Canvas.CanvasPool,O={textObjectToBitmap:p,canvasObjectToBitmap:p,textureTColorMap:function(t,e,r,i){var n;"string"==typeof t?("string"!=typeof e&&(i=r,r=e,e=void 0),n=this.textureManager.getFrame(t,e)):(n=t instanceof w?t.frame:t,i=r,r=e),r instanceof h&&(i=r,r=void 0);var o=void 0!==this._tmpCanvas,u=o?this._tmpCanvas:m.create2D(this,void 0,void 0,void 0,!0),s=_(r,"x",void 0),a=_(r,"y",void 0),f=_(r,"width",void 0),c=_(r,"height",void 0);return i=l(function(t,e){return e.width=t.cutWidth,e.height=t.cutHeight,e.getContext("2d",{willReadFrequently:!0}).drawImage(t.source.image,t.cutX,t.cutY,t.cutWidth,t.cutHeight),e}(n,u),s,a,f,c,b,g,void 0,i),o?(u.width=1,u.height=1):m.remove(u),i}},j=Phaser.Display.Canvas.CanvasPool,P=function(e){!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);}(a,Phaser.Plugins.BasePlugin);var o=u(a);function a(e){return t(this,a),o.call(this,e)}return r(a,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this),this._tmpCanvas=j.create2D(this);}},{key:"destroy",value:function(){j.remove(this._tmpCanvas),this._tmpCanvas=void 0,s(i(a.prototype),"destroy",this).call(this);}},{key:"textureManager",get:function(){return this.game.textures}}]),a}();return Object.assign(P.prototype,O),P}));