2018-01-17 15:22:16 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var Factory = require('./Factory');
|
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
|
|
|
var GetValue = require('../../utils/object/GetValue');
|
|
|
|
var MatterAttractors = require('./lib/plugins/MatterAttractors');
|
|
|
|
var MatterLib = require('./lib/core/Matter');
|
|
|
|
var MatterWrap = require('./lib/plugins/MatterWrap');
|
|
|
|
var Merge = require('../../utils/object/Merge');
|
|
|
|
var Plugin = require('./lib/core/Plugin');
|
|
|
|
var PluginManager = require('../../plugins/PluginManager');
|
|
|
|
var World = require('./World');
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class MatterPhysics
|
|
|
|
* @memberOf Phaser.Physics.Matter
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Scene} scene - [description]
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
var MatterPhysics = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function MatterPhysics (scene)
|
|
|
|
{
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.MatterPhysics#scene
|
|
|
|
* @type {Phaser.Scene}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
this.scene = scene;
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.MatterPhysics#systems
|
|
|
|
* @type {Phaser.Scenes.Systems}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
this.systems = scene.sys;
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
if (!scene.sys.settings.isBooted)
|
|
|
|
{
|
|
|
|
scene.sys.events.once('boot', this.boot, this);
|
|
|
|
}
|
2018-01-17 15:22:16 +00:00
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.MatterPhysics#config
|
|
|
|
* @type {object}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
this.config = this.getConfig();
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.MatterPhysics#world
|
|
|
|
* @type {Phaser.Physics.Matter.World}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
this.world;
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Matter.MatterPhysics#add
|
|
|
|
* @type {Phaser.Physics.Matter.Factory}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
this.add;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#getConfig
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {object} [description]
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
getConfig: function ()
|
|
|
|
{
|
|
|
|
var gameConfig = this.systems.game.config.physics;
|
|
|
|
var sceneConfig = this.systems.settings.physics;
|
|
|
|
|
|
|
|
var config = Merge(
|
|
|
|
GetFastValue(sceneConfig, 'matter', {}),
|
|
|
|
GetFastValue(gameConfig, 'matter', {})
|
|
|
|
);
|
|
|
|
|
|
|
|
return config;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#boot
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
var config = this.config;
|
|
|
|
|
|
|
|
this.world = new World(this.scene, config);
|
|
|
|
this.add = new Factory(this.world);
|
|
|
|
|
|
|
|
// Matter plugins
|
|
|
|
|
|
|
|
if (GetValue(config, 'plugins.attractors', false))
|
|
|
|
{
|
|
|
|
Plugin.register(MatterAttractors);
|
|
|
|
Plugin.use(MatterLib, MatterAttractors);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetValue(config, 'plugins.wrap', false))
|
|
|
|
{
|
|
|
|
Plugin.register(MatterWrap);
|
|
|
|
Plugin.use(MatterLib, MatterWrap);
|
|
|
|
}
|
|
|
|
|
2018-01-18 14:00:31 +00:00
|
|
|
var eventEmitter = this.systems.events;
|
|
|
|
|
|
|
|
eventEmitter.on('update', this.world.update, this.world);
|
|
|
|
eventEmitter.on('postupdate', this.world.postUpdate, this.world);
|
|
|
|
eventEmitter.on('shutdown', this.shutdown, this);
|
|
|
|
eventEmitter.on('destroy', this.destroy, this);
|
2018-01-17 15:22:16 +00:00
|
|
|
},
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#enableAttractorPlugin
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
enableAttractorPlugin: function ()
|
|
|
|
{
|
|
|
|
Plugin.register(MatterAttractors);
|
|
|
|
Plugin.use(MatterLib, MatterAttractors);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#enableWrapPlugin
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
enableWrapPlugin: function ()
|
|
|
|
{
|
|
|
|
Plugin.register(MatterWrap);
|
|
|
|
Plugin.use(MatterLib, MatterWrap);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#pause
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Matter.World} The Matter World object.
|
|
|
|
*/
|
|
|
|
pause: function ()
|
|
|
|
{
|
|
|
|
return this.world.pause();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#resume
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Matter.World} The Matter World object.
|
|
|
|
*/
|
|
|
|
resume: function ()
|
|
|
|
{
|
|
|
|
return this.world.resume();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#shutdown
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
shutdown: function ()
|
|
|
|
{
|
|
|
|
this.world.shutdown();
|
|
|
|
},
|
|
|
|
|
2018-02-12 13:48:38 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Matter.MatterPhysics#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-17 15:22:16 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.world.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-01-18 05:18:09 +00:00
|
|
|
PluginManager.register('MatterPhysics', MatterPhysics, 'matterPhysics');
|
2018-01-17 15:22:16 +00:00
|
|
|
|
|
|
|
module.exports = MatterPhysics;
|