Skip to content

Commit 8ca79cd

Browse files
committed
Working on the plugin config setup
1 parent 1408a2d commit 8ca79cd

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

src/boot/Config.js

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
var Class = require('../utils/Class');
88
var CONST = require('../const');
9+
var GetFastValue = require('../utils/object/GetFastValue');
910
var GetValue = require('../utils/object/GetValue');
11+
var IsPlainObject = require('../utils/object/IsPlainObject');
1012
var MATH = require('../math/const');
1113
var NOOP = require('../utils/NOOP');
1214
var Plugins = require('../plugins');
@@ -443,12 +445,62 @@ var Config = new Class({
443445
*/
444446
this.loaderTimeout = GetValue(config, 'loader.timeout', 0);
445447

446-
// Scene Plugins
448+
// Plugins
447449

448450
/**
449-
* @const {any} Phaser.Boot.Config#defaultPlugins - [description]
451+
* @const {any} Phaser.Boot.Config#defaultPlugins - The plugins installed into every Scene (in addition to CoreScene and Global).
450452
*/
451-
this.defaultPlugins = GetValue(config, 'plugins', Plugins.DefaultScene);
453+
this.defaultPlugins = Plugins.DefaultScene;
454+
455+
/**
456+
* @const {any} Phaser.Boot.Config#installPlugins - [description]
457+
*/
458+
this.installPlugins = { global: [], scene: [], files: [] };
459+
460+
var plugins = GetValue(config, 'plugins', null);
461+
462+
/*
463+
* Allows `plugins` property to either be an array, in which case it just replaces
464+
* the default plugins like previously.
465+
*
466+
* plugins: {
467+
* install: [
468+
* ModPlayerPlugin,
469+
* WireFramePlugin
470+
* ],
471+
* filetypes: [
472+
* MODFile
473+
* OBJFile,
474+
* ],
475+
* default: [], OR
476+
* defaultMerge: {
477+
* 'ModPlayer': 'mod'
478+
* }
479+
* }
480+
*
481+
* If an object, it checks for an 'install' property,
482+
*/
483+
if (plugins)
484+
{
485+
// Old 3.7 array format?
486+
if (Array.isArray(plugins))
487+
{
488+
this.defaultPlugins = plugins;
489+
}
490+
else if (IsPlainObject(plugins))
491+
{
492+
this.installPlugins.global = GetFastValue(plugins, 'install', []);
493+
494+
if (Array.isArray(plugins.default))
495+
{
496+
this.defaultPlugins = plugins.default;
497+
}
498+
else if (Array.isArray(plugins.defaultMerge))
499+
{
500+
this.defaultPlugins = this.defaultPlugins.concat(plugins.defaultMerge);
501+
}
502+
}
503+
}
452504

453505
// Default / Missing Images
454506
var pngPrefix = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAg';

src/plugins/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* @namespace Phaser.Plugins
9+
*/
10+
11+
module.exports = {
12+
13+
PluginManager: require('./PluginManager')
14+
15+
};

0 commit comments

Comments
 (0)