playcanvas
Version:
PlayCanvas WebGL game engine
50 lines (47 loc) • 1.48 kB
JavaScript
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
};
}
// we need to specify JSON for blob URLs
var 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);
}
/**
* Parses raw DataView and returns string.
*
* @param {DataView} data - The raw data as a DataView
* @returns {Template} The parsed resource data.
*/ openBinary(data) {
var _this_decoder;
(_this_decoder = this.decoder) != null ? _this_decoder : this.decoder = new TextDecoder('utf-8');
return new Template(this._app, JSON.parse(this.decoder.decode(data)));
}
constructor(app){
super(app, 'template'), /**
* TextDecoder for decoding binary data.
*
* @type {TextDecoder|null}
* @private
*/ this.decoder = null;
}
}
export { TemplateHandler };