Skip to content

Commit

Permalink
Moved FB plugin behind build flag
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Aug 23, 2018
1 parent 8af2347 commit 7765496
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 51 deletions.
107 changes: 67 additions & 40 deletions src/boot/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,33 @@ var CacheManager = require('../cache/CacheManager');
var CanvasPool = require('../display/canvas/CanvasPool');
var Class = require('../utils/Class');
var Config = require('./Config');
var CreateDOMContainer = require('./CreateDOMContainer');
var CreateRenderer = require('./CreateRenderer');
var DataManager = require('../data/DataManager');
var DebugHeader = require('./DebugHeader');
var Device = require('../device');
var DOMContentLoaded = require('../dom/DOMContentLoaded');
var EventEmitter = require('eventemitter3');
var FacebookInstantGamesPlugin = require('../fbinstant/FacebookInstantGamesPlugin');
var InputManager = require('../input/InputManager');
var PluginCache = require('../plugins/PluginCache');
var PluginManager = require('../plugins/PluginManager');
var ScaleManager = require('./ScaleManager');
var SceneManager = require('../scene/SceneManager');
var SoundManagerCreator = require('../sound/SoundManagerCreator');
var TextureManager = require('../textures/TextureManager');
var TimeStep = require('./TimeStep');
var VisibilityHandler = require('./VisibilityHandler');


if (typeof EXPERIMENTAL)
{
var CreateDOMContainer = require('./CreateDOMContainer');
var ScaleManager = require('./ScaleManager');
}

if (typeof PLUGIN_FBINSTANT)
{
var FacebookInstantGamesPlugin = require('../fbinstant/FacebookInstantGamesPlugin');
}

/**
* @classdesc
* The Phaser.Game instance is the main controller for the entire Phaser game. It is responsible
Expand Down Expand Up @@ -72,19 +81,22 @@ var Game = new Class({
*/
this.renderer = null;

/**
* A reference to an HTML Div Element used as a DOM Element Container.
*
* Only set if `createDOMContainer` is `true` in the game config (by default it is `false`) and
* if you provide a parent element to insert the Phaser Game inside.
*
* See the DOM Element Game Object for more details.
*
* @name Phaser.Game#domContainer
* @type {HTMLDivElement}
* @since 3.12.0
*/
this.domContainer = null;
if (typeof EXPERIMENTAL)
{
/**
* A reference to an HTML Div Element used as a DOM Element Container.
*
* Only set if `createDOMContainer` is `true` in the game config (by default it is `false`) and
* if you provide a parent element to insert the Phaser Game inside.
*
* See the DOM Element Game Object for more details.
*
* @name Phaser.Game#domContainer
* @type {HTMLDivElement}
* @since 3.12.0
*/
this.domContainer = null;
}

/**
* A reference to the HTML Canvas Element that Phaser uses to render the game.
Expand Down Expand Up @@ -215,16 +227,19 @@ var Game = new Class({
*/
this.device = Device;

/**
* An instance of the Scale Manager.
*
* The Scale Manager is a global system responsible for handling game scaling events.
*
* @name Phaser.Game#scaleManager
* @type {Phaser.Boot.ScaleManager}
* @since 3.12.0
*/
this.scaleManager = new ScaleManager(this, this.config);
if (typeof EXPERIMENTAL)
{
/**
* An instance of the Scale Manager.
*
* The Scale Manager is a global system responsible for handling game scaling events.
*
* @name Phaser.Game#scaleManager
* @type {Phaser.Boot.ScaleManager}
* @since 3.12.0
*/
this.scaleManager = new ScaleManager(this, this.config);
}

/**
* An instance of the base Sound Manager.
Expand Down Expand Up @@ -261,14 +276,17 @@ var Game = new Class({
*/
this.plugins = new PluginManager(this, this.config);

