UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 2.34 kB
var e,t;e=void 0,t=function(){const e=Phaser.Loader.FILE_POPULATED,t=Phaser.Utils.String.UUID;class n extends Phaser.Loader.File{constructor(e,n){n.hasOwnProperty("type")||(n.type="await"),n.hasOwnProperty("url")||(n.url=""),n.hasOwnProperty("key")||(n.key=t()),super(e,n)}load(){if(this.state===e)this.loader.nextFile(this,!0);else{var t=this.config,n=t.callback,o=t.scope;if(n){var s=this,i=!1,r=function(){i||(setTimeout((function(){s.onLoad()}),0),i=!0)},a=function(){i||(setTimeout((function(){s.onError()}),0),i=!0)};o?n.call(o,r,a):n(r,a)}else this.onLoad()}}onLoad(){this.loader.nextFile(this,!0)}onError(){this.loader.nextFile(this,!1)}}const o=Phaser.Utils.Objects.IsPlainObject,s=function(e,t){var s;return(s=e)&&"function"==typeof s?t={config:{callback:e,scope:t}}:o(e)?(t=e).hasOwnProperty("config")||(t={config:t}):t={key:e,config:t},this.addFile(new n(this,t)),this},i=Phaser.Scene;var r=function(e){return e instanceof i},a=function(e,t){void 0===t&&(t=0);var n=(e=function(e){return r(e)?e.load:e}(e)).totalToLoad-t;return 1-(e.list.size+e.inflight.size-t)/n};class c extends Phaser.Events.EventEmitter{constructor(e){super(),this.scene=e,this.boot()}boot(){var e=this,t=this.scene.load;s.call(t,(function(n,o){var s=function(){var n=a(t,1);e.emit("progress",n),1===n&&(0===e.listenerCount("complete")?r():e.emit("complete",r))},i=!1,r=function(){i||(i=!0,e.emit("shutdown"),t.off("progress",s),n(),e.destroy())};t.on("progress",s)}))}destroy(){this.scene=void 0,super.destroy()}}const l=Phaser.Utils.Objects.IsPlainObject;class u extends Phaser.Plugins.BasePlugin{constructor(e){super(e),e.registerFileType("rexAwait",s)}addToScene(e){e.sys.load.rexAwait=s}startScene(e,t,n,o){!function(e,t,n,o,s){if(l(e)){var i=e;e=i.mainScene,t=i.animationScene,o=i.onLoadingComplete,s=i.onLoadingProgress}else"function"==typeof n&&(s=o,o=n,n=void 0);r(t)&&(t=(a=t).sys.settings.key),e.scene.getStatus(t)<Phaser.Scenes.START&&e.scene.launch(t,n);var a=e.scene.get(t);new c(e).on("progress",(function(e){s&&s(e,a)})).on("complete",(function(e){o?o(e,a):e()})).on("shutdown",(function(){a.scene.stop()}))}(e,t,n,o)}}return u},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexloadinganimationsceneplugin=t();