phaser3-rex-plugins
Version:
2 lines (1 loc) • 5.67 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).rexhexagonplugin=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 f=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=Math.sqrt(3),h=Math.sqrt(3),y=Math.PI/180,a=Phaser.Geom.Polygon,l=Phaser.Utils.Objects.IsPlainObject,p=Phaser.Utils.Objects.GetValue,g=Phaser.Geom.Line,v=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),l(e)){var f=e;e=p(f,"x",0),n=p(f,"y",0),i=p(f,"size",0),s=p(f,"type",1);}for(var c=u.points,h=0;h<6;h++)c.push({});return u.setTo(e,n,i,s),u}return n(o,[{key:"setTo",value:function(t,e,n,i){var r;return "string"==typeof i&&(i=d[i]),this._x=t,this._y=e,this._size=n,this._orientationType=i,function(t,e,n,i,r){if(void 0===r&&(r=function(t){for(var e=[],n=0;n<t;n++)e.push({x:0,y:0});return e}(6)),void 0===n);else if("number"==typeof n)for(var o,s=0===i?0:-30,u=0;u<6;u++)o=(60*u+s)*y,r[u].x=t+n*Math.cos(o),r[u].y=e+n*Math.sin(o);else {var f=n,c=f.width,h=f.height,a=c/2,l=c/4,p=h/2,g=h/4;0===i?(r[0].x=t+a,r[0].y=e,r[1].x=t+l,r[1].y=e+p,r[2].x=t-l,r[2].y=e+p,r[3].x=t-a,r[3].y=e,r[4].x=t-l,r[4].y=e-p,r[5].x=t+l,r[5].y=e-p):(r[0].x=t+a,r[0].y=e-g,r[1].x=t+a,r[1].y=e+g,r[2].x=t,r[2].y=e+p,r[3].x=t-a,r[3].y=e+g,r[4].x=t-a,r[4].y=e-g,r[5].x=t,r[5].y=e-p);}}(t,e,n,i,this.points),this.calculateArea(),this.width=0===(r=this).type?2*r.size:c*r.size,this.height=function(t){return 0===t.type?h*t.size:2*t.size}(this),this}},{key:"x",get:function(){return this._x},set:function(t){var e=t-this.x;0!==e&&(f(this,e,0),this._x=t);}},{key:"y",get:function(){return this._y},set:function(t){var e=t-this.y;0!==e&&(f(this,0,e),this._y=t);}},{key:"centerX",get:function(){return this.x},set:function(t){this.x=t;}},{key:"centerY",get:function(){return this.y},set:function(t){this.y=t;}},{key:"setPosition",value:function(t,e){var n=t-this.x,i=e-this.y;return 0===n&&0===i||(f(this,n,i),this._x=t,this._y=e),this}},{key:"left",get:function(){return this.x-this.width/2},set:function(t){this.x+=t-this.left;}},{key:"right",get:function(){return this.x+this.width/2},set:function(t){this.x+=t-this.right;}},{key:"top",get:function(){return this.y-this.height/2},set:function(t){this.y+=t-this.top;}},{key:"bottom",get:function(){return this.y+this.height/2},set:function(t){this.y+=t-this.bottom;}},{key:"size",get:function(){return this._size},set:function(t){this.setTo(this._x,this._y,t,this._orientationType);}},{key:"setSize",value:function(t){return this.size=t,this}},{key:"orientationType",get:function(){return this._orientationType},set:function(t){this.setTo(this._x,this._y,this._size,t);}},{key:"setType",value:function(t){this.orientationType=t;}},{key:"isEmpty",value:function(){return this.size<=0}},{key:"getEdge",value:function(t,e){void 0===e&&(e=new g);var n=this.points[t],i=this.points[(t+1)%6];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)}},{key:"getLineE",value:function(t){return this.getEdge(4,t)}},{key:"getLineF",value:function(t){return this.getEdge(5,t)}}]),o}(a),d={flat:0,y:0,pointy:1,x:1};return Phaser.Geom.rexHexagon=v,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 v(t,e,n,i)}}]),o}()}));