UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 3.03 kB
var t,e;t=void 0,e=function(){var t=function(t,e,i){for(var s,r=t.points,h=0,n=r.length;h<n;h++)(s=r[h]).x+=e,s.y+=i;return t};const e=Math.sqrt(3),i=Math.sqrt(3),s=Math.PI/180,r=Phaser.Geom.Polygon,h=Phaser.Utils.Objects.IsPlainObject,n=Phaser.Utils.Objects.GetValue,o=Phaser.Geom.Line;class y extends r{constructor(t,e,i,s){if(super(),h(t)){var r=t;t=n(r,"x",0),e=n(r,"y",0),i=n(r,"size",0),s=n(r,"type",1)}for(var o=this.points,y=0;y<6;y++)o.push({});this.setTo(t,e,i,s)}setTo(t,r,h,n){var o;return"string"==typeof n&&(n=g[n]),this._x=t,this._y=r,this._size=h,this._orientationType=n,function(t,e,i,r,h){if(void 0===h&&(h=function(t){for(var e=[],i=0;i<t;i++)e.push({x:0,y:0});return e}(6)),void 0===i);else if("number"==typeof i)for(var n,o=0===r?0:-30,y=0;y<6;y++)n=(60*y+o)*s,h[y].x=t+i*Math.cos(n),h[y].y=e+i*Math.sin(n);else{var g=i,u=g.width,a=g.height,x=u/2,p=u/4,d=a/2,f=a/4;0===r?(h[0].x=t+x,h[0].y=e,h[1].x=t+p,h[1].y=e+d,h[2].x=t-p,h[2].y=e+d,h[3].x=t-x,h[3].y=e,h[4].x=t-p,h[4].y=e-d,h[5].x=t+p,h[5].y=e-d):(h[0].x=t+x,h[0].y=e-f,h[1].x=t+x,h[1].y=e+f,h[2].x=t,h[2].y=e+d,h[3].x=t-x,h[3].y=e+f,h[4].x=t-x,h[4].y=e-f,h[5].x=t,h[5].y=e-d)}}(t,r,h,n,this.points),this.calculateArea(),this.width=0===(o=this).type?2*o.size:e*o.size,this.height=function(t){return 0===t.type?i*t.size:2*t.size}(this),this}get x(){return this._x}set x(e){var i=e-this.x;0!==i&&(t(this,i,0),this._x=e)}get y(){return this._y}set y(e){var i=e-this.y;0!==i&&(t(this,0,i),this._y=e)}get centerX(){return this.x}set centerX(t){this.x=t}get centerY(){return this.y}set centerY(t){this.y=t}setPosition(e,i){var s=e-this.x,r=i-this.y;return 0===s&&0===r||(t(this,s,r),this._x=e,this._y=i),this}get left(){return this.x-this.width/2}set left(t){this.x+=t-this.left}get right(){return this.x+this.width/2}set right(t){this.x+=t-this.right}get top(){return this.y-this.height/2}set top(t){this.y+=t-this.top}get bottom(){return this.y+this.height/2}set bottom(t){this.y+=t-this.bottom}get size(){return this._size}set size(t){this.setTo(this._x,this._y,t,this._orientationType)}setSize(t){return this.size=t,this}get orientationType(){return this._orientationType}set orientationType(t){this.setTo(this._x,this._y,this._size,t)}setType(t){this.orientationType=t}isEmpty(){return this.size<=0}getEdge(t,e){void 0===e&&(e=new o);var i=this.points[t],s=this.points[(t+1)%6];return e.setTo(i.x,i.y,s.x,s.y),e}getLineA(t){return this.getEdge(0,t)}getLineB(t){return this.getEdge(1,t)}getLineC(t){return this.getEdge(2,t)}getLineD(t){return this.getEdge(3,t)}getLineE(t){return this.getEdge(4,t)}getLineF(t){return this.getEdge(5,t)}}const g={flat:0,y:0,pointy:1,x:1};Phaser.Geom.rexHexagon=y;class u extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e,i,s){return new y(t,e,i,s)}}return u},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexhexagonplugin=e();