/**
* An instance of the Facebook Instant Games Manager.
*
* @name Phaser.Game#facebook
* @type {any}
* @since 3.12.0
*/
this.facebook = new FacebookInstantGamesPlugin(this);
if (typeof PLUGIN_FBINSTANT)
{
/**
* An instance of the Facebook Instant Games Manager.
*
* @name Phaser.Game#facebook
* @type {any}
* @since 3.12.0
*/
this.facebook = new FacebookInstantGamesPlugin(this);
}

/**
* Is this Game pending destruction at the start of the next frame?
Expand Down Expand Up @@ -360,7 +378,10 @@ var Game = new Class({

CreateRenderer(this);

CreateDOMContainer(this);
if (typeof EXPERIMENTAL)
{
CreateDOMContainer(this);
}

DebugHeader(this);

Expand Down Expand Up @@ -686,10 +707,13 @@ var Game = new Class({
this.config.width = width;
this.config.height = height;

if (this.domContainer)
if (typeof EXPERIMENTAL)
{
this.domContainer.style.width = width + 'px';
this.domContainer.style.height = height + 'px';
if (this.domContainer)
{
this.domContainer.style.width = width + 'px';
this.domContainer.style.height = height + 'px';
}
}

this.renderer.resize(width, height);
Expand Down Expand Up @@ -754,9 +778,12 @@ var Game = new Class({
}
}

if (this.domContainer)
if (typeof EXPERIMENTAL)
{
this.domContainer.parentNode.removeChild(this.domContainer);
if (this.domContainer)
{
this.domContainer.parentNode.removeChild(this.domContainer);
}
}

this.loop.destroy();
Expand Down
6 changes: 5 additions & 1 deletion src/phaser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var Phaser = {
Display: require('./display'),
DOM: require('./dom'),
Events: require('./events'),
FBInstant: require('./fbinstant/FacebookInstantGamesPlugin'),
Game: require('./boot/Game'),
GameObjects: require('./gameobjects'),
Geom: require('./geom'),
Expand Down Expand Up @@ -58,6 +57,11 @@ if (typeof PLUGIN_CAMERA3D)
Phaser.GameObjects.Creators.Sprite3D = require('../plugins/camera3d/src/sprite3d/Sprite3DCreator');
}

if (typeof PLUGIN_FBINSTANT)
{
Phaser.FBInstant = require('../plugins/fbinstant/src/FacebookInstantGamesPlugin');
}

// Merge in the consts

Phaser = Extend(false, Phaser, CONST);
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/DefaultPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var DefaultPlugins = {
'game',
'anims',
'cache',
'facebook',
'plugins',
'registry',
'sound',
Expand Down Expand Up @@ -91,4 +90,9 @@ if (typeof PLUGIN_CAMERA3D)
DefaultPlugins.DefaultScene.push('CameraManager3D');
}

if (typeof PLUGIN_FBINSTANT)
{
DefaultPlugins.Global.push('facebook');
}

module.exports = DefaultPlugins;
6 changes: 5 additions & 1 deletion src/scene/InjectionMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var InjectionMap = {
registry: 'registry',
sound: 'sound',
textures: 'textures',
facebook: 'facebook',

events: 'events',
cameras: 'cameras',
Expand All @@ -51,4 +50,9 @@ if (typeof PLUGIN_CAMERA3D)
InjectionMap.cameras3d = 'cameras3d';
}

if (typeof PLUGIN_FBINSTANT)
{
InjectionMap.facebook = 'facebook';
}

module.exports = InjectionMap;
19 changes: 11 additions & 8 deletions src/scene/Systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ var Systems = new Class({
*/
this.game;

/**
* [description]
*
* @name Phaser.Scenes.Systems#facebook
* @type {any}
* @since 3.12.0
*/
this.facebook;
if (typeof PLUGIN_FBINSTANT)
{
/**
* [description]
*
* @name Phaser.Scenes.Systems#facebook
* @type {any}
* @since 3.12.0
*/
this.facebook;
}

/**
* [description]
Expand Down

0 comments on commit 7765496

Please sign in to comment.