UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 2.48 kB
var e,t;e=void 0,t=function(){const e=Phaser.Utils.Objects.GetValue,t=Phaser.Geom.Rectangle,o=Phaser.Utils.Objects.GetValue;var r,a,i=function(i,n){void 0===r&&(r=new t),a=function(t,o){return void 0===t&&(t=0),void 0===o&&(o={}),"number"==typeof t?(o.left=t,o.right=t,o.top=t,o.bottom=t):(o.left=e(t,"left",0),o.right=e(t,"right",0),o.top=e(t,"top",0),o.bottom=e(t,"bottom",0)),o}(o(n,"padding",0),a);var s=i.width,l=i.height,c=-s/2-a.left,d=-l/2-a.top;s+=a.left+a.right,l+=a.top+a.bottom,r.setTo(c,d,s,l);var u=o(n,"stepRate",10);return r.getPoints(0,u)};const n=Phaser.Utils.Objects.GetValue,s=1e3/60,l=Phaser.GameObjects.Particles.ParticleEmitter.prototype.preUpdate,c=Phaser.Utils.Objects.GetValue,d=Phaser.Math.Vector2;var u,f=function(e){void 0===u&&(u={x:0,y:0}),e.getCenter(u),this.setPosition(u.x,u.y).setScale(e.scaleX,e.scaleY).setAngle(e.angle).setAlpha(e.alpha),this.depth!==e.depth&&this.setDepth(e.depth)},p=function(e,t){void 0===t&&(t={});var o=function(e,t){var o=i(e,t),r={blendMode:n(t,"blendMode","ADD"),emitZone:{type:"edge",source:{getPoints:function(){return o}},yoyo:n(t,"yoyo",!1)},speed:n(t,"spread",10)},a=n(t,"lifespan",1e3);r.lifespan=a;var l=n(t,"duration",void 0);if(void 0!==l){var c=l-a;if(c<=0)r.quantity=o.length;else{var d=c/o.length;d<=s?r.quantity=Math.ceil(s/d):r.frequency=d}}var u=(1+n(t,"repeat",0))*o.length;r.hasOwnProperty("frequency")?r.emitCallback=function(e,t){(u-=1)<=0&&t.stop()}:r.stopAfter=u;var f=n(t,"textureFrames",void 0);f&&(r.frame={frames:f,cycle:n(t,"textureFrameCycle",!0)});var p=n(t,"scale",void 0);void 0!==p&&(r.scale=p);var h=n(t,"alpha",void 0);void 0!==h&&(r.alpha=h);var v=n(t,"tint",void 0);return void 0!==v&&(r.tint=v),r}(e,t),r=e.scene.add.particles(0,0,t.textureKey,o);return function(e,t,o){var r=c(o,"gravityX",0),a=c(o,"gravityY",0),i=0!==r||0!==a;e.preUpdate=function(o,n,s){if(t.scene){if(f.call(e,t),i){var c,u;if(0!==t.rotation){var p=new d;p.setTo(r,a).rotate(-t.rotation),c=p.x,u=p.y}else c=r,u=a;e.setParticleGravity(c,u)}l.call(e,o,n,s)}else this.destroy()}.bind(e)}(r,e,t),r.once("complete",(function(){r.destroy()})),r};class h extends Phaser.Plugins.BasePlugin{constructor(e){super(e)}start(){this.game.events.on("destroy",this.destroy,this)}startEffect(e,t){return p(e,t)}}return h},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexparticlesalongboundsplugin=t();