phaser4-rex-plugins
Version:
2 lines (1 loc) • 1.24 kB
JavaScript
var e,t;e=void 0,t=function(){const e=Phaser.Cameras.Scene2D.BaseCamera,t=Phaser.Geom.Rectangle;var n=function(n,i,o){return i instanceof e||(o=i,i=void 0),void 0===o?o=new t:!0===o&&(o=r),i?n.scale.getViewPort(i,o):n.scale.getViewPort(o)},r=new t;const i=Phaser.Utils.Objects.GetValue,o=Phaser.Utils.Objects.IsPlainObject,s=Phaser.Geom.Circle,a=Phaser.Geom.Intersects.CircleToCircle;class l extends Phaser.Plugins.BasePlugin{constructor(e){super(e)}start(){this.game.events.on("destroy",this.destroy,this)}randomPlace(e,t){return function(e,t){if(0===e.length)return e;var r=i(t,"getPositionCallback",void 0);if(void 0===r){var l=i(t,"area",void 0);if(void 0===l){var c=e[0];f=o(c)?c.gameObject:c,l=n(f.scene)}r=l.getRandomPoint.bind(l)}for(var d,f,u,h=i(t,"radius",0),v=[],g=0,P=e.length;g<P;g++)if(d=e[g],o(d)?(f=i(d,"gameObject",void 0),u=i(d,"radius",h)):(f=d,u=h),f)if(u<=0)r(f);else{var m,b=new s(0,0,u);do{r(b),m=!1;for(var p=0,y=v.length;p<y&&!(m=a(b,v[p]));p++);}while(m);v.push(b),f.setPosition(b.x,b.y)}return e}(e,t)}}return l},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexrandomplaceplugin=t();