phaser4-rex-plugins
Version:
2 lines (1 loc) • 2.28 kB
JavaScript
var t,e;t=void 0,e=function(){var t=function(t,e,s){for(var i,h=t.points,r=0,n=h.length;r<n;r++)(i=h[r]).x+=e,i.y+=s;return t};const e=Phaser.Geom.Polygon,s=Phaser.Utils.Objects.IsPlainObject,i=Phaser.Utils.Objects.GetValue,h=Phaser.Geom.Line;class r extends e{constructor(t,e,h,r){if(super(),s(t)){var n=t;t=i(n,"x",0),e=i(n,"y",0),h=i(n,"width",0),r=i(n,"height",0)}for(var o=this.points,g=0;g<4;g++)o.push({});this.setTo(t,e,h,r)}setTo(t,e,s,i){this._x=t,this._y=e,this._width=s,this._height=i;var h=this.points,r=this.centerX,n=this.centerY,o=s/2,g=i/2;return h[0].x=r+o,h[0].y=n,h[1].x=r,h[1].y=n+g,h[2].x=r-o,h[2].y=n,h[3].x=r,h[3].y=n-g,this.calculateArea(),this}get x(){return this._x}set x(e){var s=e-this.x;0!==s&&(t(this,s,0),this._x=e)}get y(){return this._y}set y(e){var s=e-this.y;0!==s&&(t(this,0,s),this._y=e)}setPosition(e,s){var i=e-this.x,h=s-this.y;return 0===i&&0===h||(t(this,i,h),this._x=e,this._y=s),this}get left(){return this.x}set left(t){this.x+=t-this.left}get right(){return this.x+this.width}set right(t){this.x+=t-this.right}get top(){return this.y}set top(t){this.y+=t-this.top}get bottom(){return this.y+this.height}set bottom(t){this.y+=t-this.bottom}get centerX(){return this.x+this.width/2}set centerX(t){this.x+=t-this.centerX}get centerY(){return this.y+this.height/2}set centerY(t){this.y+=t-this.centetY}get width(){return this._width}set width(t){this.setTo(this._x,this._y,t,this._height)}get height(){return this._height}set height(t){this.setTo(this._x,this._y,this._width,t)}setSize(t,e){return this.setTo(this._x,this._y,t,e),this}isEmpty(){return this.width<=0||this.height<=0}getEdge(t,e){void 0===e&&(e=new h);var s=this.points[t],i=this.points[(t+1)%4];return e.setTo(s.x,s.y,i.x,i.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)}}Phaser.Geom.rexRhombus=r;class n extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e,s,i){return new r(t,e,s,i)}}return n},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexrhombusplugin=e();