phaser4-rex-plugins
Version:
2 lines (1 loc) • 1.93 kB
JavaScript
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,r=t.scope;if(n){var i=this,o=!1,s=function(){o||(setTimeout((function(){i.onLoad()}),0),o=!0)},a=function(){o||(setTimeout((function(){i.onError()}),0),o=!0)};r?n.call(r,s,a):n(s,a)}else this.onLoad()}}onLoad(){this.loader.nextFile(this,!0)}onError(){this.loader.nextFile(this,!1)}}var r=function(e){return new Promise((function(t,n){!function(e,t){for(var n=document.getElementsByTagName("script"),r=0,i=n.length;r<i;r++)if(-1!=n[r].src.indexOf(e))return void(t&&t());var o=document.createElement("script");o.setAttribute("src",e),t&&(o.onload=t),document.head.appendChild(o)}(e,t)}))};const i=Phaser.Utils.Objects.IsPlainObject,o=Phaser.Utils.Objects.GetFastValue,s=function(e){if(Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.addFile(a(this,e[t]));else this.addFile(a(this,e));return this};var a=function(e,t,s){if(i(t)){var a=t;t=o(a,"url"),s=o(a,"availableTest")}return new n(e,{type:"scriptTag",config:{callback:function(e,n){r(t).then((function(){if(!s)return Promise.resolve();var e=function(){return s()?Promise.resolve():(t=10,void 0===t&&(t=0),new Promise((function(e,r){setTimeout((function(){e(n)}),t)}))).then((function(){return e()}));var t,n};return e()})).then((function(){e()}))}}})};class l extends Phaser.Plugins.BasePlugin{constructor(e){super(e),e.registerFileType("rexScriptTag",s)}addToScene(e){e.sys.load.rexScriptTag=s}}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).rexscripttagloaderplugin=t();