UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 30.8 kB
var t,e;t=void 0,e=function(){var t=!1;!function(e){if(!t){void 0===e&&(e=0);var i=Phaser.VERSION.split("."),r=parseInt(i[0]);if(4===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 e=Phaser.GameObjects.Zone,i=Phaser.Utils.Array.Add,r=Phaser.Utils.Array.Remove;class s extends e{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=[]}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.destroy(t);this.clear(!t),super.destroy(t)}}contains(t){return-1!==this.children.indexOf(t)}add(t){var e=this;return i(this.children,t,0,(function(t){t.once("destroy",e.onChildDestroy,e)}),this),this}remove(t,e){var i=this;return r(this.children,t,(function(t){t.off("destroy",i.onChildDestroy,i),e&&t.destroy()})),this}onChildDestroy(t,e){this.remove(t,!1)}clear(t){for(var e,i=0,r=this.children.length;i<r;i++)(e=this.children[i]).off("destroy",this.onChildDestroy,this),t&&e.destroy();return this.children.length=0,this}}const a=Phaser.GameObjects.Components;Phaser.Class.mixin(s,[a.Alpha,a.Flip]);var n=function(t,e){var i;if(void 0===e)t.hasOwnProperty("rexContainer")&&(i=t.rexContainer.parent);else for(i=n(t);i&&i.name!==e;)i=n(i);return i};const h=Phaser.Math.DegToRad,l=Phaser.Math.RadToDeg;var o=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 l(this.rotation)},set:function(t){this.rotation=h(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},c={setParent(t,e){void 0===e&&(e=this);var i=o(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),n(t,e)},getTopmostParent(t){return void 0===t&&(t=this),function(t){for(var e=n(t);e;)t=e,e=n(e);return t}(t)}};const d=Phaser.Utils.Objects.GetValue,u=s.prototype.add;var p=function(t,e){this.setParent(t);var i=o(t);return y(i,e),this.resetChildState(t).updateChildVisible(t).updateChildActive(t).updateChildScrollFactor(t).updateChildMask(t).updateCameraFilter(t),u.call(this,t),f.call(this,t,i),this},v=function(t,e){this.setParent(t);var i=o(t);return y(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),u.call(this,t),f.call(this,t,i),this},y=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=d(e,"syncPosition",!0),t.syncRotation=d(e,"syncRotation",!0),t.syncScale=d(e,"syncScale",!0),t.syncAlpha=d(e,"syncAlpha",!0),t.syncScrollFactor=d(e,"syncScrollFactor",!0),t.syncCameraFilter=d(e,"syncCameraFilter",!0),t.syncDisplayList=d(e,"syncDisplayList",!0))},f=function(t,e){this.addToParentContainer(t),e.syncDisplayList&&this.addToPatentLayer(t),this.addToRenderLayer(t)},g={add(t){return Array.isArray(t)?this.addMultiple(t):p.call(this,t),this},pin(t,e){return Array.isArray(t)?this.addMultiple(t,e):p.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):v.call(this,t),this},pinLocal(t,e){return Array.isArray(t)?this.addMultiple(t,e):v.call(this,t,e),this},addLocalMultiple(t){for(var e=0,i=t.length;e<i;e++)v.call(this,t[e]);return this}};const C=s.prototype.remove,m=s.prototype.clear;var x={remove(t,e){return n(t)!==this||(this.setParent(t,null),e||this.removeFromRenderLayer(t),C.call(this,t,e)),this},unpin(t,e){return n(t)!==this||(this.setParent(t,null),e||this.removeFromRenderLayer(t),C.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),t||this.removeFromRenderLayer(s)}return m.call(this,t),this}},b={getLocalState:t=>o(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}},P={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}},L=function(t,e){return t===e?1:t/e},A={updateChildPosition(t){t.isRexContainerLite&&(t.syncChildrenEnable=!1);var e=o(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=o(t),i=e.parent;return e.x=t.x,e.y=t.y,i.worldToLocal(e),e.scaleX=L(t.scaleX,i.scaleX),e.scaleY=L(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=o(t);return r.x=e,r.y=i,this.updateChildPosition(t),this},resetLocalPositionState(){var t=o(this).parent;return t&&t.resetChildPositionState(this),this},getChildLocalX:t=>o(t).x,getChildLocalY:t=>o(t).y};const S=Phaser.Math.DegToRad;var F={updateChildRotation(t){var e=o(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=o(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 o(t).rotation=e,this.updateChildRotation(t),this},setChildLocalAngle(t,e){return o(t).rotation=S(e),this.updateChildRotation(t),this},resetLocalRotationState(){var t=o(this).parent;return t&&t.resetChildRotationState(this),this},getChildLocalRotation:t=>o(t).rotation},R={updateChildScale(t){var e=o(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=o(t),i=e.parent;return e.scaleX=L(t.scaleX,i.scaleX),e.scaleY=L(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},setChildLocalScale(t,e,i){void 0===i&&(i=e);var r=o(t);return r.scaleX=e,r.scaleY=i,this.updateChildScale(t),this},setChildDisplaySize(t,e,i){return t.setDisplaySize(e,i),this.resetChildScaleState(t),this},resetLocalScaleState(){var t=o(this).parent;return t&&t.resetChildScaleState(this),this},getChildLocalScaleX:t=>o(t).scaleX,getChildLocalScaleY:t=>o(t).scaleY},T={updateChildVisible(t){var e=o(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=o(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),o(t).visible=e,this.updateChildVisible(t),this},setChildMaskVisible(t,e){return void 0===e&&(e=!0),o(t).maskVisible=e,this.updateChildVisible(t),this},resetLocalVisibleState(){var t=o(this).parent;return t&&t.resetChildVisibleState(this),this},getChildLocalVisible:t=>o(t).visible},k={updateChildAlpha(t){var e=o(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=o(t),i=e.parent;return e.alpha=L(t.alpha,i.alpha),this},setChildAlpha(t,e){return t.alpha=e,this.resetChildAlphaState(t),this},setChildLocalAlpha(t,e){return o(t).alpha=e,this.updateChildAlpha(t),this},resetLocalAlphaState(){var t=o(this).parent;return t&&t.resetChildAlphaState(this),this},getChildLocalAlpha:t=>o(t).alpha},X={updateChildActive(t){var e=o(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 o(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),o(t).active=e,this.updateChildActive(t),this},resetLocalActiveState(){var t=o(this).parent;return t&&t.resetChildActiveState(this),this},getChildLocalActive:t=>o(t).active},Y={updateChildScrollFactor(t){var e=o(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}},w={updateCameraFilter(t){var e=o(t),i=e.parent;return e.syncCameraFilter&&(t.cameraFilter=i.cameraFilter),this},syncCameraFilter(){return this.syncChildrenEnable&&this.children.forEach(this.updateCameraFilter,this),this}},O={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},clearMask(t){void 0===t&&(t=!1);var e=this;return this._mask=null,this.setChildMaskVisible(this),this.children.forEach((function(t){t.clearMask&&t.clearMask(!1),t.hasOwnProperty("isRexContainerLite")||e.setChildMaskVisible(t)})),t&&this.mask&&this.mask.destroy(),this}},_=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},M=function(t){return t.filter((function(t){return!!t.displayList||!!t.parentContainer||void 0}))},j={setDepth(t,e){if(this.depth=t,!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.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;var e=this.getAllChildren([this]);_(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;var e=this.getAllChildren([this]);_(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;var i=this.getAllChildren([this]);_(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;var i=this.getAllChildren([this]);_(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){var e;t!==this&&t.isRexContainerLite?(e=t.getAllChildren([t]),e=M(e),e=_(e,!1)):e=[t];var i=this.getAllChildren([this]);i=M(i);for(var r=(i=_(i,!1))[i.length-1],s=0,a=e.length;s<a;s++){var n=e[s];r!==n&&(n!==this&&r.displayList!==n.displayList||(r.displayList.moveAbove(n,r),r=n))}return this},sendChildToBack(t){var e;t!==this&&t.isRexContainerLite?(e=t.getAllChildren([t]),e=M(e),e=_(e,!1)):e=[t];var i=this.getAllChildren([this]);i=M(i);for(var r=(i=_(i,!1))[0],s=e.length-1;s>=0;s--){var a=e[s];r!==a&&(a!==this&&r.displayList!==a.displayList||(r.displayList.moveBelow(a,r),r=a))}return this}},V=function(t,e){if(!e(t)&&t.isRexContainerLite)for(var i=t.children,r=0,s=i.length;r<s;r++)V(i[r],e)},B=function(t,e){for(var i=[t];i.length>0;){var r=i.shift();!e(r)&&r.isRexContainerLite&&i.push(...r.children)}};const G=Phaser.Utils.Array;var D={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 B(e,(function(i){i!==e&&t.push(i)})),t},getAllVisibleChildren(t){void 0===t&&(t=[]);var e=this;return B(e,(function(i){if(i!==e)return!i.visible||void t.push(i)})),t},bfs(t,e){return void 0===e&&(e=this),B(e,t),this},dfs(t,e){return void 0===e&&(e=this),V(e,t),this},contains(t){var e=n(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 G.GetFirst(this.children,"name",t)},getRandom(t,e){return G.GetRandom(this.children,t,e)},getFirst(t,e,i,r){return G.GetFirstElement(this.children,t,e,i,r)},getAll(t,e,i,r){return G.GetAll(this.children,t,e,i,r)},count(t,e,i,r){return G.CountAllMatching(this.children,t,e,i,r)},swap(t,e){return G.Swap(this.children,t,e),this},setAll(t,e,i,r){return G.SetAll(this.children,t,e,i,r),this}},E=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},U=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()},z={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=E(e);var r=i.tweens.add(t);return r.on("update",U),r}},tweenSelf(t){return t.targets=[this],this.tweenChild(t)},createTweenChildConfig(t){var e=t.targets;e&&(Array.isArray(e)||(e=[e]),t.targets=E(e));var i=t.onUpdate;return t.onUpdate=function(t,e){i&&i(t,e),U(t,void 0,e)},t},tween(t){var e=this.scene;return t.targets||(t.targets=this),e.tweens.add(t)}};const I=Phaser.GameObjects.Container,W=Phaser.GameObjects.Layer;var H=function(t){return t instanceof W},N=function(t){var e=t.getAllChildren([t]);return e=e.filter((function(t){return!!t.displayList||!!t.parentContainer}))},$=function(t){var e=N(this);-1===e.indexOf(this)&&e.push(this),_(e),t.add(e)},Z=function(t,e,i){if(this.scene){var r=N(this);_(r,e),t.remove(r),i&&r.forEach((function(t){t.addToDisplayList()}))}},q={addToContainer(t){return t instanceof I?(this._setParentContainerFlag=!0,$.call(this,t),this._setParentContainerFlag=!1,this):this},addToLayer(t){return H(t)?($.call(this,t),this):this},removeFromContainer(){return this.parentContainer?(this._setParentContainerFlag=!0,Z.call(this,this.parentContainer,!0,!1),this._setParentContainerFlag=!1,this):this},removeFromLayer(t){return void 0===t&&(t=!0),H(this.displayList)?(Z.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||H(e)&&(t.isRexContainerLite?t.addToLayer(e):e.add(t)),this}},J={hasLayer(){return!!this.privateRenderLayer},enableLayer(){if(this.hasLayer())return this;var t=this.scene.add.layer();return this.moveDepthBelow(t),this.addToLayer(t),this.privateRenderLayer=t,this},getLayer(){return this.hasLayer()||this.enableLayer(),this.privateRenderLayer},getRenderLayer(){if(this.hasLayer())return this.privateRenderLayer;for(var t=this.getParent();t;){var e=t.privateRenderLayer;if(e)return e;t=t.getParent()}return null},addToRenderLayer(t){if(!t.displayList)return this;var e=this.getRenderLayer();return e?(e===t.displayList||(t.isRexContainerLite?t.addToLayer(e):e.add(t),o(t).layer=e),this):this},removeFromRenderLayer(t){var e=o(t),i=e.layer;return i?(t.isRexContainerLite?t.removeFromLayer(!0):i.remove(t),e.layer=null,this):this}},K=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},Q=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height};const tt=Phaser.Geom.Rectangle,et=Phaser.Math.Vector2,it=Phaser.Math.RotateAround,rt=Phaser.GameObjects.Container;var st=function(t,e){if(void 0===e?e=new tt:!0===e&&(void 0===at&&(at=new tt),e=at),t.getBounds&&!(t instanceof rt))return t.getBounds(e);var i,r,s,a,n,h,l,o;if(t.parentContainer){var c=t.parentContainer.getBoundsTransformMatrix();nt(t,e),c.transformPoint(e.x,e.y,e),i=e.x,r=e.y,ht(t,e),c.transformPoint(e.x,e.y,e),s=e.x,a=e.y,lt(t,e),c.transformPoint(e.x,e.y,e),n=e.x,h=e.y,ot(t,e),c.transformPoint(e.x,e.y,e),l=e.x,o=e.y}else nt(t,e),i=e.x,r=e.y,ht(t,e),s=e.x,a=e.y,lt(t,e),n=e.x,h=e.y,ot(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},at=void 0,nt=function(t,e,i){return void 0===e?e=new et:!0===e&&(void 0===ct&&(ct=new et),e=ct),t.getTopLeft?t.getTopLeft(e,i):(e.x=t.x-K(t)*t.originX,e.y=t.y-Q(t)*t.originY,dt(t,e,i))},ht=function(t,e,i){return void 0===e?e=new et:!0===e&&(void 0===ct&&(ct=new et),e=ct),t.getTopRight?t.getTopRight(e,i):(e.x=t.x-K(t)*t.originX+K(t),e.y=t.y-Q(t)*t.originY,dt(t,e,i))},lt=function(t,e,i){return void 0===e?e=new et:!0===e&&(void 0===ct&&(ct=new et),e=ct),t.getBottomLeft?t.getBottomLeft(e,i):(e.x=t.x-K(t)*t.originX,e.y=t.y-Q(t)*t.originY+Q(t),dt(t,e,i))},ot=function(t,e,i){return void 0===e?e=new et:!0===e&&(void 0===ct&&(ct=new et),e=ct),t.getBottomRight?t.getBottomRight(e,i):(e.x=t.x-K(t)*t.originX+K(t),e.y=t.y-Q(t)*t.originY+Q(t),dt(t,e,i))},ct=void 0,dt=function(t,e,i){return void 0===i&&(i=!1),0!==t.rotation&&it(e,t.x,t.y,t.rotation),i&&t.parentContainer&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e),e};const ut=Phaser.Geom.Rectangle,pt=Phaser.Geom.Rectangle.Union;var vt,yt=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 ft=Phaser.GameObjects.GameObject,gt=Phaser.GameObjects.Layer;var Ct=function(t){return t instanceof ft||t instanceof gt},mt=Phaser.Utils.Objects.GetValue,xt=function(t){if(t){var e=t.gameObjects;Array.isArray(e)||(e=[e]);var i,r,s=t.renderTexture,a=t.saveTexture,n=mt(t,"x",void 0),h=mt(t,"y",void 0),l=mt(t,"width",void 0),o=mt(t,"height",void 0),c=mt(t,"originX",0),d=mt(t,"originY",0),u=mt(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 ut:!0===e&&(void 0===vt&&(vt=new ut),e=vt),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=st(i,!0);r?(e.setTo(n.x,n.y,n.width,n.height),r=!1):pt(n,e,e)}return e}(e,!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),c=.5,d=.5):(n=p.x,h=p.y,l=p.width,o=p.height,c=0,d=0),i=p.x,r=p.y}else i=n+(0-c)*l,r=h+(0-d)*o;i-=u,r-=u,l+=2*u,o+=2*u;var v=e[0].scene,y=v.sys.textures;return a&&!s&&(s=y.addDynamicTexture(a,l,o)),s||(s=v.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(c,d),s.camera.setScroll(i,r),e=_(yt(e)),s.draw(e).render(),a&&(Ct(s)?s.saveTexture(a):s.key!==a&&y.renameTexture(s.key,key)),s}},bt={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=xt(t),a=!!s.scene;return r||(this.setScale(e,i),a&&s.setScale(e,i)),a?s:this}};const Pt=Phaser.Utils.Objects.GetValue;var Lt=function(t,e,i,r,s,a,n,h){if(t.getBounds||void 0!==t.width&&void 0!==t.height){var l=nt(t,At[0],h);l.x-=n,l.y-=n;var o=ht(t,At[1],h);o.x+=n,o.y-=n;var c=ot(t,At[2],h);c.x+=n,c.y+=n;var d=lt(t,At[3],h);d.x-=n,d.y+=n,null!==s&&e.fillStyle(s,a).fillPoints(At,!0,!0),null!==i&&e.lineStyle(r,i).strokePoints(At,!0,!0)}},At=[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const St=Phaser.Utils.Objects.GetValue,Ft=Phaser.Math.RotateAround;var Rt={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};Ft(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=St(e,"drawContainer",!0),r=St(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=Pt(i,"color"),s=Pt(i,"lineWidth"),a=Pt(i,"fillColor"),n=Pt(i,"fillAlpha"),h=Pt(i,"padding"),l=Pt(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,c=t.length;o<c;o++)Lt(t[o],e,r,s,a,n,h,l);else Lt(t,e,r,s,a,n,h,l)}(r,t,e),this}};Object.assign(Rt,c,g,x,b,P,A,F,R,T,k,X,Y,w,O,j,D,z,q,J,bt);class Tt extends s{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,this.privateRenderLayer=void 0,a&&this.add(a)}destroy(t){this.scene&&!this.ignoreDestroy&&(this.syncChildrenEnable=!1,super.destroy(t),this.privateRenderLayer&&this.privateRenderLayer.scene&&(this.privateRenderLayer.list.length=0,this.privateRenderLayer.destroy()))}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.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 n(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=n(this);return!!t&&t.setParentContainerFlag}}Object.assign(Tt.prototype,Rt);const kt=Phaser.Utils.Objects.GetValue;var Xt={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}},Yt=[Phaser.GameObjects.Image,Phaser.GameObjects.Sprite,Phaser.GameObjects.Mesh,Phaser.GameObjects.Shader,Phaser.GameObjects.Video],wt=[Phaser.GameObjects.BitmapText],Ot=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=Yt.length;e<i;e++){var r=Yt[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=wt.length;e<i;e++){var r=wt[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)}};const _t={fit:0,FIT:0,envelop:1,ENVELOP:1};var Mt={};const jt=Phaser.Utils.Objects.IsPlainObject;class Vt extends Tt{setBackground(t){var e,i,r,s,a,n,h,l,o,c,d,u;return jt(t)&&(e=this.scene,r=kt(i=t,"x",0),s=kt(i,"y",0),a=kt(i,"width",1),n=kt(i,"height",1),h=kt(i,"color",void 0),l=kt(i,"alpha",1),o=kt(i,"strokeColor",void 0),c=kt(i,"strokeAlpha",1),d=kt(i,"strokeWidth",2),u=e.add.rectangle(r,s,a,n),void 0!==h&&u.setFillStyle(h,l),void 0!==o&&u.setStrokeStyle(d,o,c),t=u,this.scene.add.existing(t)),t&&this.add(t),this.background=t,this}setImage(t){return t?t.setPosition(this.x,this.y).setOrigin(.5):t=this.scene.add.image(this.x,this.y),this.add(t),this.image=t,this.image.setFlipX(this.flipX).setFlipY(this.flipY),void 0!==this._colorTopLeft&&this.image.setTint(this._colorTopLeft,this._colorTopRight,this._colorBottomLeft,this._colorBottomRight),this}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))}set tint(t){this.image.tint=t}get isTinted(){return this.image.isTinted}setTint(t,e,i,r){return this._colorTopLeft=t,this._colorTopRight=e,this._colorBottomLeft=i,this._colorBottomRight=r,this.image.setTint(t,e,i,r),this}resizeBackground(){var t=this.background;return t?(t.setOrigin(this.originX,this.originY),t.setPosition(this.x,this.y),Ot(t,this.displayWidth,this.displayHeight),this.resetChildScaleState(t),this):this}scaleImage(){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=_t[i])}void 0===r?r={}:!0===r&&(r=Mt);var a=e.width/t.width,n=e.height/t.height,h=i?Math.max(a,n):Math.min(a,n),l=t.width*h,o=t.height*h;return Ct(r)?Ot(r,l,o):(r.width=l,r.height=o),r}(t,this,"FIT",!0);return t.setDisplaySize(e.width*this.scaleX,e.height*this.scaleY),this.resetChildScaleState(t),this}resize(t,e){return super.resize(t,e),this.resizeBackground(),this.scaleImage(),this}setTexture(t,e){var i=this.image;return i.setTexture(t,e),t?(this.setChildVisible(i,!0),this.scaleImage()):this.setChildVisible(i,!1),this}}Object.assign(Vt.prototype,Xt);const Bt=Phaser.Utils.Objects.IsPlainObject,Gt=Phaser.Utils.Objects.GetValue;class Dt extends Vt{constructor(t,e,i,r,s,a){Bt(e)?(e=Gt(a=e,"x",0),i=Gt(a,"y",0),r=Gt(a,"key",void 0),s=Gt(a,"frame",void 0)):Bt(s)&&(a=s,s=void 0),super(t,e,i,1,1),this.type="rexImageBox";var n=Gt(a,"background");this.setBackground(n);var h=Gt(a,"image");this.setImage(h),h=this.image,void 0===r?this.setChildVisible(h,!1):h.setTexture(r,s),this.scaleUp=Gt(a,"scaleUp",!1);var l=Gt(a,"width",h.width),o=Gt(a,"height",h.height);this.resize(l,o)}}function Et(t,e,i,r,s){var a=new Dt(this.scene,t,e,i,r,s);return this.scene.add.existing(a),a}const Ut=Phaser.Utils.Objects.GetAdvancedValue,zt=Phaser.GameObjects.BuildGameObject;function It(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=Ut(t,"key",null),r=Ut(t,"frame",null),s=new Dt(this.scene,0,0,i,r,t);return zt(this.scene,s,t),s}var Wt=function(t){return null==t||""===t||0===t.length};class Ht extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexImageBox",Et,It)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,i,r){if(void 0===r&&(r="."),"object"==typeof t)if(Wt(e)){if(null==i)return;"object"==typeof i&&(t=i)}else{"string"==typeof e&&(e=e.split(r));var s=e.pop(),a=function(t,e,i){var r=t;if(Wt(e));else{var s;"string"==typeof e&&(e=e.split("."));for(var a=0,n=e.length;a<n;a++){var h;null!=r[s=e[a]]&&"object"==typeof r[s]||(h=a===n-1?void 0===i?{}:i:{},r[s]=h),r=r[s]}}return r}(t,e);a[s]=i}}(window,"RexPlugins.GameObjects.ImageBox",Dt),Ht},"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();