phaser4-rex-plugins
Version:
2 lines (1 loc) • 1.71 kB
JavaScript
var e,t;e=void 0,t=function(){const e=Phaser.Utils.Objects.GetValue,t=Phaser.GameObjects.Image,r=Phaser.Utils.Objects.IsPlainObject,a=Phaser.Math.RotateAround;class o extends Phaser.Plugins.BasePlugin{constructor(e){super(e)}start(){this.game.events.on("destroy",this.destroy,this)}gridCut(o,n,s,i){return function(o,n,s,i){r(n)&&(n=e(i=n,"columns",1),s=e(i,"rows",1));var l=e(i,"createImageCallback");if(!l){var c=e(i,"ImageClass",t);l=function(e,t,r){return new c(e,0,0,t,r)}}for(var u=e(i,"originX",.5),d=e(i,"originY",.5),f=e(i,"add",!0),g=e(i,"align",f),h=e(i,"objectPool",void 0),m=o.scene,p=o.texture,v=function(e,t,r,a,o,n){var s,i;null==r&&(r="__BASE"),n||(i=n,"object"==typeof(s=r)&&(s=s.name),void 0===i&&(i=","),n="__BASE"===s?function(e,t){return`${e}${i}${t}`}:function(e,t){return`${s}_${e}${i}${t}`});for(var l,c,u,d=e.sys.textures.get(t),f="object"==typeof r?r:d.get(r),g=f.width/a,h=f.height/o,m=f.cutX,p=f.cutY,v=0,b=0,y=0;y<o;y++){v=0;for(var P=0;P<a;P++)u=n(P,y),l=v+m,c=b+p,d.add(u,0,l,c,g,h),v+=g;b+=h}return{getFrameNameCallback:n,cellWidth:g,cellHeight:h,columns:a,rows:o}}(m,p,o.frame,n,s),b=v.getFrameNameCallback,y=o.scaleX,P=o.scaleY,x=o.rotation,j=o.getTopLeft(),$=j.x,C=j.y,O=[],_=v.cellWidth*y,w=v.cellHeight*P,I=0;I<s;I++)for(var T=0;T<n;T++){var k,A=b(T,I);if(k=h&&h.length>0?h.pop().setTexture(p,A):l(m,p,A),f&&m.add.existing(k),g){var B=$+_*T+u*_,S=C+w*I+d*w;k.setOrigin(u,d).setPosition(B,S).setScale(y,P).setRotation(x),a(k,$,C,x)}O.push(k)}return O}(o,n,s,i)}}return o},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexgridcutimageplugin=t();