UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 33 kB
var t,e;t=void 0,e=function(){var t=!1,e={renderWebGL:function(t,e,i){if(i.addToRenderList(e),e.layerRendererEnable){var r=e.rendererLayer;if(r){var s=r.list,a=s.length;if(0!==a){r.depthSort(),t.pipelines.preBatch(e);var n=-1!==e.blendMode;n||t.setBlendMode(0);for(var h=0;h<a;h++){var l=s[h];if(l.willRender(i)){n||l.blendMode===t.currentBlendMode||t.setBlendMode(l.blendMode);var o=l.mask;o&&o.preRenderWebGL(t,l,i);var d=l.type;d!==t.currentType&&(t.newType=!0,t.currentType=d),t.nextTypeMatch=h<a-1&&s[h+1].type===t.currentType,l.renderWebGL(t,l,i),o&&o.postRenderWebGL(t,i),t.newType=!1}}t.pipelines.postBatch(e)}}}},renderCanvas:function(t,e,i){if(i.addToRenderList(e),e.layerRendererEnable){var r=e.rendererLayer;if(r){var s=r.list;if(0!==s.length){r.depthSort();var a=-1!==e.blendMode;a||t.setBlendMode(0),e.mask&&e.mask.preRenderCanvas(t,null,i);for(var n=0;n<s.length;n++){var h=s[n];h.willRender(i)&&(a||h.blendMode===t.currentBlendMode||t.setBlendMode(h.blendMode),h.renderCanvas(t,h,i))}e.mask&&e.mask.postRenderCanvas(t)}}}}};const i=Phaser.Structs.List,r=Phaser.Utils.Array.StableSort,s=Phaser.GameObjects.Events,a=Phaser.Scenes.Events;class n extends i{constructor(t){super(t.scene),this.parent=t,this.scene=t.scene,this.events=this.scene.sys.events,this.active=!1,this.sortChildrenFlag=!1,this.addCallback=this.addChildCallback,this.removeCallback=this.removeChildCallback}addChildCallback(t){var e=t.displayList;e&&e!==this&&t.removeFromDisplayList(),t.parentContainer&&t.parentContainer.remove(t),t.displayList||(this.queueDepthSort(),t.displayList=this,t.emit(s.ADDED_TO_SCENE,t,this.scene),this.events.emit(a.ADDED_TO_SCENE,t,this.scene))}removeChildCallback(t){this.queueDepthSort(),t.displayList===this&&(t.displayList=null),t.emit(s.REMOVED_FROM_SCENE,t,this.scene),this.events.emit(a.REMOVED_FROM_SCENE,t,this.scene)}queueDepthSort(){return this.sortChildrenFlag=!0,this}depthSort(){return!this.sortChildrenFlag||this.list.length<2?(this.sortChildrenFlag=!1,this):(r(this.list,this.sortByDepth),this.sortChildrenFlag=!1,this)}sortByDepth(t,e){return t._depth-e._depth}}!function(e){if(!t){void 0===e&&(e=60);var i=Phaser.VERSION.split("."),r=parseInt(i[0]);if(3===r){var s=parseInt(i[1]);s<e&&console.error(`Minimum supported version : ${r}.${s}`)}else console.error(`Can't supported version : ${r}`);t=!0}}();const h=Phaser.GameObjects.Zone,l=Phaser.Utils.Array.Add,o=Phaser.Utils.Array.Remove;class d extends h{constructor(t,e,i,r,s){void 0===e&&(e=0),void 0===i&&(i=0),void 0===r&&(r=1),void 0===s&&(s=1),super(t,e,i,r,s),this.children=[],this.layerRendererEnable=!1,this.rendererLayer=void 0}destroy(t){if(this.scene&&!this.ignoreDestroy){if(t)for(var e,i=this.children.length-1;i>=0;i--)(e=this.children[i]).parentContainer||e.displayList&&e.displayList!==this.rendererLayer||e.destroy(t);this.clear(!t),super.destroy(t),this.rendererLayer=void 0}}contains(t){return-1!==this.children.indexOf(t)}add(t){return l(this.children,t,0,(function(t){t.once("destroy",this.onChildDestroy,this),this.addChildCallback(t)}),this),this}remove(t,e){return o(this.children,t,(function(t){t.off("destroy",this.onChildDestroy,this),this.removeChildCallback(t,e),e&&t.destroy()}),this),this}addChildCallback(t){var e=this.rendererLayer;e&&e.add(t)}removeChildCallback(t,e){var i=this.rendererLayer;i&&i.remove(t)}onChildDestroy(t,e){this.remove(t,!1)}clear(t){for(var e,i=this.children.slice(),r=0,s=i.length;r<s;r++)(e=i[r])&&(e.off("destroy",this.onChildDestroy,this),this.removeChildCallback(e,t),t&&e.destroy());return this.children.length=0,this}enableLayerRenderer(){if(this.layerRendererEnable)return this;this.layerRendererEnable=!0;var t=new n(this);this.rendererLayer=t;for(var e=0,i=this.children.length;e<i;e++)this.addChildCallback(this.children[e]);return t.queueDepthSort(),this}}const c=Phaser.GameObjects.Components;Phaser.Class.mixin(d,[c.Alpha,c.Flip]),Object.assign(d.prototype,e);var u=function(t,e){var i;if(void 0===e)t.hasOwnProperty("rexContainer")&&(i=t.rexContainer.parent);else for(i=u(t);i&&i.name!==e;)i=u(i);return i};const p=Phaser.Math.DegToRad,v=Phaser.Math.RadToDeg;var y=function(t){if(!t.hasOwnProperty("rexContainer")){var e={parent:null,self:null,layer:null,x:0,y:0,syncPosition:!0,rotation:0,syncRotation:!0,scaleX:0,scaleY:0,syncScale:!0,alpha:0,syncAlpha:!0,syncScrollFactor:!0,syncCameraFilter:!0,syncDisplayList:!0,visible:!0,active:!0};Object.defineProperty(e,"angle",{get:function(){return v(this.rotation)},set:function(t){this.rotation=p(t)}}),Object.defineProperty(e,"displayWidth",{get:function(){return t.width*this.scaleX},set:function(e){this.scaleX=e/t.width}}),Object.defineProperty(e,"displayHeight",{get:function(){return t.height*this.scaleY},set:function(e){this.scaleY=e/t.height}}),t.rexContainer=e}return t.rexContainer},f={setParent(t,e){void 0===e&&(e=this);var i=y(t);return e?(i.parent=e,i.self=t):(i.parent=null,i.self=null),this},getParent(t,e){return"string"==typeof t&&(e=t,t=void 0),void 0===t&&(t=this),u(t,e)},getTopmostParent(t){return void 0===t&&(t=this),function(t){for(var e=u(t);e;)t=e,e=u(e);return t}(t)}};const C=Phaser.Utils.Objects.GetValue,g=d.prototype.add;var b=function(t,e){this.setParent(t);var i=y(t);return x(i,e),this.resetChildState(t).updateChildVisible(t).updateChildActive(t).updateChildScrollFactor(t).updateChildMask(t).updateCameraFilter(t),g.call(this,t),L.call(this,t,i),this},m=function(t,e){this.setParent(t);var i=y(t);return x(i,e),i.x=t.x,i.y=t.y,i.rotation=t.rotation,i.scaleX=t.scaleX,i.scaleY=t.scaleY,i.alpha=t.alpha,i.visible=t.visible,i.active=t.active,this.updateChildPosition(t).updateChildAlpha(t).updateChildVisible(t).updateChildActive(t).updateChildScrollFactor(t).updateChildMask(t),g.call(this,t),L.call(this,t,i),this},x=function(t,e){void 0===e&&(e=!0),"boolean"==typeof e?(t.syncPosition=e,t.syncRotation=e,t.syncScale=e,t.syncAlpha=e,t.syncScrollFactor=e,t.syncCameraFilter=e,t.syncDisplayList=e):(t.syncPosition=C(e,"syncPosition",!0),t.syncRotation=C(e,"syncRotation",!0),t.syncScale=C(e,"syncScale",!0),t.syncAlpha=C(e,"syncAlpha",!0),t.syncScrollFactor=C(e,"syncScrollFactor",!0),t.syncCameraFilter=C(e,"syncCameraFilter",!0),t.syncDisplayList=C(e,"syncDisplayList",!0))},L=function(t,e){this.addToParentContainer(t),e.syncDisplayList&&this.addToPatentLayer(t)},P={add(t){return Array.isArray(t)?this.addMultiple(t):b.call(this,t),this},pin(t,e){return Array.isArray(t)?this.addMultiple(t,e):b.call(this,t,e),this},addMultiple(t){for(var e=Array.from(arguments),i=0,r=t.length;i<r;i++)e[0]=t[i],this.add.apply(this,e);return this},addLocal(t){return Array.isArray(t)?this.addMultiple(t):m.call(this,t),this},pinLocal(t,e){return Array.isArray(t)?this.addMultiple(t,e):m.call(this,t,e),this},addLocalMultiple(t){for(var e=0,i=t.length;e<i;e++)m.call(this,t[e]);return this}};const S=d.prototype.remove,A=d.prototype.clear;var R={remove(t,e){return u(t)!==this||(this.setParent(t,null),S.call(this,t,e)),this},unpin(t,e){return u(t)!==this||(this.setParent(t,null),S.call(this,t,e)),this},clear(t){for(var e=this.children,i=0,r=e.length;i<r;i++){var s=e[i];this.setParent(s,null)}return A.call(this,t),this}},k={getLocalState:t=>y(t),resetChildState(t){return this.resetChildPositionState(t).resetChildVisibleState(t).resetChildAlphaState(t).resetChildActiveState(t),this},resetChildrenState(t){for(var e=0,i=t.length;e<i;e++)this.resetChildState(t[e]);return this},syncProperties(){return this.syncPosition().syncVisible().syncAlpha().syncActive().syncScrollFactor().syncMask(),this}},F={worldToLocal(t){t.x-=this.x,t.y-=this.y;var e=Math.cos(-this.rotation),i=Math.sin(-this.rotation),r=t.x,s=t.y;return t.x=r*e-s*i,t.y=r*i+s*e,t.x/=this.scaleX,t.y/=this.scaleY,t},localToWorld(t){t.x*=this.scaleX,t.y*=this.scaleY;var e=Math.cos(this.rotation),i=Math.sin(this.rotation),r=t.x,s=t.y;return t.x=r*e-s*i,t.y=r*i+s*e,t.x+=this.x,t.y+=this.y,t}},w=function(t,e){return t===e?1:t/e},M={updateChildPosition(t){t.isRexContainerLite&&(t.syncChildrenEnable=!1);var e=y(t),i=e.parent;return e.syncPosition&&(t.x=e.x,t.y=e.y,i.localToWorld(t)),e.syncRotation&&(t.rotation=e.rotation+i.rotation),e.syncScale&&(t.scaleX=e.scaleX*i.scaleX,t.scaleY=e.scaleY*i.scaleY),t.isRexContainerLite&&(t.syncChildrenEnable=!0,t.syncPosition()),this},syncPosition(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildPosition,this),this},resetChildPositionState(t){var e=y(t),i=e.parent;return e.x=t.x,e.y=t.y,i.worldToLocal(e),e.scaleX=w(t.scaleX,i.scaleX),e.scaleY=w(t.scaleY,i.scaleY),e.rotation=t.rotation-i.rotation,this},setChildPosition(t,e,i){return t.x=e,t.y=i,this.resetChildPositionState(t),this},setChildLocalPosition(t,e,i){var r=y(t);return r.x=e,r.y=i,this.updateChildPosition(t),this},resetLocalPositionState(){var t=y(this).parent;return t&&t.resetChildPositionState(this),this},getChildLocalX:t=>y(t).x,getChildLocalY:t=>y(t).y};const T=Phaser.Math.DegToRad;var X={updateChildRotation(t){var e=y(t),i=e.parent;return e.syncRotation&&(t.rotation=i.rotation+e.rotation),this},syncRotation(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildRotation,this),this},resetChildRotationState(t){var e=y(t),i=e.parent;return e.rotation=t.rotation-i.rotation,this},setChildRotation(t,e){return t.rotation=e,this.resetChildRotationState(t),this},setChildAngle(t,e){return t.angle=e,this.resetChildRotationState(t),this},setChildLocalRotation(t,e){return y(t).rotation=e,this.updateChildRotation(t),this},setChildLocalAngle(t,e){return y(t).rotation=T(e),this.updateChildRotation(t),this},resetLocalRotationState(){var t=y(this).parent;return t&&t.resetChildRotationState(this),this},getChildLocalRotation:t=>y(t).rotation},Y={updateChildScale(t){var e=y(t),i=e.parent;return e.syncScale&&(t.scaleX=i.scaleX*e.scaleX,t.scaleY=i.scaleY*e.scaleY),this},syncScale(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildScale,this),this},resetChildScaleState(t){var e=y(t),i=e.parent;return e.scaleX=w(t.scaleX,i.scaleX),e.scaleY=w(t.scaleY,i.scaleY),this},setChildScale(t,e,i){return void 0===i&&(i=e),t.scaleX=e,t.scaleY=i,this.resetChildScaleState(t),this},setChildScaleX(t,e){return t.scaleX=e,this.resetChildScaleState(t),this},setChildScaleY(t,e){return t.scaleY=e,this.resetChildScaleState(t),this},setChildLocalScale(t,e,i){void 0===i&&(i=e);var r=y(t);return r.scaleX=e,r.scaleY=i,this.updateChildScale(t),this},setChildLocalScaleX(t,e){return y(t).scaleX=e,this.updateChildScale(t),this},setChildLocalScaleY(t,e){return y(t).scaleY=e,this.updateChildScale(t),this},setChildDisplaySize(t,e,i){return t.setDisplaySize(e,i),this.resetChildScaleState(t),this},resetLocalScaleState(){var t=y(this).parent;return t&&t.resetChildScaleState(this),this},getChildLocalScaleX:t=>y(t).scaleX,getChildLocalScaleY:t=>y(t).scaleY},E={updateChildVisible(t){var e=y(t),i=e.parent,r=!e.hasOwnProperty("maskVisible")||e.maskVisible,s=!i||i.visible;return t.visible=s&&e.visible&&r,this},syncVisible(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildVisible,this),this},resetChildVisibleState(t){var e=y(t);return e.hasOwnProperty("maskVisible")&&delete e.maskVisible,e.visible=t.visible,this},setChildVisible(t,e){return this.setChildLocalVisible(t,e),this},setChildLocalVisible(t,e){return void 0===e&&(e=!0),y(t).visible=e,this.updateChildVisible(t),this},setChildMaskVisible(t,e){return void 0===e&&(e=!0),y(t).maskVisible=e,this.updateChildVisible(t),this},resetLocalVisibleState(){var t=y(this).parent;return t&&t.resetChildVisibleState(this),this},getChildLocalVisible:t=>y(t).visible},O={updateChildAlpha(t){var e=y(t),i=e.parent;return e.syncAlpha&&(t.alpha=i.alpha*e.alpha),this},syncAlpha(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildAlpha,this),this},resetChildAlphaState(t){var e=y(t),i=e.parent;return e.alpha=w(t.alpha,i.alpha),this},setChildAlpha(t,e){return t.alpha=e,this.resetChildAlphaState(t),this},setChildLocalAlpha(t,e){return y(t).alpha=e,this.updateChildAlpha(t),this},resetLocalAlphaState(){var t=y(this).parent;return t&&t.resetChildAlphaState(this),this},getChildLocalAlpha:t=>y(t).alpha},_={updateChildActive(t){var e=y(t),i=e.parent;return t.active=i.active&&e.active,this},syncActive(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildActive,this),this},resetChildActiveState(t){return y(t).active=t.active,this},setChildActive(t,e){return t.active=e,this.resetChildActiveState(t),this},setChildLocalActive(t,e){return void 0===e&&(e=!0),y(t).active=e,this.updateChildActive(t),this},resetLocalActiveState(){var t=y(this).parent;return t&&t.resetChildActiveState(this),this},getChildLocalActive:t=>y(t).active},D={updateChildScrollFactor(t){var e=y(t),i=e.parent;return e.syncScrollFactor&&(t.scrollFactorX=i.scrollFactorX,t.scrollFactorY=i.scrollFactorY),this},syncScrollFactor(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildScrollFactor,this),this}},V={updateCameraFilter(t){var e=y(t),i=e.parent;return e.syncCameraFilter&&(t.cameraFilter=i.cameraFilter),this},syncCameraFilter(){return this.syncChildrenEnable&&this.children.forEach(this.updateCameraFilter,this),this}},B={updateChildMask(t){return null==this.mask||(this.mask.hasOwnProperty("geometryMask")?this.mask.geometryMask:this.mask.bitmapMask)!==t&&(t.mask=this.mask),this},syncMask(){return this.syncChildrenEnable&&this.children.forEach(this.updateChildMask,this),this},setMask(t){return this.mask=t,this},clearChildrenMask(){for(var t=this.children,e=0,i=t.length;e<i;e++){var r=t[e];r.clearMask&&r.clearMask(!1),r.hasOwnProperty("isRexContainerLite")||this.setChildMaskVisible(r)}return this},clearMask(t){return void 0===t&&(t=!1),t&&this.mask&&mask.destroy(),this._mask=null,this.setChildMaskVisible(this),this.clearChildrenMask(),this}},j=function(t,e){if(t.length<=1)return t;var i;void 0===e&&(e=!1);for(var r=0,s=t.length;r<s;r++){var a=t[r];if(a.displayList?i=a.displayList:a.parentContainer&&(i=a.parentContainer.list),i)break}return i||(i=a.scene.sys.displayList),i.depthSort&&(i.depthSort(),i=i.list),e?t.sort((function(t,e){return i.indexOf(e)-i.indexOf(t)})):t.sort((function(t,e){return i.indexOf(t)-i.indexOf(e)})),t},G=function(t,e){var i=e?e.displayList:void 0,r=e?e.parentContainer:void 0;return t.filter((function(t){var s=t.displayList,a=t.parentContainer;return!(!s&&!a||e&&(s?s!==i:!a||a!==r))}))},U={setDepth(t,e){if(this.depth=t,!this.layerRendererEnable&&!e&&this.children)for(var i=this.getAllChildren(),r=0,s=i.length;r<s;r++)i[r].depth=t;return this},swapDepth(t){var e=this.depth,i=t.depth;return this.setDepth(i),t.setDepth(e),this},incDepth(t){if(this.depth+=t,!this.layerRendererEnable&&this.children)for(var e=this.getAllChildren(),i=0,r=e.length;i<r;i++)e[i].depth+=t;return this},bringToTop(){var t=this.displayList;if(!t)return this;if(this.layerRendererEnable)t.exists(this)&&t.bringToTop(this);else{var e=this.getAllChildren([this]);j(e,!1);for(var i=0,r=e.length;i<r;i++){var s=e[i];t.exists(s)&&t.bringToTop(s)}}return this},bringMeToTop(){return this.bringToTop()},sendToBack(){var t=this.displayList;if(!t)return this;if(this.layerRendererEnable)t.exists(this)&&t.sendToBack(this);else{var e=this.getAllChildren([this]);j(e,!0);for(var i=0,r=e.length;i<r;i++){var s=e[i];t.exists(s)&&t.sendToBack(s)}}return this},sendMeToBack(){return this.sendToBack()},moveDepthBelow(t){var e=this.displayList;if(!e)return this;if(t.displayList!==e)return this;if(this.layerRendererEnable)e.exists(this)&&e.moveBelow(t,this);else{var i=this.getAllChildren([this]);j(i,!1);for(var r=0,s=i.length;r<s;r++){var a=i[r];if(e.exists(a)){e.moveBelow(t,a);break}}}return this},moveMyDepthBelow(t){return this.moveDepthBelow(t)},moveDepthAbove(t){var e=this.displayList;if(!e)return this;if(t.displayList!==e)return this;if(this.layerRendererEnable)e.exists(this)&&e.moveAbove(t,this);else{var i=this.getAllChildren([this]);j(i,!0);for(var r=0,s=i.length;r<s;r++){var a=i[r];if(e.exists(a)){e.moveAbove(t,a);break}}}return this},moveMyDepthAbove(t){return this.moveDepthAbove(t)},bringChildToTop(t){if(t===this&&this.layerRendererEnable)return this;var e,i;if(t!==this&&t.isRexContainerLite&&!t.layerRendererEnable?(e=t.getAllChildren([t]),e=G(e,t),e=j(e,!1)):e=[t],this.layerRendererEnable)i=this;else{var r=this.getAllChildren([this]);r=G(r,t),i=(r=j(r,!1))[r.length-1]}for(var s=0,a=e.length;s<a;s++){var n=e[s];i!==n&&(n!==this&&i.displayList!==n.displayList||(i.displayList.moveAbove(n,i),i=n))}return this},sendChildToBack(t){if(t===this&&this.layerRendererEnable)return this;var e,i;if(t!==this&&t.isRexContainerLite&&!t.layerRendererEnable?(e=t.getAllChildren([t]),e=G(e,t),e=j(e,!1)):e=[t],this.layerRendererEnable)i=this;else{var r=this.getAllChildren([this]);r=G(r,t),i=(r=j(r,!1))[0]}for(var s=e.length-1;s>=0;s--){var a=e[s];i!==a&&(a!==this&&i.displayList!==a.displayList||(i.displayList.moveBelow(a,i),i=a))}return this}},W=function(t,e){if(!e(t)&&t.isRexContainerLite)for(var i=t.children,r=0,s=i.length;r<s;r++)W(i[r],e)},z=function(t,e){for(var i=[t];i.length>0;){var r=i.shift();!e(r)&&r.isRexContainerLite&&i.push(...r.children)}};const I=Phaser.Utils.Array;var H={getChildren(t){if(t)for(var e=0,i=this.children.length;e<i;e++)t.push(this.children[e]);else t=this.children;return t},getAllChildren(t){void 0===t&&(t=[]);var e=this;return z(e,(function(i){i!==e&&t.push(i)})),t},getAllVisibleChildren(t){void 0===t&&(t=[]);var e=this;return z(e,(function(i){if(i!==e)return!i.visible||void t.push(i)})),t},bfs(t,e){return void 0===e&&(e=this),z(e,t),this},dfs(t,e){return void 0===e&&(e=this),W(e,t),this},contains(t){var e=u(t);return!!e&&(e===this||this.contains(e))},getByName(t,e){if(e){for(var i,r,s=[this];s.length;)for(var a=0,n=(i=s.shift()).children.length;a<n;a++){if((r=i.children[a]).name===t)return r;r.isRexContainerLite&&s.push(r)}return null}return I.GetFirst(this.children,"name",t)},getRandom(t,e){return I.GetRandom(this.children,t,e)},getFirst(t,e,i,r){return I.GetFirstElement(this.children,t,e,i,r)},getAll(t,e,i,r){return I.GetAll(this.children,t,e,i,r)},count(t,e,i,r){return I.CountAllMatching(this.children,t,e,i,r)},swap(t,e){return I.Swap(this.children,t,e),this},setAll(t,e,i,r){return I.SetAll(this.children,t,e,i,r),this}},N=function(t){for(var e=[],i=0,r=t.length;i<r;i++){var s=t[i];s.hasOwnProperty("rexContainer")&&e.push(s.rexContainer)}return e},q=function(t,e,i){if(i.parent){var r=i.parent,s=i.self;switch(e){case"x":case"y":r.updateChildPosition(s);break;case"angle":case"rotation":r.updateChildRotation(s);break;case"scaleX":case"scaleY":case"displayWidth":case"displayHeight":r.updateChildScale(s);break;case"alpha":r.updateChildAlpha(s);break;default:r.updateChildPosition(s),r.updateChildRotation(s),r.updateChildScale(s),r.updateChildAlpha(s)}}else t.remove()},$={tweenChild(t){var e=t.targets;Array.isArray(e)||(e=[e]);var i=this.scene||function(t){for(var e=0,i=t.length;e<i;e++){var r=t[e].scene;if(r)return r}return null}(e);if(i){t.targets=N(e);var r=i.tweens.add(t);return r.on("update",q),r}},tweenSelf(t){return t.targets=[this],this.tweenChild(t)},createTweenChildConfig(t){var e=t.targets;e&&(Array.isArray(e)||(e=[e]),t.targets=N(e));var i=t.onUpdate;return t.onUpdate=function(t,e){i&&i(t,e),q(t,void 0,e)},t},tween(t){var e=this.scene;return t.targets||(t.targets=this),e.tweens.add(t)}};Phaser.GameObjects.Container;const Z=Phaser.GameObjects.Layer;var J=function(t){return t instanceof Z},K=function(t){var e=t.getAllChildren([t]);return e=e.filter((function(t){return!!t.displayList||!!t.parentContainer}))},Q=function(t){var e=K(this);-1===e.indexOf(this)&&e.push(this),j(e),t.add(e)},tt=function(t,e,i){if(this.scene){var r=K(this);j(r,e),t.remove(r),i&&r.forEach((function(t){t.addToDisplayList()}))}},et={addToContainer(t){return this._setParentContainerFlag=!0,Q.call(this,t),this._setParentContainerFlag=!1,this},addToLayer(t){return Q.call(this,t),this},removeFromContainer(){return this.parentContainer?(this._setParentContainerFlag=!0,tt.call(this,this.parentContainer,!0,!1),this._setParentContainerFlag=!1,this):this},removeFromLayer(t){return void 0===t&&(t=!0),J(this.displayList)?(tt.call(this,this.displayList,!1,t),this):this},getParentContainer(){if(this.parentContainer)return this.parentContainer;for(var t=this.getParent();t;){var e=t.parentContainer;if(e)return e;t=t.getParent()}return null},addToParentContainer(t){if(!t.displayList)return this;var e=this.getParentContainer();return e?(t.isRexContainerLite?t.addToContainer(e):e.add(t),this):this},addToPatentLayer(t){if(!t.displayList)return this;var e=this.displayList;return e===t.displayList||J(e)&&(t.isRexContainerLite?t.addToLayer(e):e.add(t)),this}},it=function(){if(this.rendererLayer)return this.rendererLayer;for(var t=this.getParent();t;){if(t.rendererLayer)return t.rendererLayer;t=t.getParent()}return null},rt={hasLayer(){return this.layerRendererEnable},enableLayer(){return this.enableLayerRenderer(),this},getLayer(){return this.enableLayerRenderer(),this},addChildCallback(t){if(t.displayList){var e=it.call(this);e&&e!==t.displayList&&(t.isRexContainerLite?t.addToLayer(e):e.add(t),y(t).layer=e)}},removeChildCallback(t,e){var i=y(t),r=i.layer;r&&(t.isRexContainerLite?t.removeFromLayer(!0):r.remove(t),i.layer=null)}},st=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},at=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height};const nt=Phaser.Geom.Rectangle,ht=Phaser.Math.Vector2,lt=Phaser.Math.RotateAround,ot=Phaser.GameObjects.Container;var dt=function(t,e){if(void 0===e?e=new nt:!0===e&&(void 0===ct&&(ct=new nt),e=ct),t.getBounds&&!(t instanceof ot))return t.getBounds(e);var i,r,s,a,n,h,l,o;if(t.parentContainer){var d=t.parentContainer.getBoundsTransformMatrix();ut(t,e),d.transformPoint(e.x,e.y,e),i=e.x,r=e.y,pt(t,e),d.transformPoint(e.x,e.y,e),s=e.x,a=e.y,vt(t,e),d.transformPoint(e.x,e.y,e),n=e.x,h=e.y,yt(t,e),d.transformPoint(e.x,e.y,e),l=e.x,o=e.y}else ut(t,e),i=e.x,r=e.y,pt(t,e),s=e.x,a=e.y,vt(t,e),n=e.x,h=e.y,yt(t,e),l=e.x,o=e.y;return e.x=Math.min(i,s,n,l),e.y=Math.min(r,a,h,o),e.width=Math.max(i,s,n,l)-e.x,e.height=Math.max(r,a,h,o)-e.y,e},ct=void 0,ut=function(t,e,i){return void 0===e?e=new ht:!0===e&&(void 0===ft&&(ft=new ht),e=ft),t.getTopLeft?t.getTopLeft(e,i):(e.x=t.x-st(t)*t.originX,e.y=t.y-at(t)*t.originY,Ct(t,e,i))},pt=function(t,e,i){return void 0===e?e=new ht:!0===e&&(void 0===ft&&(ft=new ht),e=ft),t.getTopRight?t.getTopRight(e,i):(e.x=t.x-st(t)*t.originX+st(t),e.y=t.y-at(t)*t.originY,Ct(t,e,i))},vt=function(t,e,i){return void 0===e?e=new ht:!0===e&&(void 0===ft&&(ft=new ht),e=ft),t.getBottomLeft?t.getBottomLeft(e,i):(e.x=t.x-st(t)*t.originX,e.y=t.y-at(t)*t.originY+at(t),Ct(t,e,i))},yt=function(t,e,i){return void 0===e?e=new ht:!0===e&&(void 0===ft&&(ft=new ht),e=ft),t.getBottomRight?t.getBottomRight(e,i):(e.x=t.x-st(t)*t.originX+st(t),e.y=t.y-at(t)*t.originY+at(t),Ct(t,e,i))},ft=void 0,Ct=function(t,e,i){return void 0===i&&(i=!1),0!==t.rotation&&lt(e,t.x,t.y,t.rotation),i&&t.parentContainer&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e),e};const gt=Phaser.Geom.Rectangle,bt=Phaser.Geom.Rectangle.Union;var mt,xt=function(t,e){var i=Array.isArray(t);if(void 0===e?e=i?[]:{}:function(t){if("object"!=typeof t||null===t)return t;if(Array.isArray(t))t.length=0;else for(var e in t)delete t[e]}(e),i){e.length=t.length;for(var r=0,s=t.length;r<s;r++)e[r]=t[r]}else for(var a in t)e[a]=t[a];return e};const Lt=Phaser.GameObjects.GameObject,Pt=Phaser.GameObjects.Layer;var St=Phaser.Utils.Objects.GetValue,At=function(t){if(t){var e,i,r=t.gameObjects,s=t.renderTexture,a=t.saveTexture,n=St(t,"x",void 0),h=St(t,"y",void 0),l=St(t,"width",void 0),o=St(t,"height",void 0),d=St(t,"originX",0),c=St(t,"originY",0),u=St(t,"padding",0);if(void 0===l||void 0===o||void 0===n||void 0===h){var p=function(t,e){var i;void 0===e?e=new gt:!0===e&&(void 0===mt&&(mt=new gt),e=mt),e.setTo(0,0,0,0);for(var r=!0,s=0,a=t.length;s<a;s++)if((i=t[s]).getBounds){var n=dt(i,!0);r?(e.setTo(n.x,n.y,n.width,n.height),r=!1):bt(n,e,e)}return e}(r,!0);void 0!==n&&void 0!==h?(l=2*Math.max(n-p.left,p.right-n),o=2*Math.max(h-p.top,p.bottom-h),d=.5,c=.5):(n=p.x,h=p.y,l=p.width,o=p.height,d=0,c=0),e=p.x,i=p.y}else e=n+(0-d)*l,i=h+(0-c)*o;e-=u,i-=u,l+=2*u,o+=2*u;var v,y=r[0].scene,f=y.sys.textures;return a&&!s&&(s=f.addDynamicTexture(a,l,o)),s||(s=y.add.renderTexture(0,0,l,o)),s.setPosition&&s.setPosition(n,h),s.width===l&&s.height===o||s.setSize(l,o),s.setOrigin&&s.setOrigin(d,c),s.camera.setScroll(e,i),r=j(xt(r)),s.draw(r),a&&((v=s)instanceof Lt||v instanceof Pt?s.saveTexture(a):s.key!==a&&f.renameTexture(s.key,key)),s}},Rt={snapshot(t){var e=this.scaleX,i=this.scaleY,r=1===e&&1===i;r||this.setScale(1),void 0===t&&(t={}),t.gameObjects=this.getAllVisibleChildren(),t.x=this.x,t.y=this.y,t.originX=this.originX,t.originY=this.originY;var s=At(t),a=!!s.scene;return r||(this.setScale(e,i),a&&s.setScale(e,i)),a?s:this}};const kt=Phaser.Utils.Objects.GetValue;var Ft=function(t,e,i,r,s,a,n,h){if(t.getBounds||void 0!==t.width&&void 0!==t.height){var l=ut(t,wt[0],h);l.x-=n,l.y-=n;var o=pt(t,wt[1],h);o.x+=n,o.y-=n;var d=yt(t,wt[2],h);d.x+=n,d.y+=n;var c=vt(t,wt[3],h);c.x-=n,c.y+=n,null!==s&&e.fillStyle(s,a).fillPoints(wt,!0,!0),null!==i&&e.lineStyle(r,i).strokePoints(wt,!0,!0)}},wt=[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const Mt=Phaser.Utils.Objects.GetValue,Tt=Phaser.Math.RotateAround;var Xt={changeOrigin:function(t,e){this.syncChildrenEnable=!1,function(t,e,i){void 0===i&&(i=e);var r={x:(e-t.originX)*t.displayWidth,y:(i-t.originY)*t.displayHeight};Tt(r,0,0,t.rotation),t.originX=e,t.originY=i,t.x=t.x+r.x,t.y=t.y+r.y}(this,t,e),this.syncChildrenEnable=!0;for(var i=this.getAllChildren(),r=0,s=i.length;r<s;r++)this.resetChildPositionState(i[r]);return this},drawBounds:function(t,e){var i=Mt(e,"drawContainer",!0),r=Mt(e,"children");return void 0===r&&(r=this.getAllVisibleChildren([this])),i||(r=r.filter((function(t){return!t.isRexContainerLite}))),function(t,e,i){var r,s,a,n,h,l;if("number"==typeof i?r=i:(r=kt(i,"color"),s=kt(i,"lineWidth"),a=kt(i,"fillColor"),n=kt(i,"fillAlpha"),h=kt(i,"padding"),l=kt(i,"includeParent")),void 0===r&&(r=16777215),void 0===s&&(s=1),void 0===a&&(a=null),void 0===n&&(n=1),void 0===h&&(h=0),void 0===l&&(l=!0),Array.isArray(t))for(var o=0,d=t.length;o<d;o++)Ft(t[o],e,r,s,a,n,h,l);else Ft(t,e,r,s,a,n,h,l)}(r,t,e),this}};Object.assign(Xt,f,P,R,k,F,M,X,Y,E,O,_,D,V,B,U,H,$,et,rt,Rt);class Yt extends d{constructor(t,e,i,r,s,a){Array.isArray(r)&&(a=r,r=void 0,s=void 0),super(t,e,i,r,s),this.type="rexContainerLite",this.isRexContainerLite=!0,this.syncChildrenEnable=!0,this._active=!0,this._mask=null,this._scrollFactorX=1,this._scrollFactorY=1,this._cameraFilter=0,a&&this.add(a)}destroy(t){this.scene&&!this.ignoreDestroy&&(this.syncChildrenEnable=!1,super.destroy(t))}resize(t,e){return this.setSize(t,e),this}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this.syncPosition())}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this.syncPosition())}get rotation(){return super.rotation}set rotation(t){this.rotation!==t&&(super.rotation=t,this.syncPosition())}get scaleX(){return super.scaleX}set scaleX(t){this.scaleX!==t&&(super.scaleX=t,this.syncPosition())}get scaleY(){return super.scaleY}set scaleY(t){this.scaleY!==t&&(super.scaleY=t,this.syncPosition())}get scale(){return super.scale}set scale(t){this.scale!==t&&(super.scale=t,this.syncPosition())}get visible(){return super.visible}set visible(t){super.visible!==t&&(super.visible=t,this.syncVisible())}get alpha(){return super.alpha}set alpha(t){super.alpha!==t&&(super.alpha=t,this.syncAlpha())}get active(){return this._active}set active(t){this._active!==t&&(this._active=t,this.syncActive())}get mask(){return this._mask}set mask(t){this._mask!==t&&(this._mask=t,this.layerRendererEnable||this.syncMask())}get scrollFactorX(){return this._scrollFactorX}set scrollFactorX(t){this._scrollFactorX!==t&&(this._scrollFactorX=t,this.syncScrollFactor())}get scrollFactorY(){return this._scrollFactorY}set scrollFactorY(t){this._scrollFactorY!==t&&(this._scrollFactorY=t,this.syncScrollFactor())}get cameraFilter(){return this._cameraFilter}set cameraFilter(t){this._cameraFilter!==t&&(this._cameraFilter=t,this.syncCameraFilter())}get list(){return this.children}static GetParent(t){return u(t)}get parentContainer(){return this._parentContainer}set parentContainer(t){this._parentContainer||t?this.setParentContainerFlag?this._parentContainer=t:this._parentContainer&&!t?(this.removeFromContainer(),this._parentContainer=t):t?(this._parentContainer=t,this.addToContainer(t)):this._parentContainer=t:this._parentContainer=t}get setParentContainerFlag(){if(this._setParentContainerFlag)return!0;var t=u(this);return!!t&&t.setParentContainerFlag}}Object.assign(Yt.prototype,Xt);const Et={fit:0,FIT:0,envelop:1,ENVELOP:1};var Ot={},_t={setFlipX(t){return this.flipX=t,this},setFlipY(t){return this.flipY=t,this},toggleFlipX(){return this.flipX=!this.flipX,this},toggleFlipY(){return this.flipY=!this.flipY,this},setFlip(t,e){return this.flipX=t,this.flipY=e,this},resetFlip(){return this.flipX=!1,this.flipY=!1,this}},Dt={scaleImage:function(){var t=this.image;if(!this.scaleUp&&t.width<=this.width&&t.height<=this.height)return this;var e=function(t,e,i,r){if(void 0===i)i=0;else{var s=typeof i;"boolean"===s?(r=i,i=0):"string"===s&&(i=Et[i])}void 0===r?r={}:!0===r&&(r=Ot);var a=e.width/t.width,n=e.height/t.height,h=i?Math.max(a,n):Math.min(a,n);return r.width=t.width*h,r.height=t.height*h,r}(t,this,"FIT",!0);return t.setDisplaySize(e.width,e.height),this.resetChildScaleState(t),this}};Object.assign(Dt,_t);var Vt=[Phaser.GameObjects.Image,Phaser.GameObjects.Sprite,Phaser.GameObjects.Mesh,Phaser.GameObjects.Shader,Phaser.GameObjects.Video],Bt=[Phaser.GameObjects.BitmapText],jt=function(t,e,i){if(t&&(void 0!==e||void 0!==i))if(function(t){if(t.resize)return!0;if(!t.setSize)return!1;for(var e=0,i=Vt.length;e<i;e++){var r=Vt[e];if(r&&t instanceof r)return!1}return!0}(t)){var r,s;r=void 0===e?t.width:e/t.scaleX,s=void 0===i?t.height:i/t.scaleY,t.resize?t.resize(r,s):t.setSize(r,s)}else{var a=function(t){if(void 0===t.displayWidth)return!1;for(var e=0,i=Bt.length;e<i;e++){var r=Bt[e];if(r&&t instanceof r)return!1}return!0}(t);void 0!==e&&(a?t.displayWidth=e:t.scaleX=e/t.width),void 0!==i&&(a?t.displayHeight=i:t.scaleY=i/t.height)}},Gt=function(){var t=this.background;return t?(t.setOrigin(this.originX,this.originY),t.setPosition(this.x,this.y),jt(t,this.displayWidth,this.displayHeight),this.resetChildScaleState(t),this):this};const Ut=Phaser.Utils.Objects.IsPlainObject,Wt=Phaser.Utils.Objects.GetValue;class zt extends Yt{constructor(t,e,i,r,s,a){Ut(e)?(e=Wt(a=e,"x",0),i=Wt(a,"y",0),r=Wt(a,"key",void 0),s=Wt(a,"frame",void 0)):Ut(s)&&(a=s,s=void 0);var n=Wt(a,"image");n?n.setPosition(e,i).setOrigin(.5):(n=t.add.image(e,i,r,s),void 0===r&&n.setVisible(!1)),super(t,e,i,1,1),this.type="rexImageBox";var h=Wt(a,"background");h&&this.add(h),this.background=h,this.add(n),this.image=n,this.scaleUp=Wt(a,"scaleUp",!1);var l=Wt(a,"width",n.width),o=Wt(a,"height",n.height);this.resize(l,o)}get texture(){return this.image.texture}get frame(){return this.image.frame}get flipX(){return this._flipX}set flipX(t){this._flipX!==t&&(this._flipX=t,this.image.setFlipX(t))}get flipY(){return this._flipY}set flipY(t){this._flipY!==t&&(this._flipY=t,this.image.setFlipY(t))}resize(t,e){return super.resize(t,e),Gt.call(this),this.scaleImage(),this}setTexture(t,e){var i=this.image;return i.setTexture(t,e),null!==t?(this.setChildVisible(i,!0),this.scaleImage()):this.setChildVisible(i,!1),this}}function It(t,e,i,r,s){var a=new zt(this.scene,t,e,i,r,s);return this.scene.add.existing(a),a}Object.assign(zt.prototype,Dt);const Ht=Phaser.Utils.Objects.GetAdvancedValue,Nt=Phaser.GameObjects.BuildGameObject;function qt(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=Ht(t,"key",null),r=Ht(t,"frame",null),s=new zt(this.scene,0,0,i,r,t);return Nt(this.scene,s,t),s}var $t=function(t){return null!==t&&"object"==typeof t};class Zt extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexImageBox",It,qt)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,i,r="."){if(!$t(t))return t;if(function(t){return null==t}(e)||""===e||Array.isArray(e)&&0===e.length)return t;if("string"==typeof e&&-1===e.indexOf(r)||"number"==typeof e)return t[e]=i,t;var s=function(t,e){return Array.isArray(t)||(t="string"!=typeof t||""===t.trim()?[]:t.split(e).filter(Boolean)),t}(e,r);if(0===s.length)return t;for(var a=t,n=s.length,h=0;h<n-1;h++){var l=s[h],o=a[l];$t(o)||(a[l]={}),a=a[l]}a[s[n-1]]=i}(window,"RexPlugins.GameObjects.ImageBox",zt),Zt},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).reximageboxplugin=e();