UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

45 lines (42 loc) 1.15 kB
import { http } from '../../platform/net/http.js'; import { Template } from '../template.js'; import { ResourceHandler } from './handler.js'; class TemplateHandler extends ResourceHandler { load(url, callback) { if (typeof url === 'string') { url = { load: url, original: url }; } const options = { retry: this.maxRetries > 0, maxRetries: this.maxRetries }; http.get(url.load, options, (err, response)=>{ if (err) { callback(`Error requesting template: ${url.original}`); } else { callback(err, response); } }); } open(url, data) { return new Template(this._app, data); } openBinary(data) { this.decoder ?? (this.decoder = new TextDecoder('utf-8')); return new Template(this._app, JSON.parse(this.decoder.decode(data))); } patch(asset, registry) { if (!asset || !asset.resource || !asset.data || !asset.data.entities) { return; } const template = asset.resource; template.data = asset.data; } constructor(app){ super(app, 'template'), this.decoder = null; } } export { TemplateHandler };