Merge remote-tracking branch 'origin/master'

This commit is contained in:
Pavle Goloskokovic 2018-01-19 12:08:40 +01:00
commit f019b8ad75
4 changed files with 91 additions and 7 deletions

View file

@ -204,7 +204,7 @@ File.createObjectURL = function (image, blob, defaultType)
*/
File.revokeObjectURL = function (image)
{
if(URL)
if (typeof URL === 'function')
{
URL.revokeObjectURL(image.src);
}

View file

@ -15,6 +15,7 @@ var GLSLFile = require('./filetypes/GLSLFile');
var HTMLFile = require('./filetypes/HTMLFile');
var ImageFile = require('./filetypes/ImageFile');
var JSONFile = require('./filetypes/JSONFile');
var PluginFile = require('./filetypes/PluginFile');
var ScriptFile = require('./filetypes/ScriptFile');
var SpriteSheet = require('./filetypes/SpriteSheet');
var SVGFile = require('./filetypes/SVGFile');
@ -75,6 +76,11 @@ var Loader = new Class({
return ScriptFile.create(this, key, url, xhrSettings);
},
plugin: function (key, url, xhrSettings)
{
return PluginFile.create(this, key, url, xhrSettings);
},
xml: function (key, url, xhrSettings)
{
return XMLFile.create(this, key, url, xhrSettings);
@ -321,7 +327,7 @@ var Loader = new Class({
shutdown: function ()
{
// TODO
}
});

View file

@ -0,0 +1,73 @@
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var GetFastValue = require('../../utils/object/GetFastValue');
var PluginManager = require('../../plugins/PluginManager');
// Phaser.Loader.FileTypes.PluginFile
var PluginFile = new Class({
Extends: File,
initialize:
function PluginFile (key, url, path, xhrSettings)
{
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
var fileConfig = {
type: 'script',
extension: GetFastValue(key, 'extension', 'js'),
responseType: 'text',
key: fileKey,
url: GetFastValue(key, 'file', url),
path: path,
xhrSettings: GetFastValue(key, 'xhr', 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);
// Need to wait for onload?
window[this.key].register(PluginManager);
this.onComplete();
callback(this);
}
});
PluginFile.create = function (loader, key, url, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
loader.addFile(new PluginFile(key[i], url, loader.path, xhrSettings));
}
}
else
{
loader.addFile(new PluginFile(key, url, loader.path, xhrSettings));
}
// For method chaining
return loader;
};
module.exports = PluginFile;

View file

@ -28,6 +28,7 @@ var Systems = new Class({
this.anims;
this.cache;
this.plugins;
this.registry;
this.sound;
this.textures;
@ -47,13 +48,17 @@ var Systems = new Class({
{
this.game = game;
game.plugins.installGlobal(this, GlobalPlugins);
var pluginManager = game.plugins;
game.plugins.installLocal(this, CoreScenePlugins);
this.plugins = pluginManager;
game.plugins.installLocal(this, GetScenePlugins(this));
pluginManager.installGlobal(this, GlobalPlugins);
game.plugins.installLocal(this, GetPhysicsPlugins(this));
pluginManager.installLocal(this, CoreScenePlugins);
pluginManager.installLocal(this, GetScenePlugins(this));
pluginManager.installLocal(this, GetPhysicsPlugins(this));
this.events.emit('boot', this);
@ -67,7 +72,7 @@ var Systems = new Class({
plugin = [ plugin ];
}
this.game.plugins.installLocal(this, plugin);
this.plugins.installLocal(this, plugin);
},
step: function (time, delta)