Loader can now handle script files

This commit is contained in:
Richard Davey 2017-07-11 19:23:03 +01:00
parent 3e131d5369
commit b4e84860da
3 changed files with 56 additions and 1 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = { var CHECKSUM = {
build: '301d58e0-6661-11e7-a646-9f2c5eee0a48' build: '9eb76a80-6665-11e7-ab02-edf4fee981c3'
}; };
module.exports = CHECKSUM; module.exports = CHECKSUM;

View file

@ -0,0 +1,47 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
// Phaser.Loader.FileTypes.ScriptFile
var ScriptFile = new Class({
Extends: File,
initialize:
function ScriptFile (key, url, path, xhrSettings)
{
var fileConfig = {
type: 'script',
extension: 'js',
responseType: 'text',
key: key,
url: url,
path: path,
xhrSettings: xhrSettings
};
File.call(this, fileConfig);
},
onProcess: function (callback)
{
this.state = CONST.FILE_PROCESSING;
this.data = document.createElement('script');
this.data.language = 'javascript';
this.data.type = 'text/javascript';
this.data.defer = false;
this.data.text = this.xhrLoader.responseText;
document.head.appendChild(this.data);
this.onComplete();
callback(this);
}
});
module.exports = ScriptFile;

View file

@ -11,6 +11,7 @@ var GLSLFile = require('../loader/filetypes/GLSLFile');
var HTMLFile = require('../loader/filetypes/HTMLFile'); var HTMLFile = require('../loader/filetypes/HTMLFile');
var ImageFile = require('../loader/filetypes/ImageFile'); var ImageFile = require('../loader/filetypes/ImageFile');
var JSONFile = require('../loader/filetypes/JSONFile'); var JSONFile = require('../loader/filetypes/JSONFile');
var ScriptFile = require('../loader/filetypes/ScriptFile');
var SpriteSheet = require('../loader/filetypes/SpriteSheet'); var SpriteSheet = require('../loader/filetypes/SpriteSheet');
var SVGFile = require('../loader/filetypes/SVGFile'); var SVGFile = require('../loader/filetypes/SVGFile');
var TextFile = require('../loader/filetypes/TextFile'); var TextFile = require('../loader/filetypes/TextFile');
@ -107,6 +108,13 @@ var Loader = new Class({
return this.addFile(file); return this.addFile(file);
}, },
script: function (key, url, xhrSettings)
{
var file = new ScriptFile(key, url, this.path, xhrSettings);
return this.addFile(file);
},
xml: function (key, url, xhrSettings) xml: function (key, url, xhrSettings)
{ {
var file = new XMLFile(key, url, this.path, xhrSettings); var file = new XMLFile(key, url, this.path, xhrSettings);