var gdjs;(function(l){const c=new l.Logger("JSON Manager"),i=["json","tilemap","tileset"];class d{constructor(e){this._loadedJsons=new l.ResourceCache;this._callbacks=new l.ResourceCache;this._getJsonResource=e=>{const o=this._resourceLoader.getResource(e);return o&&this.getResourceKinds().includes(o.kind)?o:null};this._resourceLoader=e}getResourceKinds(){return i}async loadResource(e){const o=this._resourceLoader.getResource(e);if(!o){c.warn('Unable to find json for resource "'+e+'".');return}if(!o.disablePreload)try{await this.loadJsonAsync(o.name)}catch(s){throw c.error(`Error while preloading json resource ${o.name}:`,s),s}}loadJsonAsync(e){const o=this;return new Promise((s,t)=>{o.loadJson(e,(r,n)=>{r&&t(r.message),s(n)})})}async processResource(e){}loadJson(e,o){const s=this._getJsonResource(e);if(!s){o(new Error(`Can't find resource with name: "`+e+'" (or is not a json resource).'),null);return}if(this._loadedJsons.get(s)){o(null,this._loadedJsons.get(s));return}{const n=this._callbacks.get(s);if(n){n.push(o);return}else this._callbacks.set(s,[o])}const t=this,r=new XMLHttpRequest;r.responseType="json",r.withCredentials=this._resourceLoader.checkIfCredentialsRequired(s.file),r.open("GET",this._resourceLoader.getFullUrl(s.file)),r.onload=function(){const n=t._callbacks.get(s);if(!!n){if(r.status!==200){for(const a of n)a(new Error("HTTP error: "+r.status+"("+r.statusText+")"),null);t._callbacks.delete(s);return}t._loadedJsons.set(s,r.response);for(const a of n)a(null,r.response);t._callbacks.delete(s)}},r.onerror=function(){const n=t._callbacks.get(s);if(!!n){for(const a of n)a(new Error("Network error"),null);t._callbacks.delete(s)}},r.onabort=function(){const n=t._callbacks.get(s);if(!!n){for(const a of n)a(new Error("Request aborted"),null);t._callbacks.delete(s)}},r.send()}isJsonLoaded(e){return!!this._loadedJsons.getFromName(e)}getLoadedJson(e){return this._loadedJsons.getFromName(e)||null}dispose(){this._loadedJsons.clear(),this._callbacks.clear()}unloadResource(e){this._loadedJsons.getFromName(e.name)&&this._loadedJsons.delete(e),this._callbacks.getFromName(e.name)&&this._callbacks.delete(e)}}l.JsonManager=d})(gdjs||(gdjs={}));
//# sourceMappingURL=jsonmanager.js.map
