UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 1.29 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 r=this,i=!1,a=function(){i||(setTimeout((function(){r.onLoad()}),0),i=!0)},s=function(){i||(setTimeout((function(){r.onError()}),0),i=!0)};o?n.call(o,a,s):n(a,s)}else this.onLoad()}}onLoad(){this.loader.nextFile(this,!0)}onError(){this.loader.nextFile(this,!1)}}const o=function(e,t,n){return this.addFile(r(this,e,t,n)),this};var r=function(e,t,o,r){return new n(e,{type:"imageuri",config:{key:t,callback:function(n,i){var a=new Image;a.onload=function(){void 0===r?e.textureManager.addImage(t,a):e.textureManager.addSpriteSheet(t,a,r),n()},a.src=o}}})};class i extends Phaser.Plugins.BasePlugin{constructor(e){super(e),e.registerFileType("rexImageURI",o)}addToScene(e){e.sys.load.rexImageURI=o}}return i},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).reximageuriloaderplugin=t();