2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2020-01-15 12:07:09 +00:00
|
|
|
* @copyright 2020 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-17 03:41:58 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Factory = require('./Factory');
|
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
|
|
|
var Merge = require('../../utils/object/Merge');
|
2018-05-15 11:51:50 +00:00
|
|
|
var PluginCache = require('../../plugins/PluginCache');
|
2019-01-18 13:41:43 +00:00
|
|
|
var SceneEvents = require('../../scene/events');
|
2018-01-17 03:41:58 +00:00
|
|
|
var World = require('./World');
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class ImpactPhysics
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Physics.Impact
|
2018-02-09 16:04:43 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - [description]
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
var ImpactPhysics = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function ImpactPhysics (scene)
|
|
|
|
{
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactPhysics#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
this.scene = scene;
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactPhysics#systems
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactPhysics#config
|
|
|
|
* @type {object}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
this.config = this.getConfig();
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactPhysics#world
|
|
|
|
* @type {Phaser.Physics.Impact.World}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
this.world;
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Impact.ImpactPhysics#add
|
|
|
|
* @type {Phaser.Physics.Impact.Factory}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
this.add;
|
2018-04-13 16:12:17 +00:00
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
scene.sys.events.once(SceneEvents.BOOT, this.boot, this);
|
|
|
|
scene.sys.events.on(SceneEvents.START, this.start, this);
|
2018-04-13 16:12:17 +00:00
|
|
|
},
|
|
|
|
|
2018-04-17 01:34:07 +00:00
|
|
|
/**
|
|
|
|
* This method is called automatically, only once, when the Scene is first created.
|
|
|
|
* Do not invoke it directly.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.ImpactPhysics#boot
|
|
|
|
* @private
|
|
|
|
* @since 3.5.1
|
|
|
|
*/
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
this.world = new World(this.scene, this.config);
|
|
|
|
this.add = new Factory(this.world);
|
2018-04-17 11:25:45 +00:00
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
this.systems.events.once(SceneEvents.DESTROY, this.destroy, this);
|
2018-04-17 01:34:07 +00:00
|
|
|
},
|
|
|
|
|
2018-04-13 16:12:17 +00:00
|
|
|
/**
|
|
|
|
* This method is called automatically by the Scene when it is starting up.
|
|
|
|
* It is responsible for creating local systems, properties and listening for Scene events.
|
|
|
|
* Do not invoke it directly.
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.ImpactPhysics#start
|
|
|
|
* @private
|
2018-04-15 11:44:47 +00:00
|
|
|
* @since 3.5.0
|
2018-04-13 16:12:17 +00:00
|
|
|
*/
|
|
|
|
start: function ()
|
|
|
|
{
|
2018-04-17 01:34:07 +00:00
|
|
|
if (!this.world)
|
|
|
|
{
|
|
|
|
this.world = new World(this.scene, this.config);
|
|
|
|
this.add = new Factory(this.world);
|
|
|
|
}
|
2018-04-13 16:12:17 +00:00
|
|
|
|
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
eventEmitter.on(SceneEvents.UPDATE, this.world.update, this.world);
|
|
|
|
eventEmitter.once(SceneEvents.SHUTDOWN, this.shutdown, this);
|
2018-01-17 03:41:58 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.ImpactPhysics#getConfig
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {object} [description]
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
getConfig: function ()
|
|
|
|
{
|
|
|
|
var gameConfig = this.systems.game.config.physics;
|
|
|
|
var sceneConfig = this.systems.settings.physics;
|
|
|
|
|
|
|
|
var config = Merge(
|
|
|
|
GetFastValue(sceneConfig, 'impact', {}),
|
|
|
|
GetFastValue(gameConfig, 'impact', {})
|
|
|
|
);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
},
|
|
|
|
|
2018-02-09 16:52:08 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.ImpactPhysics#pause
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-12 13:48:38 +00:00
|
|
|
* @return {Phaser.Physics.Impact.World} The Impact World object.
|
2018-02-09 16:52:08 +00:00
|
|
|
*/
|
|
|
|
pause: function ()
|
|
|
|
{
|
|
|
|
return this.world.pause();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.ImpactPhysics#resume
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-02-12 13:48:38 +00:00
|
|
|
* @return {Phaser.Physics.Impact.World} The Impact World object.
|
2018-02-09 16:52:08 +00:00
|
|
|
*/
|
|
|
|
resume: function ()
|
|
|
|
{
|
|
|
|
return this.world.resume();
|
|
|
|
},
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is shutting down.
|
|
|
|
* We need to kill and reset all internal properties as well as stop listening to Scene events.
|
2018-02-09 16:04:43 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.ImpactPhysics#shutdown
|
2018-04-13 16:12:17 +00:00
|
|
|
* @private
|
2018-02-09 16:04:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
shutdown: function ()
|
|
|
|
{
|
2018-04-13 16:12:17 +00:00
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
eventEmitter.off(SceneEvents.UPDATE, this.world.update, this.world);
|
|
|
|
eventEmitter.off(SceneEvents.SHUTDOWN, this.shutdown, this);
|
2018-04-17 01:34:07 +00:00
|
|
|
|
|
|
|
this.add.destroy();
|
|
|
|
this.world.destroy();
|
|
|
|
|
|
|
|
this.add = null;
|
|
|
|
this.world = null;
|
2018-01-17 03:41:58 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 16:04:43 +00:00
|
|
|
/**
|
2018-04-13 16:12:17 +00:00
|
|
|
* The Scene that owns this plugin is being destroyed.
|
|
|
|
* We need to shutdown and then kill off all external references.
|
2018-02-09 16:04:43 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Impact.ImpactPhysics#destroy
|
2018-04-13 16:12:17 +00:00
|
|
|
* @private
|
2018-02-09 16:04:43 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 03:41:58 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
2018-04-13 16:12:17 +00:00
|
|
|
this.shutdown();
|
|
|
|
|
2019-01-18 13:41:43 +00:00
|
|
|
this.scene.sys.events.off(SceneEvents.START, this.start, this);
|
2018-04-13 16:12:17 +00:00
|
|
|
|
|
|
|
this.scene = null;
|
|
|
|
this.systems = null;
|
2018-01-17 03:41:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-05-15 11:51:50 +00:00
|
|
|
PluginCache.register('ImpactPhysics', ImpactPhysics, 'impactPhysics');
|
2018-01-17 03:41:58 +00:00
|
|
|
|
|
|
|
module.exports = ImpactPhysics;
|