The PluginManager.installScenePlugin method has a new optional boolean parameter fromLoader which controls if the plugin is coming in from the result of a Loader operation or not. If it is, it no longer throws a console warning if the plugin already exists. This fixes an issue where if you return to a Scene that loads a Scene Plugin it would throw a warning and then not install the plugin to the Scene.

This commit is contained in:
Richard Davey 2019-02-28 12:24:41 +00:00
parent c15734f1bc
commit c85648e06a
3 changed files with 16 additions and 8 deletions

View file

@ -13,6 +13,7 @@
* The MouseManager and TouchManager now use separate handlers for the Window level input events, which check to see if the canvas is the target or not, and redirect processing accordingly.
* `AnimationManager.generateFrameNumbers` can now accept a start number greater than the end number, and will generate them in reverse (thanks @cruzdanilo)
* The return from the `ScenePlugin.add` method has changed. Previously, it would return the ScenePlugin, but now it returns a reference to the Scene that was added to the Scene Manager, keeping it in-line with all other `add` methods in the API. Fix #4359 (thanks @BigZaphod)
* The `PluginManager.installScenePlugin` method has a new optional boolean parameter `fromLoader` which controls if the plugin is coming in from the result of a Loader operation or not. If it is, it no longer throws a console warning if the plugin already exists. This fixes an issue where if you return to a Scene that loads a Scene Plugin it would throw a warning and then not install the plugin to the Scene.
### Bug Fixes

View file

@ -108,7 +108,7 @@ var ScenePluginFile = new Class({
if (this.state === CONST.FILE_POPULATED)
{
pluginManager.installScenePlugin(systemKey, this.data, sceneKey, this.loader.scene);
pluginManager.installScenePlugin(systemKey, this.data, sceneKey, this.loader.scene, true);
}
else
{
@ -123,7 +123,7 @@ var ScenePluginFile = new Class({
document.head.appendChild(this.data);
pluginManager.installScenePlugin(systemKey, window[this.key], sceneKey, this.loader.scene);
pluginManager.installScenePlugin(systemKey, window[this.key], sceneKey, this.loader.scene, true);
}
this.onProcessComplete();

View file

@ -336,25 +336,32 @@ var PluginManager = new Class({
* @param {function} plugin - The plugin code. This should be the non-instantiated version.
* @param {string} [mapping] - If this plugin is injected into the Phaser.Scene class, this is the property key to use.
* @param {Phaser.Scene} [addToScene] - Optionally automatically add this plugin to the given Scene.
* @param {boolean} [fromLoader=false] - Is this being called by the Loader?
*/
installScenePlugin: function (key, plugin, mapping, addToScene)
installScenePlugin: function (key, plugin, mapping, addToScene, fromLoader)
{
if (fromLoader === undefined) { fromLoader = false; }
if (typeof plugin !== 'function')
{
console.warn('Invalid Scene Plugin: ' + key);
return;
}
if (PluginCache.hasCore(key))
if (!PluginCache.hasCore(key))
{
// Plugin is freshly loaded
PluginCache.register(key, plugin, mapping, true);
this.scenePlugins.push(key);
}
else if (!fromLoader && PluginCache.hasCore(key))
{
// Plugin wasn't from the loader but already exists
console.warn('Scene Plugin key in use: ' + key);
return;
}
PluginCache.register(key, plugin, mapping, true);
this.scenePlugins.push(key);
if (addToScene)
{
var instance = new plugin(addToScene, this);