3 lines
15 KiB
JavaScript
3 lines
15 KiB
JavaScript
var gdjs;(function(c){const d=new c.Logger("ResourceLoader"),i=new c.Logger("ResourceLoader - debug").enable(!1),R=(g,e,s)=>{if(g.startsWith("data:")||g.startsWith("blob:"))return g;const r=g.indexOf("?")===-1?"?":"&";return g+r+e+"="+s},p=g=>g.startsWith("https://project-resources.gdevelop.io/")||g.startsWith("https://project-resources-dev.gdevelop.io/");class m{constructor(e){this.isFinished=!1;this.identifier=e,this.onProgressCallbacks=new Array,this.onFinishCallbacks=new Array}registerCallback(e,s){if(this.isFinished){e();return}this.onFinishCallbacks.push(e),s&&this.onProgressCallbacks.push(s)}onProgress(e,s){for(const r of this.onProgressCallbacks)r(e,s)}onFinish(){this.isFinished=!0;for(const e of this.onFinishCallbacks)e()}}c.LoadingTask=m;class _{async loadResource(e){}async processResource(e){}getResourceKinds(){return["internal-in-game-editor-only-svg"]}unloadResource(e){}dispose(){}}const u=class{constructor(e,s,r,o){this._spineAtlasManager=null;this._spineManager=null;this.privateResourceManager=new y(this);this.sceneResourceLoadingQueue=new M("scene",this.privateResourceManager,!1,(e,s,r,o)=>this._getResourcesOnlyUsedInUnloadedScene(e,s,r,o));this.objectResourceLoadingQueues=new Map;this._runtimeGame=e,this._globalResources=r,this.setResources(s,r,o),this._imageManager=new c.ImageManager(this),this._soundManager=new c.SoundManager(this),this._fontManager=new c.FontManager(this),this._jsonManager=new c.JsonManager(this),this._bitmapFontManager=new c.BitmapFontManager(this,this._imageManager),this._model3DManager=new c.Model3DManager(this),this._svgManager=new _;const t=[this._imageManager,this._soundManager,this._fontManager,this._jsonManager,this._bitmapFontManager,this._model3DManager,this._svgManager];this._resourceManagersMap=new Map;for(const a of t)for(const n of a.getResourceKinds())this._resourceManagersMap.set(n,a);this._registerOptionalManagersIfNeeded()}getRuntimeGame(){return this._runtimeGame}setResources(e,s,r){this._globalResources=s,this.sceneResourceLoadingQueue.clear();for(const o of this.objectResourceLoadingQueues.values())o.clear();for(const o of r)this.sceneResourceLoadingQueue.registerResources(o.name,o.usedResources);for(let o=r.length-1;o>=0;o--){const t=r[o],a=t.resourcesPreloading||"inherit";(a==="inherit"?this._runtimeGame.getSceneResourcesPreloading():a)==="at-startup"&&this.sceneResourceLoadingQueue.enqueue(t.name)}this.privateResourceManager._resources.clear();for(const o of e)!o.file||this.privateResourceManager._resources.set(o.name,o)}async loadAllResources(e){let s=0;await u.processAndRetryIfNeededWithPromisePool([...this.privateResourceManager._resources.values()],u.maxForegroundConcurrency,u.maxAttempt,async r=>{await this.privateResourceManager._loadResource(r),await this.privateResourceManager._processResource(r),s++,e(s,this.privateResourceManager._resources.size)}),this.sceneResourceLoadingQueue.setAllResourcesAs("ready");for(const r of this.objectResourceLoadingQueues.values())r.setAllResourcesAs("ready")}async loadResources(e,s){let r=0;await u.processAndRetryIfNeededWithPromisePool(e,u.maxForegroundConcurrency,u.maxAttempt,async o=>{const t=this.privateResourceManager._resources.get(o);t&&(await this.privateResourceManager._loadResource(t),await this.privateResourceManager._processResource(t)),r++,s(r,this.privateResourceManager._resources.size)})}async loadGlobalAndFirstSceneResources(e,s){const r=this.sceneResourceLoadingQueue.getResourceNamesFor(e);if(!r){d.warn(`Can't load resource for unknown scene: "`+e+'".');return}let o=0;const t=[...this._globalResources,...r];await u.processAndRetryIfNeededWithPromisePool(t,u.maxForegroundConcurrency,u.maxAttempt,async a=>{const n=this.privateResourceManager._resources.get(a);if(!n){d.warn('Unable to find resource "'+a+'".');return}await this.privateResourceManager._loadResource(n),await this.privateResourceManager._processResource(n),o++,s(o,t.length)}),this.sceneResourceLoadingQueue.setResourcesAs(e,"ready")}async loadAllSceneInBackground(){this.sceneResourceLoadingQueue.loadAllTasksInBackground()}async loadAndProcessS
|
|||
|
|
//# sourceMappingURL=ResourceLoader.js.map
|