phaser3-rex-plugins
Version:
2 lines (1 loc) • 4.86 kB
JavaScript
!function(t,e){"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();}(undefined,(function(){function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,(r=i.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(r,"string"))?o:String(o)),i);}var r,o;}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t}function i(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e);}function r(t){return r=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},r(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function s(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function u(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var n,i=r(t);if(e){var o=r(this).constructor;n=Reflect.construct(i,arguments,o);}else n=i.apply(this,arguments);return s(this,n)}}var h=function(t,e,n){for(var i,r=t.points,o=0,s=r.length;o<s;o++)(i=r[o]).x+=e,i.y+=n;return t},c=Phaser.Geom.Polygon,f=Phaser.Utils.Objects.IsPlainObject,y=Phaser.Utils.Objects.GetValue,a=Phaser.Geom.Line,l=function(e){i(o,e);var r=u(o);function o(e,n,i,s){var u;if(t(this,o),u=r.call(this),f(e)){var h=e;e=y(h,"x",0),n=y(h,"y",0),i=y(h,"width",0),s=y(h,"height",0);}for(var c=u.points,a=0;a<4;a++)c.push({});return u.setTo(e,n,i,s),u}return n(o,[{key:"setTo",value:function(t,e,n,i){this._x=t,this._y=e,this._width=n,this._height=i;var r=this.points,o=this.centerX,s=this.centerY,u=n/2,h=i/2;return r[0].x=o+u,r[0].y=s,r[1].x=o,r[1].y=s+h,r[2].x=o-u,r[2].y=s,r[3].x=o,r[3].y=s-h,this.calculateArea(),this}},{key:"x",get:function(){return this._x},set:function(t){var e=t-this.x;0!==e&&(h(this,e,0),this._x=t);}},{key:"y",get:function(){return this._y},set:function(t){var e=t-this.y;0!==e&&(h(this,0,e),this._y=t);}},{key:"setPosition",value:function(t,e){var n=t-this.x,i=e-this.y;return 0===n&&0===i||(h(this,n,i),this._x=t,this._y=e),this}},{key:"left",get:function(){return this.x},set:function(t){this.x+=t-this.left;}},{key:"right",get:function(){return this.x+this.width},set:function(t){this.x+=t-this.right;}},{key:"top",get:function(){return this.y},set:function(t){this.y+=t-this.top;}},{key:"bottom",get:function(){return this.y+this.height},set:function(t){this.y+=t-this.bottom;}},{key:"centerX",get:function(){return this.x+this.width/2},set:function(t){this.x+=t-this.centerX;}},{key:"centerY",get:function(){return this.y+this.height/2},set:function(t){this.y+=t-this.centetY;}},{key:"width",get:function(){return this._width},set:function(t){this.setTo(this._x,this._y,t,this._height);}},{key:"height",get:function(){return this._height},set:function(t){this.setTo(this._x,this._y,this._width,t);}},{key:"setSize",value:function(t,e){return this.setTo(this._x,this._y,t,e),this}},{key:"isEmpty",value:function(){return this.width<=0||this.height<=0}},{key:"getEdge",value:function(t,e){void 0===e&&(e=new a);var n=this.points[t],i=this.points[(t+1)%4];return e.setTo(n.x,n.y,i.x,i.y),e}},{key:"getLineA",value:function(t){return this.getEdge(0,t)}},{key:"getLineB",value:function(t){return this.getEdge(1,t)}},{key:"getLineC",value:function(t){return this.getEdge(2,t)}},{key:"getLineD",value:function(t){return this.getEdge(3,t)}}]),o}(c);return Phaser.Geom.rexRhombus=l,function(e){i(o,Phaser.Plugins.BasePlugin);var r=u(o);function o(e){return t(this,o),r.call(this,e)}return n(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e,n,i){return new l(t,e,n,i)}}]),o}()}));