phaser4-rex-plugins
Version:
2 lines (1 loc) • 6.13 kB
JavaScript
var t,e;t=void 0,e=function(){var t={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 s=function(t){return t instanceof e};const i=Phaser.Game;var n=function(t){return t instanceof i};const r=Phaser.Utils.Objects.GetValue;class h{constructor(t,e){this.setParent(t),this.isShutdown=!1,this.setEventEmitter(r(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:s(e)?e:e.scene&&s(e.scene)?e.scene:e.parent&&e.parent.scene&&s(e.parent.scene)?e.parent.scene:null,this.game=function(t){return null==t||"object"!=typeof t?null:n(t)?t:n(t.game)?t.game:s(t)?t.sys.game:s(t.scene)?t.scene.sys.game:void 0}(t),this}}Object.assign(h.prototype,t);const a=Phaser.Utils.Objects.GetValue;class o extends h{constructor(t,e){super(t,e),this._isRunning=!1,this.isPaused=!1,this.tickingState=!1,this.setTickingMode(a(e,"tickingMode",1))}boot(){2!==this.tickingMode||this.tickingState||this.startTicking()}shutdown(t){this.isShutdown||(this.stop(),this.tickingState&&this.stopTicking(),super.shutdown(t))}setTickingMode(t){"string"==typeof t&&(t=u[t]),this.tickingMode=t}startTicking(){this.tickingState=!0}stopTicking(){this.tickingState=!1}get isRunning(){return this._isRunning}set isRunning(t){this._isRunning!==t&&(this._isRunning=t,1===this.tickingMode&&t!=this.tickingState&&(t?this.startTicking():this.stopTicking()))}start(){return this.isPaused=!1,this.isRunning=!0,this}pause(){return this.isRunning&&(this.isPaused=!0,this.isRunning=!1),this}resume(){return this.isPaused&&(this.isPaused=!1,this.isRunning=!0),this}stop(){return this.isPaused=!1,this.isRunning=!1,this}complete(){this.isPaused=!1,this.isRunning=!1,this.emit("complete",this.parent,this)}}const u={no:0,lazy:1,always:2},c=Phaser.Utils.Objects.GetValue;class p extends o{constructor(t,e){super(t,e);var s=this.scene?"update":"step";this.tickEventName=c(e,"tickEventName",s),this.isSceneTicker=!v(this.tickEventName)}startTicking(){super.startTicking(),this.isSceneTicker?this.scene.sys.events.on(this.tickEventName,this.update,this):this.game.events.on(this.tickEventName,this.update,this)}stopTicking(){super.stopTicking(),this.isSceneTicker&&this.scene?this.scene.sys.events.off(this.tickEventName,this.update,this):this.game&&this.game.events.off(this.tickEventName,this.update,this)}}var v=function(t){return"step"===t||"poststep"===t},d=function(t,e,s,i){var n=t.body,r=n.velocity.x,h=n.velocity.y;e===r&&s===h||(n.setVelocity(e,s),i&&i(e,s,r,h))};const m=Phaser.Utils.Objects.GetValue,l=Phaser.Math.DegToRad,g=Phaser.Math.RadToDeg;class E extends p{constructor(t,e){super(t,e),this.resetFromJSON(e),this.boot()}resetFromJSON(t){this.parent.body||this.scene.physics.add.existing(this.parent,!1),this.setWrapMode(m(t,"wrap",!1),m(t,"padding",0)),this.setEnable(m(t,"enable",!0)),this.setSpeed(m(t,"speed",200));var e=m(t,"angle");if(void 0!==e){this.setAngle(e);var s=m(t,"rotation");void 0!==s&&this.setRotation(s)}return this}get enable(){return this.isRunning}set enable(t){this.isRunning=t,t||d(this.parent,0,0)}setEnable(t){return null==t&&(t=!0),this.enable=t,this}setSpeed(t){return this.speed=t,this}setWrapMode(t,e){return void 0===t&&(t=!0),this.wrap=t,this.padding=e,this}setAngle(t){return this.angle=t,this}setRotation(t){return this.rotation=t,this}set angle(t){"number"==typeof t&&(t=l(t)),this.rotation=t}get angle(){var t=this.rotation;return"number"==typeof t&&(t=g(t)),t}update(t,e){var s=this.parent;if(!this.enable)return d(s,0,0),this;if(!s.active)return this;var i=this.rotation;null==i&&(i=s.rotation);var n=this.speed*Math.cos(i),r=this.speed*Math.sin(i);return d(s,n,r),this.wrap&&s.body.world.wrap(s,this.padding),this}}class y extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e){return new E(t,e)}}return y},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexbulletplugin=e();