From b4e84860da9fbc40ef671e2690613fad460e3931 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 11 Jul 2017 19:23:03 +0100 Subject: [PATCH] Loader can now handle script files --- v3/src/checksum.js | 2 +- v3/src/loader/filetypes/ScriptFile.js | 47 +++++++++++++++++++++++++++ v3/src/plugins/Loader.js | 8 +++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 v3/src/loader/filetypes/ScriptFile.js diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 5801272f6..686bc7b14 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '301d58e0-6661-11e7-a646-9f2c5eee0a48' +build: '9eb76a80-6665-11e7-ab02-edf4fee981c3' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/loader/filetypes/ScriptFile.js b/v3/src/loader/filetypes/ScriptFile.js new file mode 100644 index 000000000..62b862100 --- /dev/null +++ b/v3/src/loader/filetypes/ScriptFile.js @@ -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; diff --git a/v3/src/plugins/Loader.js b/v3/src/plugins/Loader.js index 9400df69e..a464a3c2a 100644 --- a/v3/src/plugins/Loader.js +++ b/v3/src/plugins/Loader.js @@ -11,6 +11,7 @@ var GLSLFile = require('../loader/filetypes/GLSLFile'); var HTMLFile = require('../loader/filetypes/HTMLFile'); var ImageFile = require('../loader/filetypes/ImageFile'); var JSONFile = require('../loader/filetypes/JSONFile'); +var ScriptFile = require('../loader/filetypes/ScriptFile'); var SpriteSheet = require('../loader/filetypes/SpriteSheet'); var SVGFile = require('../loader/filetypes/SVGFile'); var TextFile = require('../loader/filetypes/TextFile'); @@ -107,6 +108,13 @@ var Loader = new Class({ 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) { var file = new XMLFile(key, url, this.path, xhrSettings);