phaser3-rex-plugins
Version:
2 lines (1 loc) • 8.05 kB
JavaScript
var t,e;t=void 0,e=function(){var t=function(t,e,i){return"__BASE"===i?`${t},${e}`:`${i}:${t},${e}`};function e(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map((t=>e(t)));if(t instanceof Date)return new Date(t);if(t instanceof RegExp)return new RegExp(t);if(Object.getPrototypeOf(t)!==Object.prototype)return t;const i={};for(let s in t)t.hasOwnProperty(s)&&(i[s]=e(t[s]));return i}const i=Phaser.Utils.Objects.IsPlainObject,s=Phaser.Utils.Objects.GetValue;var r=function(t){return"string"==typeof t&&(t=n[t]),t};const n={scale:0,repeat:1};var a=function(t,e){return 0===t||t===this.columns.count-1||0===e||e===this.rows.count-1},o=function(){},h={_beginDraw:o,_drawImage:o,_drawTileSprite:o,_endDraw:o,setGetFrameNameCallback:function(e){return void 0===e&&(e=t),this.getFrameNameCallback=e,this},setBaseTexture:function(t,i,s,r){Array.isArray(i)&&(r=s,s=i,i=void 0),null==i&&(i="__BASE"),"number"==typeof s&&arguments.length>=6?(s=[arguments[2],void 0,arguments[3]],r=[arguments[4],void 0,arguments[5]]):void 0===s&&void 0===r&&void 0!==this.columns.data&&void 0!==this.rows.data?(s=this.columns.data,r=this.rows.data):(s=e(s),r=e(r)),this.textureKey=t,this.baseFrameName=i,this.columns.data=s,this.columns.count=s?s.length:0,this.columns.stretch=0,this.columns.minWidth=0,this.columns.scale=1,this.rows.data=r,this.rows.count=r?r.length:0,this.rows.stretch=0,this.rows.minHeight=0,this.rows.scale=1;var n=this.scene.sys.textures.get(t);if(!n)return this.clear(),this;if(!s||!r)return this.clear(),this;for(var a=n.get(i),o=a.width,h=0,c=0,u=s.length;c<u;c++)void 0===s[c]?h++:"number"==typeof s[c]?o-=s[c]:o-=s[c].width;var d=h>0?o/h:0,l=a.height,m=0;for(c=0,u=r.length;c<u;c++)void 0===r[c]?m++:"number"==typeof r[c]?l-=r[c]:l-=r[c].width;for(var v,f,g,w,p,x=m?l/m:0,y=0,b=0,P=0,S=r.length;P<S;P++){void 0===r[P]&&(r[P]=x),"number"==typeof r[P]&&(r[P]={height:r[P],stretch:P%2}),g=(v=r[P]).height,this.rows.stretch+=0|v.stretch,this.rows.minHeight+=v.stretch>0?0:g,y=0,c=0;for(var F=s.length;c<F;c++){if(void 0===s[c]&&(s[c]=d),"number"==typeof s[c]&&(s[c]={width:s[c],stretch:c%2}),w=(f=s[c]).width,0===P&&(this.columns.stretch+=0|f.stretch,this.columns.minWidth+=f.stretch>0?0:w),w>=1&&g>=1){var O=typeof(p=this.getFrameNameCallback(c,P,i));"string"!==O&&"number"!==O||n.add(p,0,y+a.cutX,b+a.cutY,w,g)}y+=w}b+=g}return this.updateTexture(),this},updateTexture:function(){if(this.clear(),void 0===this.textureKey)return this;var t=this.scene.sys.textures.get(this.textureKey);if(!t)return this;var e,i,s,r,n,a,o,h=this.columns.minWidth*this.maxFixedPartScaleX,c=this.rows.minHeight*this.maxFixedPartScaleY,u=this.width-h,d=this.height-c,l=u>=0?this.maxFixedPartScaleX:this.width/h,m=d>=0?this.maxFixedPartScaleY:this.height/c;if(this.preserveRatio){var v=Math.min(l,m);if(l>v){var f=(l-v)*h;u>=0?u+=f:u=f,l=v}if(m>v){var g=(m-v)*c;d>=0?d+=g:d=g,m=v}}this.columns.scale=l,this.rows.scale=m,e=u>0&&this.columns.stretch>0?u/this.columns.stretch:0,i=d>0&&this.rows.stretch>0?d/this.rows.stretch:0;var w=0,p=0;this._beginDraw();for(var x=0,y=this.rows.count;x<y;x++){o=0===(n=this.rows.data[x]).stretch?n.height*m:i*n.stretch,w=0;for(var b=0,P=this.columns.count;b<P;b++)a=0===(r=this.columns.data[b]).stretch?r.width*l:e*r.stretch,s=this.getFrameNameCallback(b,x,this.baseFrameName),t.has(s)&&a>0&&o>0&&(0==(0===n.stretch&&0===r.stretch||0===this.getStretchMode(b,x)?0:1)?this._drawImage(this.textureKey,s,w,p,a,o):this._drawTileSprite(this.textureKey,s,w,p,a,o)),w+=a;p+=o}this._endDraw()},setStretchMode:function(t){return i(t)?(this.stretchMode.edge=r(s(t,"edge",0)),this.stretchMode.internal=r(s(t,"internal",0))):(t=r(t),this.stretchMode.edge=t,this.stretchMode.internal=t),this},getStretchMode:function(t,e){return a.call(this,t,e)?this.stretchMode.edge:this.stretchMode.internal},setPreserveRatio:function(t){return null==t&&(t=!0),this.preserveRatio=t,this},setMaxFixedPartScale:function(t,e){return void 0===e&&(e=t),this.maxFixedPartScaleX=t,this.maxFixedPartScaleY=e,this}};const c=Phaser.Utils.Objects.IsPlainObject,u=Phaser.Utils.Objects.GetValue,d=Phaser.Game;var l=function(t){return t instanceof d};const m=Phaser.Scene;var v=function(t){return t instanceof m},f=function(t){return null==t||"object"!=typeof t?null:l(t)?t:l(t.game)?t.game:v(t)?t.sys.game:v(t.scene)?t.scene.sys.game:void 0};const g=Phaser.GameObjects;var w=void 0,p=function(t,e){if(w||(w={},f(t).events.once("destroy",(function(){for(var t in w)w[t].destroy();w=void 0}))),!w.hasOwnProperty(e)){var i=f(t).scene.systemScene;(t=new g[e](i)).setOrigin(0),w[e]=t}return w[e]};const x=Phaser.GameObjects.RenderTexture;class y extends(function(t,e){class i extends t{constructor(t,i,s,r,n,a,o,h,d,l){if(c(i)?(i=u(l=i,"x",0),s=u(l,"y",0),r=u(l,"width",1),n=u(l,"height",1),a=u(l,"key",void 0),o=u(l,"baseFrame",void 0),h=u(l,"columns",void 0),d=u(l,"rows",void 0)):c(r)?(r=u(l=r,"width",1),n=u(l,"height",1),a=u(l,"key",void 0),o=u(l,"baseFrame",void 0),h=u(l,"columns",void 0),d=u(l,"rows",void 0)):c(a)?(a=u(l=a,"key",void 0),o=u(l,"baseFrame",void 0),h=u(l,"columns",void 0),d=u(l,"rows",void 0)):c(o)?(o=u(l=o,"baseFrame",void 0),h=u(l,"columns",void 0),d=u(l,"rows",void 0)):Array.isArray(o)?(l=d,d=h,h=o,o=u(l,"baseFrame",void 0)):c(h)&&(h=u(l=h,"columns",void 0),d=u(l,"rows",void 0)),void 0===o&&(o=u(l,"frame",void 0)),void 0===h){var m=u(l,"leftWidth",void 0),v=u(l,"rightWidth",void 0);void 0!==m&&void 0!==v&&(h=[m,void 0,v])}if(void 0===d){var f=u(l,"topHeight",void 0),g=u(l,"bottomHeight",void 0);void 0!==f&&void 0!==g&&(d=[f,void 0,g])}super(t),this.type=e,this.setPosition(i,s).setSize(r,n).setOrigin(.5,.5),this.columns={},this.rows={},this.stretchMode={},this._tileSprite=void 0,this._image=void 0,this.setGetFrameNameCallback(u(l,"getFrameNameCallback",void 0)),this.setStretchMode(u(l,"stretchMode",0)),this.setPreserveRatio(u(l,"preserveRatio",!0));var w=u(l,"maxFixedPartScale",1),p=u(l,"maxFixedPartScaleX",w),x=u(l,"maxFixedPartScaleY",void 0);this.setMaxFixedPartScale(p,x),this.setBaseTexture(a,o,h,d)}get minWidth(){return this.columns.minWidth}get minHeight(){return this.rows.minHeight}get fixedPartScaleX(){return this.columns.scale}get fixedPartScaleY(){return this.rows.scale}resize(t,e){return this.width===t&&this.height===e||(super.resize?super.resize(t,e):super.setSize(t,e),this.updateTexture()),this}get leftWidth(){return this.columns.data[0]}get rightWidth(){return this.columns.data[this.columns.count-1]}get topHeight(){return this.rows.data[0]}get bottomHeight(){return this.rows.data[this.rows.count-1]}}return Object.assign(i.prototype,h),i}(x,"rexNinePatch")){}var b={_drawImage:function(t,e,i,s,r,n){var a=p(this,"Image").setTexture(t,e).setDisplaySize(r,n);this.draw(a,i,s)},_drawTileSprite:function(t,e,i,s,r,n){var a=p(this,"TileSprite").setTexture(t,e).setSize(r,n);this.draw(a,i,s)}};function P(t,e,i,s,r,n,a,o,h){var c=new y(this.scene,t,e,i,s,r,n,a,o,h);return this.scene.add.existing(c),c}Object.assign(y.prototype,b);const S=Phaser.GameObjects.BuildGameObject;function F(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=new y(this.scene,t);return S(this.scene,i,t),i}var O=function(t){return null!==t&&"object"==typeof t};class j extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexNinePatch",P,F)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,i,s="."){if(!O(t))return t;if(function(t){return null==t}(e)||""===e||Array.isArray(e)&&0===e.length)return t;if("string"==typeof e&&-1===e.indexOf(s)||"number"==typeof e)return t[e]=i,t;var r=function(t,e){return Array.isArray(t)||(t="string"!=typeof t||""===t.trim()?[]:t.split(e).filter(Boolean)),t}(e,s);if(0===r.length)return t;for(var n=t,a=r.length,o=0;o<a-1;o++){var h=r[o],c=n[h];O(c)||(n[h]={}),n=n[h]}n[r[a-1]]=i}(window,"RexPlugins.GameObjects.NinePatch",y),j},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexninepatchplugin=e();