UNPKG

playcanvas

Version:

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

46 lines (45 loc) 1.07 kB
import { http } from "../../platform/net/http.js"; import { Template } from "../template.js"; import { ResourceHandler } from "./handler.js"; class TemplateHandler extends ResourceHandler { decoder = null; constructor(app) { super(app, "template"); } 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; } } export { TemplateHandler };