@petkoneo/phaser3-rex-plugins
Version:
2 lines (1 loc) • 5.64 kB
JavaScript
var t,e;t=void 0,e=function(){const t=Phaser.Game;var e=function(e){return e instanceof t};const i=Phaser.Scene;var s,a,h=function(t){return t instanceof i},r=function(t){return null==t||"object"!=typeof t?null:e(t)?t:e(t.game)?t.game:h(t)?t.sys.game:h(t.scene)?t.scene.sys.game:void 0},n=function(t,e,i,h,n){if(void 0===s){var o=(l=t.manager.game,r(l).textures.getFrame("__WHITE"));s=o.cutWidth,a=o.cutHeight}var l;return t.stamp("__WHITE",void 0,e,i,{scaleX:h/s,scaleY:n/a,originX:0,originY:0,erase:!0}),t},o=function(t,e,i,s){this.useDynamicTexture?n(this.texture,t,e,i,s):this.context.clearRect(t,e,i,s)},l=function(t,e,i,s,a){var h=this.context;h.save(),h.translate(t,e),a?s.call(a,this.canvas,h,i):s(this.canvas,h,i),h.restore()},c=function(t,e,i,s,a){var h=this.texture;h.camera.setScroll(-t,-e),a?s.call(a,h,i):s(h,i),h.camera.setScroll(0,0)},d={remove(t){var e=this.getFrameIndex(t);return-1===e||(this.addFrameName(e,void 0),this.texture.remove(t)),this},clear(){for(var t,e=this.frameNames.length;t<e;t++){var i=this.frameNames[t];void 0!==i&&(this.addFrameName(index,void 0),this.texture.remove(i))}return this}},u={draw:function(t,e,i){var s=this.getFrameIndex(t);if(-1===s&&(s=this.getFrameIndex(void 0)),-1===s)return console.warn("Does not have free space."),this;var a=this.getTopLeftPosition(s),h=a.x,r=a.y,n=this.cellPadding,d=h+n,u=r+n;o.call(this,h,r,this.outerCellWidth,this.outerCellHeight);var v={width:this.cellWidth,height:this.cellHeight};return(this.useDynamicTexture?c:l).call(this,d,u,v,e,i),this.texture.add(t,0,d,u,v.width,v.height),this.addFrameName(s,t),this},paste:function(t,e){var i;if(this.useDynamicTexture){var s=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width}(e),a=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height}(e);o=s<=this.cellWidth&&a<=this.cellHeight?1:Math.max(s/this.cellWidth,a/this.cellHeight),i=function(t,i){var h=e.originX,r=e.originY,n=e.scaleX,l=e.scaleY;e.setOrigin(0,0).setScale(o,o),t.draw(e),e.setOrigin(h,r).setScale(n,l),i.width=s/o,i.height=a/o}}else{var h,r,n=e.canvas;if(!n)return console.warn("Can't get canvas of game object."),this;if(s=n.width,a=n.height,s<=this.cellWidth&&a<=this.cellHeight)h=s,r=a;else{var o=Math.max(s/this.cellWidth,a/this.cellHeight);h=s/o,r=a/o}i=function(t,e,i){e.drawImage(n,0,0,h,r),i.width=h,i.height=r}}return this.draw(t,i),this},addEmptyFrame:function(t,e,i){var s;return void 0===e&&(e=this.cellWidth),void 0===i&&(i=this.cellHeight),s=this.useDynamicTexture?function(t,s){s.width=e,s.height=i}:function(t,s,a){a.width=e,a.height=i},this.draw(t,s),this},addToBitmapFont:function(){var t=this.texture.key,e=this.bitmapFontCache.get(t);e||(e={data:{retroFont:!0,font:t,size:this.cellWidth,lineHeight:this.cellHeight,chars:{}},texture:t,frame:null},this.bitmapFontCache.add(t,e));for(var i=e.data.chars,s=this.frameNames,a=0,h=s.length;a<h;a++){var r=s[a];if(void 0!==r){var n=this.texture.get(r),o=n.cutX,l=n.cutY,c=n.cutWidth,d=n.cutHeight;i[r.charCodeAt(0)]={x:o,y:l,width:c,height:d,centerX:o+c/2,centerY:l+d/2,xOffset:0,yOffset:0,xAdvance:c,data:{},kerning:{},u0:n.u0,v0:n.v0,u1:n.u1,v1:n.v1}}}return this}};Object.assign(u,d);const v=Phaser.Utils.Objects.IsPlainObject,g=Phaser.Utils.Objects.GetValue;class m{constructor(t,e,i,s,a,h,n,o){var l,c,d;if(v(e)){var u=e;e=g(u,"key"),i=g(u,"width"),s=g(u,"height"),a=g(u,"cellWidth"),h=g(u,"cellHeight"),d=g(u,"cellPadding",0),l=g(u,"columns"),c=g(u,"rows"),n=g(u,"fillColor"),o=g(u,"useDynamicTexture")}else"boolean"==typeof n&&(o=n,n=void 0);void 0===a&&(a=64),void 0===h&&(h=64),void 0===d&&(d=0),this.cellWidth=a,this.cellHeight=h,this.cellPadding=d,l?i=this.outerCellWidth*l:(void 0===i&&(i=4096),l=Math.floor(i/this.outerCellWidth)),c?s=this.outerCellHeight*c:(void 0===s&&(s=4096),c=Math.floor(s/this.outerCellHeight)),void 0===o&&(o=!1);var m=r(t);if(this.useDynamicTexture=o,this.texture=function(t,e,i,s,a){void 0===a&&(a=!1);var h=(t=r(t)).textures;return h.exists(e)&&h.remove(e),h[a?"addDynamicTexture":"createCanvas"](e,i,s)}(m,e,i,s,o),this.canvas=o?void 0:this.texture.getCanvas(),this.context=o?void 0:this.texture.getContext(),this.bitmapFontCache=m.cache.bitmapFont,void 0!==n)if(o)this.texture.fill(n);else{var f=this.context;f.fillStyle=n,f.fillRect(0,0,this.canvas.width,this.canvas.height)}this.key=e,this.width=i,this.height=s,this.columns=l,this.rows=c,this.totalCount=this.columns*this.rows,this.frameNames=Array(this.totalCount);for(var x=0,y=this.frameNames.length;x<y;x++)this.frameNames[x]=void 0}get outerCellWidth(){return this.cellWidth+2*this.cellPadding}get outerCellHeight(){return this.cellHeight+2*this.cellPadding}destroy(){this.texture=void 0,this.canvas=void 0,this.context=void 0,this.frameNames=void 0,this.bitmapFontCache=void 0}getFrameIndex(t){return this.frameNames.indexOf(t)}contains(t){return-1!==this.getFrameIndex(t)}addFrameName(t,e){return this.frameNames[t]=e,this}get isFull(){return-1===this.getFrameIndex(void 0)}getTopLeftPosition(t,e){void 0===e&&(e={});var i=t%this.columns,s=Math.floor(t/this.columns);return e.x=i*(this.cellWidth+2*this.cellPadding),e.y=s*(this.cellHeight+2*this.cellPadding),e}updateTexture(){return this.useDynamicTexture||this.texture.refresh(),this}}Object.assign(m.prototype,u);class f extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e,i,s,a,h,r,n){return new m(t,e,i,s,a,h,r,n)}}return f},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexframemanagerplugin=e();