var gdjs;(function(x){const l=new x.Logger("PIXI Image manager"),d=GlobalPIXIModule.PIXI,T=(a,e)=>{l.error("Unable to load file "+a+" with error:",e||"(unknown error)")},E=(a,e)=>{!a||e.smoothed||(a.baseTexture.scaleMode=d.SCALE_MODES.NEAREST)},R=(a,e)=>{e&&!e.smoothed&&(a.magFilter=THREE.NearestFilter,a.minFilter=THREE.NearestFilter)},g=(a,e,r)=>{for(let s=0,t=a.length;s<t;++s){const i=a[s];if(i.name===e&&i.kind===r)return i}return null};class A{constructor(e,r){this._resources=e,this._resourcesLoader=r,this._invalidTexture=d.Texture.from("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAFElEQVQoU2P8z/D/PwMewDgyFAAApMMX8Zi0uXAAAAAASUVORK5CYIIA"),this._loadedTextures=new Hashtable,this._loadedThreeTextures=new Hashtable,this._loadedThreeMaterials=new Hashtable}setResources(e){this._resources=e}getPIXITexture(e){if(this._loadedTextures.containsKey(e)){const i=this._loadedTextures.get(e);if(i.valid)return i;l.error("Texture for "+e+" is not valid anymore (or never was).")}if(e==="")return this._invalidTexture;const r=g(this._resources,e,"image");if(!r)return l.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;l.log('Loading texture for resource "'+e+'"...');const s=r.file,t=d.Texture.from(this._resourcesLoader.getFullUrl(s),{resourceOptions:{crossorigin:this._resourcesLoader.checkIfCredentialsRequired(s)?"use-credentials":"anonymous"}}).on("error",i=>{T(s,i)});return E(t,r),this._loadedTextures.put(e,t),t}getThreeTexture(e){const r=this._loadedThreeTextures.get(e);if(r)return r;const s=this.getPIXITexture(e);if(!this._resourcesLoader._runtimeGame.getRenderer().getPIXIRenderer())throw new Error("No PIXI renderer was found.");const i=s.baseTexture.resource.source;if(!(i instanceof HTMLImageElement))throw new Error(`Can't load texture for resource "${e}" as it's not an image.`);const o=new THREE.Texture(i);o.magFilter=THREE.LinearFilter,o.minFilter=THREE.LinearFilter,o.wrapS=THREE.RepeatWrapping,o.wrapT=THREE.RepeatWrapping,o.needsUpdate=!0;const h=g(this._resources,e,"image");return R(o,h),this._loadedThreeTextures.put(e,o),o}getThreeMaterial(e,{useTransparentTexture:r,forceBasicMaterial:s}){const t=`${e}|${r?1:0}|${s?1:0}`,i=this._loadedThreeMaterials.get(t);if(i)return i;const o=s?new THREE.MeshBasicMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r}):new THREE.MeshStandardMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r,metalness:0});return this._loadedThreeMaterials.put(t,o),o}getPIXIVideoTexture(e){if(this._loadedTextures.containsKey(e))return this._loadedTextures.get(e);if(e==="")return this._invalidTexture;const r=g(this._resources,e,"video");if(!r)return l.warn('Unable to find video texture for resource "'+e+'".'),this._invalidTexture;const s=r.file;l.log('Loading video texture for resource "'+e+'"...');const t=d.Texture.from(this._resourcesLoader.getFullUrl(s),{resourceOptions:{crossorigin:this._resourcesLoader.checkIfCredentialsRequired(s)?"use-credentials":"anonymous"}}).on("error",i=>{T(s,i)});return this._loadedTextures.put(e,t),t}getInvalidPIXITexture(){return this._invalidTexture}loadTextures(e,r){const s=this._resources,t={};for(let u=0,c=s.length;u<c;++u){const n=s[u];if(n.file&&n.kind==="image"){if(this._loadedTextures.containsKey(n.name))continue;t[n.file]=t[n.file]?t[n.file].concat(n):[n]}}const i=Object.keys(t).length;if(i===0)return r(i);const o=d.Loader.shared;let h=0;const _=o.onProgress.add(function(){h++,e(h,i)});for(const u in t)t.hasOwnProperty(u)&&o.add({name:u,url:this._resourcesLoader.getFullUrl(u),loadType:d.LoaderResource.LOAD_TYPE.IMAGE,crossOrigin:this._resourcesLoader.checkIfCredentialsRequired(u)?"use-credentials":"anonymous"});o.load((u,c)=>{u.onProgress.detach(_);for(const n in c)if(c.hasOwnProperty(n)){if(!t.hasOwnProperty(n))continue;t[n].forEach(I=>{const f=c[n].texture;if(!f){const p=c[n].error;T(n,p);return}this._loadedTextures.put(I.name,f),E(f,I)})}r(i)})}}x.PixiImageManager=A,x.ImageManager=x.PixiImageManager})(gdjs||(gdjs={}));
//# sourceMappingURL=pixi-image-manager.js.map
