UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 13.1 kB
var t,e;t=void 0,e=function(){var t=Phaser.Renderer.WebGL.Utils,e=Phaser.Renderer.WebGL.Utils;const i=Phaser.GameObjects.GetCalcMatrix,s=Phaser.Renderer.Canvas.SetTransform;var r={renderWebGL:function(s,r,n,h){r.dirty&&(r.updateData(),r.dirty=!1);var a=n.camera;a.addToRenderList(r);var o=i(r,a,h,!n.useCanvas).calc,l=r._displayOriginX,d=r._displayOriginY,u=r.alpha,v=r.customRenderNodes.Submitter||r.defaultRenderNodes.Submitter;r.isFilled&&function(e,i,s,r,n,h,a,o){var l,d,u,v,y,p=t.getTintAppendFloatAlpha(n.fillColor,n.fillAlpha*h),c=n.pathData,m=n.pathIndexes,g=c.length,f=Array(2*g),_=Array(g),x=0,S=0;for(l=0;l<g;l+=2)d=c[l]-a,u=c[l+1]-o,v=s.getX(d,u),y=s.getY(d,u),f[x++]=v,f[x++]=y,_[S++]=p;i.batch(e,m,f,_)}(n,v,o,0,r,u,l,d),r.isStroked&&function(t,i,s,r,n,h,a,o){var l=e.getTintAppendFloatAlpha(n.strokeColor,n.strokeAlpha*h),d=n.pathData,u=d.length-1,v=n.lineWidth,y=!n.closePath,p=r.customRenderNodes.StrokePath||r.defaultRenderNodes.StrokePath,c=[];y&&(u-=2);for(var m=0;m<u;m+=2){var g=d[m]-a,f=d[m+1]-o;m>0&&g===d[m-2]&&f===d[m-1]||c.push({x:g,y:f,width:v})}p.run(t,i,c,v,y,s,l,l,l,l)}(n,v,o,r,r,u,l,d)},renderCanvas:function(t,e,i,r){e.dirty&&(e.updateData(),e.dirty=!1),i.addToRenderList(e);var n=t.currentContext;if(s(t,n,e,i,r)){var h=e._displayOriginX,a=e._displayOriginY,o=e.pathData,l=o.length-1,d=o[0]-h,u=o[1]-a;n.beginPath(),n.moveTo(d,u),e.closePath||(l-=2);for(var v=2;v<l;v+=2){var y=o[v]-h,p=o[v+1]-a;n.lineTo(y,p)}n.closePath(),e.isFilled&&(function(t,e,i,s){var r=i||e.fillColor,n=s||e.fillAlpha,h=(16711680&r)>>>16,a=(65280&r)>>>8,o=255&r;t.fillStyle="rgba("+h+","+a+","+o+","+n+")"}(n,e),n.fill()),e.isStroked&&(function(t,e,i,s){var r=i||e.strokeColor,n=s||e.strokeAlpha,h=(16711680&r)>>>16,a=(65280&r)>>>8,o=255&r;t.strokeStyle="rgba("+h+","+a+","+o+","+n+")",t.lineWidth=e.lineWidth}(n,e),n.stroke()),n.restore()}}};const n=Phaser.GameObjects.Shape;class h extends n{get fillColor(){return this._fillColor}set fillColor(t){this._fillColor=t,this.isFilled=null!=t&&this._fillAlpha>0}get fillAlpha(){return this._fillAlpha}set fillAlpha(t){this._fillAlpha=t,this.isFilled=t>0&&null!=this._fillColor}setFillStyle(t,e){return void 0===e&&(e=1),this.fillColor=t,this.fillAlpha=e,this}get strokeColor(){return this._strokeColor}set strokeColor(t){this._strokeColor=t,this.isStroked=null!=t&&this._strokeAlpha>0&&this._lineWidth>0}get strokeAlpha(){return this._strokeAlpha}set strokeAlpha(t){this._strokeAlpha=t,this.isStroked=t>0&&null!=this._strokeColor&&this._lineWidth>0}get lineWidth(){return this._lineWidth}set lineWidth(t){this._lineWidth=t,this.isStroked=t>0&&null!=this._strokeColor}setStrokeStyle(t,e,i){return void 0===i&&(i=1),this.lineWidth=t,this.strokeColor=e,this.strokeAlpha=i,this}updateData(){return this}get width(){return this.geom.width}set width(t){this.resize(t,this.height)}get height(){return this.geom.height}set height(t){this.resize(this.width,t)}setSize(t,e){var i=this.input;return i&&!i.customHitArea&&(i.hitArea.width=t,i.hitArea.height=e),this}resize(t,e){return this.setSize(t,e),this}}Object.assign(h.prototype,r);const a=Phaser.Utils.Objects.GetValue;let o=class{constructor(t,e,i,s,r){void 0===t&&(t=0),void 0===e&&(e=t),void 0===i&&(i=0),void 0===s&&(s=0),void 0===r&&(r=0),this.cornerRadius={},this._width=0,this._height=0,this.setTo(t,e,i,s,r)}setTo(t,e,i,s,r){return this.setPosition(t,e),this.setRadius(r),this.setSize(i,s),this}setPosition(t,e){return this.x=t,this.y=e,this}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setSize(t,e){return this.width=t,this.height=e,this}get minWidth(){var t=this.cornerRadius;return Math.max(t.tl.x+t.tr.x,t.bl.x+t.br.x)}get minHeight(){var t=this.cornerRadius;return Math.max(t.tl.y+t.bl.y,t.tr.y+t.br.y)}get width(){return this._width}set width(t){null==t&&(t=0),this._width=Math.max(t,this.minWidth)}get height(){return this._height}set height(t){null==t&&(t=0),this._height=Math.max(t,this.minHeight)}get radius(){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 radius(t){var e,i;"number"==typeof t?(e=t,i=t):(e=a(t,"x",0),i=a(t,"y",0));var s=this.cornerRadius;s.tl=l(a(t,"tl",void 0),e,i),s.tr=l(a(t,"tr",void 0),e,i),s.bl=l(a(t,"bl",void 0),e,i),s.br=l(a(t,"br",void 0),e,i)}get radiusTL(){var t=this.cornerRadius.tl;return Math.max(t.x,t.y)}set radiusTL(t){d(this.cornerRadius.tl,t)}get radiusTR(){var t=this.cornerRadius.tr;return Math.max(t.x,t.y)}set radiusTR(t){d(this.cornerRadius.tr,t)}get radiusBL(){var t=this.cornerRadius.bl;return Math.max(t.x,t.y)}set radiusBL(t){d(this.cornerRadius.bl,t)}get radiusBR(){var t=this.cornerRadius.br;return Math.max(t.x,t.y)}set radiusBR(t){d(this.cornerRadius.br,t)}};var l=function(t,e,i){return void 0===t?t={x:e,y:i}:"number"==typeof t&&(t={x:t,y:t}),u(t),t},d=function(t,e){"number"==typeof e?(t.x=e,t.y=e):(t.x=a(e,"x",0),t.y=a(e,"y",0)),u(t)},u=function(t){t.convex=t.x>=0||t.y>=0,t.x=Math.abs(t.x),t.y=Math.abs(t.y)},v=function(t){return t.x>0&&t.y>0},y=function(t,e,i){var s=i.length;if(s>=2){var r=i[s-2],n=i[s-1];if(t===r&&e===n)return i}return i.push(t,e),i};const p=Phaser.Math.DegToRad;var c=function(t,e,i,s,r,n,h,a,o){h&&n>r?n-=360:!h&&n<r&&(n+=360);var l=p(n-r)/a;r=p(r);for(var d=0;d<=a;d++){var u=r+l*d,v=t+i*Math.cos(u),c=e+s*Math.sin(u);y(v,c,o)}return o};const m=Phaser.Utils.Objects.IsPlainObject,g=Phaser.Utils.Objects.GetValue,f=Phaser.Geom.Polygon.Earcut;class _ extends h{constructor(t,e,i,s,r,n,h,a){var l,d,u,v;if(m(e)){var y=e;e=y.x,i=y.y,s=y.width,r=y.height,n=y.radius,h=y.color,a=y.alpha,l=y.strokeColor,d=y.strokeAlpha,u=y.strokeWidth,v=y.shape}void 0===e&&(e=0),void 0===i&&(i=0),void 0===s&&(s=1),void 0===r&&(r=s),void 0===n&&(n=0),void 0===v&&(v=0);var p=new o;if(super(t,"rexRoundRectangleShape",p),this.setShapeType(v),0===this.shapeType){var c=g(n,"radius",n);p.setTo(0,0,s,r,c)}else c={x:s/2,y:r/2},p.setTo(0,0,s,r,c);this.setIteration(g(n,"iteration",void 0)),this.setPosition(e,i),this.setFillStyle(h,a),void 0===u&&(u=2),this.setStrokeStyle(u,l,d),this.updateDisplayOrigin(),this.dirty=!0}updateData(){var t=this.geom,e=this.pathData;e.length=0;var i,s=t.width,r=t.height,n=t.cornerRadius,h=this.iteration+1;if(i=n.tl,v(i))if(i.convex){var a=i.x,o=i.y;c(a,o,i.x,i.y,180,270,!1,h,e)}else c(a=0,o=0,i.x,i.y,90,0,!0,h,e);else y(0,0,e);return i=n.tr,v(i)?i.convex?(a=s-i.x,o=i.y,c(a,o,i.x,i.y,270,360,!1,h,e)):c(a=s,o=0,i.x,i.y,180,90,!0,h,e):y(s,0,e),i=n.br,v(i)?i.convex?(a=s-i.x,o=r-i.y,c(a,o,i.x,i.y,0,90,!1,h,e)):c(a=s,o=r,i.x,i.y,270,180,!0,h,e):y(s,r,e),i=n.bl,v(i)?i.convex?(a=i.x,o=r-i.y,c(a,o,i.x,i.y,90,180,!1,h,e)):c(a=0,o=r,i.x,i.y,360,270,!0,h,e):y(0,r,e),e.push(e[0],e[1]),this.pathIndexes=f(e),this}setShapeType(t){return"string"==typeof t&&(t=x[t]),this.shapeType=t,this}setSize(t,e){return void 0===e&&(e=t),this.geom.width===t&&this.geom.height===e||(this.geom.setSize(t,e),1===this.shapeType&&this.setRadius({x:t/2,y:e/2}),this.updateDisplayOrigin(),this.dirty=!0,super.setSize(t,e)),this}get radius(){return this.geom.radius}set radius(t){this.geom.setRadius(t),this.updateDisplayOrigin(),this.dirty=!0}get radiusTL(){return this.geom.radiusTL}set radiusTL(t){this.geom.radiusTL=t,this.dirty=!0}get radiusTR(){return this.geom.radiusTR}set radiusTR(t){this.geom.radiusTR=t,this.dirty=!0}get radiusBL(){return this.geom.radiusBL}set radiusBL(t){this.geom.radiusBL=t,this.dirty=!0}get radiusBR(){return this.geom.radiusBR}set radiusBR(t){this.geom.radiusBR=t,this.dirty=!0}setRadius(t){return void 0===t&&(t=0),this.radius=t,this}setRadiusTL(t){return void 0===t&&(t=0),this.radiusTL=t,this}setRadiusTR(t){return void 0===t&&(t=0),this.radiusTR=t,this}setRadiusBL(t){return void 0===t&&(t=0),this.radiusBL=t,this}setRadiusBR(t){return void 0===t&&(t=0),this.radiusBR=t,this}get cornerRadius(){return this.geom.cornerRadius}set cornerRadius(t){this.radius=t}setCornerRadius(t){return this.setRadius(t)}get iteration(){return this._iteration}set iteration(t){void 0!==this._iteration?this._iteration!==t&&(this._iteration=t,this.dirty=!0):this._iteration=t}setIteration(t){return void 0===t&&(t=6),this.iteration=t,this}}const x={rectangle:0,circle:1};var S={setEventEmitter(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(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){return this._eventEmitter},on(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}};const E=Phaser.Scene;var R=function(t){return t instanceof E};const b=Phaser.Game;var T=function(t){return t instanceof b};const A=Phaser.Utils.Objects.GetValue;class k{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(A(e,"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))}shutdown(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)}destroy(t){this.shutdown(t)}onEnvDestroy(){this.destroy(!0)}onParentDestroy(t,e){this.destroy(e)}setParent(t){var e;return this.parent=t,this.scene=null==(e=t)||"object"!=typeof e?null:R(e)?e:e.scene&&R(e.scene)?e.scene:e.parent&&e.parent.scene&&R(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:T(t)?t:T(t.game)?t.game:R(t)?t.sys.game:R(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(k.prototype,S);const P=Phaser.Utils.Objects.GetValue;class w extends k{constructor(t,e){super(t,e),this.style=P(e,"style",this);var i=P(e,"propertiesMap");this.activeStyle=M(e,"active",i),this.hoverStyle=M(e,"hover",i),this.disableStyle=M(e,"disable",i),this.onModifyStyle=P(e,"onModifyStyle")}getStyle(t){return function(t,e,i){if(void 0===i&&(i={}),Array.isArray(e))for(var s=0,r=e.length;s<r;s++)i[n=e[s]]=t[n];else for(var n in e)i[n]=t[n];return i}(this.style,t)}modifyStyle(t){for(var e in t)this.style[e]=t[e];return this.onModifyStyle&&this.onModifyStyle(this.parent,t),this}applyStyle(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)}}setActiveState(t){return C.call(this,"active",t),this}setHoverState(t){return C.call(this,"hover",t),this}setDisableState(t){return C.call(this,"disable",t),this}}var M=function(t,e,i){var s=function(t,e,i,s){if(void 0===i&&(i="."),void 0===s&&(s={}),!t)return s;if(e in t)return Object.assign(s,t[e]);for(var r in e+=i,t)r.startsWith(e)&&(s[r.replace(e,"")]=t[r]);return s}(t,e);if(i)for(var r in s)i.hasOwnProperty(r)&&(s[i[r]]=s[r],delete s[r]);return s},C=function(t,e){void 0===e&&(e=!0);var i=`${t}State`,s=`${t}Style`,r=`${t}StyleSave`;this[i]!==e&&(this[i]=e,e?this[r]=this.applyStyle(this[s]):(this.applyStyle(this[r]),this[r]=void 0))},L={addStyleManager(t){return this.styleManager=new w(this,t),this},setActiveState(t){return this.styleManager.setActiveState(t),this},setHoverState(t){return this.styleManager.setHoverState(t),this},setDisableState(t){return this.styleManager.setDisableState(t),this}};class D extends _{constructor(t,e){void 0===e&&(e={}),super(t,e),this.type="rexStatesRoundRectangleShape",e.style=this,e.propertiesMap=O,this.addStyleManager(e),delete e.style,delete e.propertiesMap}}const O={color:"fillColor",alpha:"fillAlpha",strokeWidth:"lineWidth"};return Object.assign(D.prototype,L),D},"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();