@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 712 B
JavaScript
import{Bundle as e}from"../bundle/bundle.js";import{Untar as t}from"./untar.js";import{ResourceHandler as s}from"./handler.js";class r extends s{constructor(e){super(e,"bundle"),this._assets=e.assets}_fetchRetries(e,t,s=0){return new Promise(((r,n)=>{const o=()=>{fetch(e,t).then(r).catch((e=>{++s<this.maxRetries?o():n(e)}))};o()}))}load(s,r){"string"==typeof s&&(s={load:s,original:s}),this._fetchRetries(s.load,{mode:"cors",credentials:"include"},this.maxRetries).then((s=>{const n=new e;r(null,n);const o=new t(s,this._assets.prefix);o.on("file",(e=>{n.addFile(e.name,e.data)})),o.on("done",(()=>{n.loaded=!0})),o.on("error",(e=>{r(e)}))})).catch((e=>{r(e)}))}open(e,t){return t}}export{r as BundleHandler};