phaser4-rex-plugins
Version:
2 lines (1 loc) • 4.39 kB
JavaScript
var t,e;t=void 0,e=function(){const t=Phaser.Math.Linear,e=Phaser.Display.Color;var i={rgbaToColor32:(t,e,i,r)=>r<<24|t<<16|e<<8|i,color32ToColorInt:t=>16777215&t,color32ToAlpha:t=>t>>>24,color32ToColorObject(t,i){var r=t>>16&255,s=t>>8&255,o=255&t,h=t>>24&255;return void 0===i?i=new e(r,o,s,h):i.setTo(r,o,s,h),i},interpolateColor32:function(e,i,r){var s=e>>8&255,o=255&e,h=e>>24&255,a=i>>8&255,n=255&i,u=i>>24&255,d=t(e>>16&255,i>>16&255,r),v=t(s,a,r),f=t(o,n,r);return t(h,u,r)<<24|d<<16|v<<8|f}};class r{constructor(t,e,i){void 0===e&&(e=0),void 0===i&&(i=e),this.width=e,this.height=i,this.buffer=new t(e*i)}destroy(){this.buffer.destroy(),this.buffer=void 0}getOffset(t,e){return e*this.width+t}get(t,e){var i;return i=2===arguments.length?this.getOffset(t,e):t,this.buffer.get(i)}set(t,e,i){var r;return 3===arguments.length?r=this.getOffset(t,e):(r=t,i=e),this.buffer.set(r,i),this}fill(t,e,i,r,s,o,h){if("number"==typeof t){var a=t;this.buffer.fill(a)}else{void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=t.width-e),void 0===s&&(s=t.height-i),this.resize(r,s);for(var n,u=t.getContext("2d",{willReadFrequently:!0}).getImageData(e,i,r,s).data,d=0,v=u.length/4;d<v;d++)n=4*d,a=h?o.call(h,u,n):o(u,n),this.set(d,a)}return this}clear(){return this.fill(0),this}resize(t,e){return this.width===t&&this.height===e||(this.width=t,this.height=e,this.buffer.resize(t*e)),this}forEach(t,e,i){var r;void 0===i&&(i=!1);for(var s=0,o=this.height;s<o;s++)for(var h=0,a=this.width;h<a;h++)r=this.get(h,s),(!i||0!==r&&!1!==r)&&(e?t.call(e,r,h,s,this):t(r,h,s,this));return this}forEachNonZero(t,e){return this.forEach(t,e,!0),this}}Object.assign(r.prototype,i);var s=function(t,e,i,s,o,h,a,n,u){return void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=t.width-e),void 0===o&&(o=t.height-i),void 0===u&&(u=new r(h,s,o)),u.fill(t,e,i,s,o,a,n),u};class o{constructor(t){this.resize(t)}destroy(){this._rows=void 0,this._buf=void 0,this._bin=void 0}get(t){var e=t>>3,i=1<<t%8;return(this._bin[e]&i)>0}set(t,e){var i=t>>3,r=1<<t%8;return e?this._bin[i]|=r:(r^=255,this._bin[i]&=r),this}fill(t){t=t?255:0;for(var e=0,i=this._rows;e<i;e++)this._bin[e]=t;return this}resize(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}}var h=function(t,e){return t[e+3]>0};const a=Phaser.Utils.Objects.GetValue;var n=function(t,e,i){e instanceof r&&(i=e,e=void 0);var n=a(e,"x",void 0),u=a(e,"y",void 0),d=a(e,"width",void 0),v=a(e,"height",void 0);return s(t.canvas,n,u,d,v,o,h,void 0,i)};class u{constructor(t){this.resize(t)}destroy(){this._rows=void 0,this._buf=void 0,this._colors=void 0}get(t){return this._colors[t]}set(t,e){return this._colors[t]=e,this}fill(t){for(var e=0,i=this._rows;e<i;e++)this._colors[e]=t;return this}resize(t){return t!==this._rows&&(this._rows=t,this._buf=new ArrayBuffer(4*this._rows),this._colors=new Uint32Array(this._buf)),this}}var d=function(t,e){return t[e+3]<<24|t[e+0]<<16|t[e+1]<<8|t[e+2]};const v=Phaser.GameObjects.GameObject,f=Phaser.GameObjects.Layer,c=Phaser.Utils.Objects.GetValue,l=Phaser.Display.Canvas.CanvasPool;var g={textObjectToBitmap:n,canvasObjectToBitmap:n,textureTColorMap:function(t,e,i,o){var h,a;"string"==typeof t?("string"!=typeof e&&(o=i,i=e,e=void 0),h=this.textureManager.getFrame(t,e)):(h=(a=t)instanceof v||a instanceof f?t.frame:t,o=i,i=e),i instanceof r&&(o=i,i=void 0);var n=void 0!==this._tmpCanvas,g=n?this._tmpCanvas:l.create2D(this,void 0,void 0,void 0,!0),b=c(i,"x",void 0),_=c(i,"y",void 0),w=c(i,"width",void 0),p=c(i,"height",void 0);return o=s(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}(h,g),b,_,w,p,u,d,void 0,o),n?(g.width=1,g.height=1):l.remove(g),o}};const b=Phaser.Display.Canvas.CanvasPool;class _ extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this),this._tmpCanvas=b.create2D(this)}destroy(){b.remove(this._tmpCanvas),this._tmpCanvas=void 0,super.destroy()}get textureManager(){return this.game.textures}}return Object.assign(_.prototype,g),_},"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();