UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 16.8 kB
!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).rexstatesroundrectangle=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(r=n.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(r,"string"))?s:String(s)),n);}var r,s;}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(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 s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function a(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function h(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 i,n=s(t);if(e){var r=s(this).constructor;i=Reflect.construct(n,arguments,r);}else i=n.apply(this,arguments);return function(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 a(t)}(this,i)}}var u=Phaser.Utils.Objects.GetValue,l=function(){function t(i,n,r,s,o){e(this,t),void 0===i&&(i=0),void 0===n&&(n=i),void 0===r&&(r=0),void 0===s&&(s=0),void 0===o&&(o=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(i,n,r,s,o);}return n(t,[{key:"setTo",value:function(t,e,i,n,r){return this.setPosition(t,e),this.setRadius(r),this.setSize(i,n),this}},{key:"setPosition",value:function(t,e){return this.x=t,this.y=e,this}},{key:"setRadius",value:function(t){return void 0===t&&(t=0),this.radius=t,this}},{key:"setSize",value:function(t,e){return this.width=t,this.height=e,this}},{key:"minWidth",get:function(){var t=this.cornerRadius;return Math.max(t.tl.x+t.tr.x,t.bl.x+t.br.x)}},{key:"minHeight",get:function(){var t=this.cornerRadius;return Math.max(t.tl.y+t.bl.y,t.tr.y+t.br.y)}},{key:"width",get:function(){return this._width},set:function(t){null==t&&(t=0),this._width=Math.max(t,this.minWidth);}},{key:"height",get:function(){return this._height},set:function(t){null==t&&(t=0),this._height=Math.max(t,this.minHeight);}},{key:"radius",get:function(){var t=this.cornerRadius;return Math.max(t.tl.x,t.tl.y,t.tr.x,t.tr.y,t.bl.x,t.bl.y,t.br.x,t.br.y)},set:function(t){var e,i;"number"==typeof t?(e=t,i=t):(e=u(t,"x",0),i=u(t,"y",0));var n=this.cornerRadius;n.tl=c(u(t,"tl",void 0),e,i),n.tr=c(u(t,"tr",void 0),e,i),n.bl=c(u(t,"bl",void 0),e,i),n.br=c(u(t,"br",void 0),e,i);}},{key:"radiusTL",get:function(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)},set:function(t){f(this.cornerRadius.tl,t);}},{key:"radiusTR",get:function(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)},set:function(t){f(this.cornerRadius.tr,t);}},{key:"radiusBL",get:function(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)},set:function(t){f(this.cornerRadius.bl,t);}},{key:"radiusBR",get:function(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)},set:function(t){f(this.cornerRadius.br,t);}}]),t}(),c=function(t,e,i){return void 0===t?t={x:e,y:i}:"number"==typeof t&&(t={x:t,y:t}),y(t),t},f=function(t,e){"number"==typeof e?(t.x=e,t.y=e):(t.x=u(e,"x",0),t.y=u(e,"y",0)),y(t);},y=function(t){t.convex=t.x>=0||t.y>=0,t.x=Math.abs(t.x),t.y=Math.abs(t.y);},d=function(t,e,i){var n=i.length;if(n>=2){var r=i[n-2],s=i[n-1];if(t===r&&e===s)return i}return i.push(t,e),i},v=Phaser.Math.DegToRad,p=function(t,e,i,n,r,s,o,a,h){o&&s>r?s-=360:!o&&s<r&&(s+=360);var u=v(s-r)/a;r=v(r);for(var l=0;l<=a;l++){var c=r+u*l,f=t+i*Math.cos(c),y=e+n*Math.sin(c);d(f,y,h);}return h},m=Phaser.Renderer.WebGL.Utils,g=Phaser.Renderer.WebGL.Utils,b=Phaser.GameObjects.GetCalcMatrix,k=Phaser.Renderer.Canvas.SetTransform,_={renderWebGL:function(t,e,i,n){e.dirty&&(e.updateData(),e.dirty=!1),i.addToRenderList(e);var r=t.pipelines.set(e.pipeline),s=b(e,i,n),o=r.calcMatrix.copyFrom(s.calc),a=e._displayOriginX,h=e._displayOriginY,u=i.alpha*e.alpha;t.pipelines.preBatch(e),e.isFilled&&function(t,e,i,n,r,s){for(var o=m.getTintAppendFloatAlpha(i.fillColor,i.fillAlpha*n),a=i.pathData,h=i.pathIndexes,u=0;u<h.length;u+=3){var l=2*h[u],c=2*h[u+1],f=2*h[u+2],y=a[l+0]-r,d=a[l+1]-s,v=a[c+0]-r,p=a[c+1]-s,g=a[f+0]-r,b=a[f+1]-s,k=e.getX(y,d),_=e.getY(y,d),S=e.getX(v,p),E=e.getY(v,p),x=e.getX(g,b),R=e.getY(g,b);t.batchTri(i,k,_,S,E,x,R,0,0,1,1,o,o,o,2);}}(r,o,e,u,a,h),e.isStroked&&function(t,e,i,n,r){var s=t.strokeTint,o=g.getTintAppendFloatAlpha(e.strokeColor,e.strokeAlpha*i);s.TL=o,s.TR=o,s.BL=o,s.BR=o;var a=e.pathData,h=a.length-1,u=e.lineWidth,l=u/2,c=a[0]-n,f=a[1]-r;e.closePath||(h-=2);for(var y=2;y<h;y+=2){var d=a[y]-n,v=a[y+1]-r;t.batchLine(c,f,d,v,l,l,u,y-2,!!e.closePath&&y===h-1),c=d,f=v;}}(r,e,u,a,h),t.pipelines.postBatch(e);},renderCanvas:function(t,e,i,n){e.dirty&&(e.updateData(),e.dirty=!1),i.addToRenderList(e);var r=t.currentContext;if(k(t,r,e,i,n)){var s=e._displayOriginX,o=e._displayOriginY,a=e.pathData,h=a.length-1,u=a[0]-s,l=a[1]-o;r.beginPath(),r.moveTo(u,l),e.closePath||(h-=2);for(var c=2;c<h;c+=2){var f=a[c]-s,y=a[c+1]-o;r.lineTo(f,y);}r.closePath(),e.isFilled&&(!function(t,e,i,n){var r=i||e.fillColor,s=n||e.fillAlpha,o=(16711680&r)>>>16,a=(65280&r)>>>8,h=255&r;t.fillStyle="rgba("+o+","+a+","+h+","+s+")";}(r,e),r.fill()),e.isStroked&&(!function(t,e,i,n){var r=i||e.strokeColor,s=n||e.strokeAlpha,o=(16711680&r)>>>16,a=(65280&r)>>>8,h=255&r;t.strokeStyle="rgba("+o+","+a+","+h+","+s+")",t.lineWidth=e.lineWidth;}(r,e),r.stroke()),r.restore();}}},S=Phaser.GameObjects.Shape,E=Phaser.Utils.Objects.IsPlainObject,x=Phaser.Utils.Objects.GetValue,R=Phaser.Geom.Polygon.Earcut,P=function(t){r(s,t);var i=h(s);function s(t,n,r,o,a,h,u,c){var f,y,d,v,p;if(e(this,s),E(n)){var m=n;n=m.x,r=m.y,o=m.width,a=m.height,h=m.radius,u=m.color,c=m.alpha,y=m.strokeColor,d=m.strokeAlpha,v=m.strokeWidth,p=m.shape;}void 0===n&&(n=0),void 0===r&&(r=0),void 0===o&&(o=1),void 0===a&&(a=o),void 0===h&&(h=0),void 0===p&&(p=0);var g=new l;if((f=i.call(this,t,"rexRoundRectangleShape",g)).setShapeType(p),0===f.shapeType){var b=x(h,"radius",h);g.setTo(0,0,o,a,b);}else {b={x:o/2,y:a/2};g.setTo(0,0,o,a,b);}var k=x(h,"iteration",void 0);return f.setIteration(k),f.setPosition(n,r),f.setFillStyle(u,c),void 0!==y&&void 0===v&&(v=2),f.setStrokeStyle(v,y,d),f.updateDisplayOrigin(),f.dirty=!0,f}return n(s,[{key:"fillColor",get:function(){return this._fillColor},set:function(t){this._fillColor=t,this.isFilled=null!=t&&this._fillAlpha>0;}},{key:"fillAlpha",get:function(){return this._fillAlpha},set:function(t){this._fillAlpha=t,this.isFilled=t>0&&null!=this._fillColor;}},{key:"setFillStyle",value:function(t,e){return void 0===e&&(e=1),this.fillColor=t,this.fillAlpha=e,this}},{key:"strokeColor",get:function(){return this._strokeColor},set:function(t){this._strokeColor=t,this.isStroked=null!=t&&this._strokeAlpha>0&&this._lineWidth>0;}},{key:"strokeAlpha",get:function(){return this._strokeAlpha},set:function(t){this._strokeAlpha=t,this.isStroked=t>0&&null!=this._strokeColor&&this._lineWidth>0;}},{key:"lineWidth",get:function(){return this._lineWidth},set:function(t){this._lineWidth=t,this.isStroked=t>0&&null!=this._strokeColor;}},{key:"setStrokeStyle",value:function(t,e,i){return void 0===i&&(i=1),this.lineWidth=t,this.strokeColor=e,this.strokeAlpha=i,this}},{key:"updateData",value:function(){var t=this.geom,e=this.pathData;e.length=0;var i,n=t.width,r=t.height,s=t.cornerRadius,o=this.iteration+1;if(i=s.tl,w(i))if(i.convex){var a=i.x,h=i.y;p(a,h,i.x,i.y,180,270,!1,o,e);}else {p(a=0,h=0,i.x,i.y,90,0,!0,o,e);}else d(0,0,e);if(i=s.tr,w(i))if(i.convex){a=n-i.x,h=i.y;p(a,h,i.x,i.y,270,360,!1,o,e);}else {p(a=n,h=0,i.x,i.y,180,90,!0,o,e);}else d(n,0,e);if(i=s.br,w(i))if(i.convex){a=n-i.x,h=r-i.y;p(a,h,i.x,i.y,0,90,!1,o,e);}else {p(a=n,h=r,i.x,i.y,270,180,!0,o,e);}else d(n,r,e);if(i=s.bl,w(i))if(i.convex){a=i.x,h=r-i.y;p(a,h,i.x,i.y,90,180,!1,o,e);}else {p(a=0,h=r,i.x,i.y,360,270,!0,o,e);}else d(0,r,e);return e.push(e[0],e[1]),this.pathIndexes=R(e),this}},{key:"setShapeType",value:function(t){return "string"==typeof t&&(t=T[t]),this.shapeType=t,this}},{key:"width",get:function(){return this.geom.width},set:function(t){this.resize(t,this.height);}},{key:"height",get:function(){return this.geom.height},set:function(t){this.resize(this.width,t);}},{key:"setSize",value:function(t,e){if(void 0===e&&(e=t),this.geom.width===t&&this.geom.height===e)return this;this.geom.setSize(t,e),1===this.shapeType&&this.setRadius({x:t/2,y:e/2}),this.updateDisplayOrigin(),this.dirty=!0;var i=this.input;return i&&!i.customHitArea&&(i.hitArea.width=t,i.hitArea.height=e),this}},{key:"resize",value:function(t,e){return this.setSize(t,e),this}},{key:"radius",get:function(){return this.geom.radius},set:function(t){this.geom.setRadius(t),this.updateDisplayOrigin(),this.dirty=!0;}},{key:"radiusTL",get:function(){return this.geom.radiusTL},set:function(t){this.geom.radiusTL=t,this.dirty=!0;}},{key:"radiusTR",get:function(){return this.geom.radiusTR},set:function(t){this.geom.radiusTR=t,this.dirty=!0;}},{key:"radiusBL",get:function(){return this.geom.radiusBL},set:function(t){this.geom.radiusBL=t,this.dirty=!0;}},{key:"radiusBR",get:function(){return this.geom.radiusBR},set:function(t){this.geom.radiusBR=t,this.dirty=!0;}},{key:"setRadius",value:function(t){return void 0===t&&(t=0),this.radius=t,this}},{key:"setRadiusTL",value:function(t){return void 0===t&&(t=0),this.radiusTL=t,this}},{key:"setRadiusTR",value:function(t){return void 0===t&&(t=0),this.radiusTR=t,this}},{key:"setRadiusBL",value:function(t){return void 0===t&&(t=0),this.radiusBL=t,this}},{key:"setRadiusBR",value:function(t){return void 0===t&&(t=0),this.radiusBR=t,this}},{key:"cornerRadius",get:function(){return this.geom.cornerRadius},set:function(t){this.radius=t;}},{key:"setCornerRadius",value:function(t){return this.setRadius(t)}},{key:"iteration",get:function(){return this._iteration},set:function(t){void 0!==this._iteration?this._iteration!==t&&(this._iteration=t,this.dirty=!0):this._iteration=t;}},{key:"setIteration",value:function(t){return void 0===t&&(t=6),this.iteration=t,this}}]),s}(S),w=function(t){return t.x>0&&t.y>0},T={rectangle:0,circle:1};Object.assign(P.prototype,_);var O={setEventEmitter:function(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},A=Phaser.Scene,M=function(t){return t instanceof A},j=Phaser.Game,L=function(t){return t instanceof j},C=Phaser.Utils.Objects.GetValue,D=function(){function i(t,n){e(this,i),this.setParent(t),this.isShutdown=!1,this.setEventEmitter(C(n,"eventEmitter",!0)),this.parent&&(this.parent===this.scene?this.scene.sys.events.once("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.once("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.once("destroy",this.onParentDestroy,this));}return n(i,[{key:"shutdown",value:function(t){this.isShutdown||(this.parent&&(this.parent===this.scene?this.scene.sys.events.off("shutdown",this.onEnvDestroy,this):this.parent===this.game?this.game.events.off("shutdown",this.onEnvDestroy,this):this.parent.once&&this.parent.off("destroy",this.onParentDestroy,this)),this.destroyEventEmitter(),this.parent=void 0,this.scene=void 0,this.game=void 0,this.isShutdown=!0);}},{key:"destroy",value:function(t){this.shutdown(t);}},{key:"onEnvDestroy",value:function(){this.destroy(!0);}},{key:"onParentDestroy",value:function(t,e){this.destroy(e);}},{key:"setParent",value:function(e){var i;return this.parent=e,this.scene=null==(i=e)||"object"!==t(i)?null:M(i)?i:i.scene&&M(i.scene)?i.scene:i.parent&&i.parent.scene&&M(i.parent.scene)?i.parent.scene:null,this.game=function(e){return null==e||"object"!==t(e)?null:L(e)?e:L(e.game)?e.game:M(e)?e.sys.game:M(e.scene)?e.scene.sys.game:void 0}(e),this}}]),i}();Object.assign(D.prototype,O);var B=Phaser.Utils.Objects.GetValue,W=function(t){r(s,t);var i=h(s);function s(t,n){var r;e(this,s),(r=i.call(this,t,n)).style=B(n,"style",a(r));var o=B(n,"propertiesMap");return r.activeStyle=G(n,"active",o),r.hoverStyle=G(n,"hover",o),r.disableStyle=G(n,"disable",o),r.onModifyStyle=B(n,"onModifyStyle"),r}return n(s,[{key:"getStyle",value:function(t){return function(t,e,i){if(void 0===i&&(i={}),Array.isArray(e))for(var n=0,r=e.length;n<r;n++)i[s=e[n]]=t[s];else for(var s in e)i[s]=t[s];return i}(this.style,t)}},{key:"modifyStyle",value:function(t){for(var e in t)this.style[e]=t[e];return this.onModifyStyle&&this.onModifyStyle(this.parent,t),this}},{key:"applyStyle",value:function(t){if(t){var e=this.getStyle(t);return function(t,e){for(var i in t){if(!(i in e))return !1;if(t[i]!==e[i])return !1}for(var i in e)if(!(i in t))return !1;return !0}(e,t)?void 0:(this.modifyStyle(t),e)}}},{key:"setActiveState",value:function(t){return F.call(this,"active",t),this}},{key:"setHoverState",value:function(t){return F.call(this,"hover",t),this}},{key:"setDisableState",value:function(t){return F.call(this,"disable",t),this}}]),s}(D),G=function(t,e,i){var n=function(t,e,i,n){if(void 0===i&&(i="."),void 0===n&&(n={}),!t)return n;if(e in t)return Object.assign(n,t[e]);for(var r in e+=i,t)r.startsWith(e)&&(n[r.replace(e,"")]=t[r]);return n}(t,e);if(i)for(var r in n)i.hasOwnProperty(r)&&(n[i[r]]=n[r],delete n[r]);return n},F=function(t,e){void 0===e&&(e=!0);var i="".concat(t,"State"),n="".concat(t,"Style"),r="".concat(t,"StyleSave");this[i]!==e&&(this[i]=e,e?this[r]=this.applyStyle(this[n]):(this.applyStyle(this[r]),this[r]=void 0));},z={addStyleManager:function(t){return this.styleManager=new W(this,t),this},setActiveState:function(t){return this.styleManager.setActiveState(t),this},setHoverState:function(t){return this.styleManager.setHoverState(t),this},setDisableState:function(t){return this.styleManager.setDisableState(t),this}},U=function(t){r(s,t);var i=h(s);function s(t,n){var r;return e(this,s),void 0===n&&(n={}),(r=i.call(this,t,n)).type="rexStatesRoundRectangleShape",n.style=a(r),n.propertiesMap=H,r.addStyleManager(n),delete n.style,delete n.propertiesMap,r}return n(s)}(P),H={color:"fillColor",alpha:"fillAlpha",strokeWidth:"lineWidth"};return Object.assign(U.prototype,z),U}));