mirror of
https://github.com/photonstorm/phaser
synced 2024-11-28 07:31:11 +00:00
Moved Matter over to use the plugin system.
This commit is contained in:
parent
bae63901d7
commit
f41d016c9f
5 changed files with 161 additions and 84 deletions
|
@ -4,7 +4,7 @@ module.exports = {
|
|||
|
||||
Arcade: require('./arcade'),
|
||||
Impact: require('./impact'),
|
||||
Matter: require('./matter-js/CustomMain'),
|
||||
Matter: require('./matter-js'),
|
||||
PolyDecomp: require('./poly-decomp')
|
||||
|
||||
};
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var Factory = require('./Factory');
|
||||
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 Plugin = require('./lib/core/Plugin');
|
||||
var World = require('./World');
|
||||
|
||||
var Matter = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
// Referenced from the Scene PhysicsManager as `system`
|
||||
|
||||
function Matter (physicsManager, config)
|
||||
{
|
||||
this.config = config;
|
||||
|
||||
physicsManager.world = new World(physicsManager.scene, config);
|
||||
|
||||
physicsManager.add = new Factory(physicsManager.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);
|
||||
}
|
||||
},
|
||||
|
||||
enableAttractorPlugin: function ()
|
||||
{
|
||||
Plugin.register(MatterAttractors);
|
||||
Plugin.use(MatterLib, MatterAttractors);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
enableWrapPlugin: function ()
|
||||
{
|
||||
Plugin.register(MatterWrap);
|
||||
Plugin.use(MatterLib, MatterWrap);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
module.exports = Matter;
|
121
src/physics/matter-js/MatterPhysics.js
Normal file
121
src/physics/matter-js/MatterPhysics.js
Normal file
|
@ -0,0 +1,121 @@
|
|||
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');
|
||||
|
||||
// Phaser.Physics.Matter.MatterPhysics
|
||||
|
||||
var MatterPhysics = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
// Referenced from the Scene PhysicsManager as `system`
|
||||
|
||||
function MatterPhysics (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
this.mapping = 'matter';
|
||||
|
||||
this.systems.events.on('boot', this.boot, this);
|
||||
|
||||
this.config = this.getConfig();
|
||||
|
||||
this.world;
|
||||
|
||||
this.add;
|
||||
},
|
||||
|
||||
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;
|
||||
},
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
this.systems.inject(this);
|
||||
|
||||
this.systems.events.on('update', this.update, this);
|
||||
this.systems.events.on('postupdate', this.postUpdate, this);
|
||||
this.systems.events.on('shutdown', this.shutdown, this);
|
||||
this.systems.events.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
enableAttractorPlugin: function ()
|
||||
{
|
||||
Plugin.register(MatterAttractors);
|
||||
Plugin.use(MatterLib, MatterAttractors);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
enableWrapPlugin: function ()
|
||||
{
|
||||
Plugin.register(MatterWrap);
|
||||
Plugin.use(MatterLib, MatterWrap);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
update: function (time, delta)
|
||||
{
|
||||
this.world.update(time, delta);
|
||||
},
|
||||
|
||||
postUpdate: function (time, delta)
|
||||
{
|
||||
this.world.postUpdate(time, delta);
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
this.world.shutdown();
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.world.destroy();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PluginManager.register('matterPhysics', MatterPhysics);
|
||||
|
||||
module.exports = MatterPhysics;
|
|
@ -307,8 +307,11 @@ var World = new Class({
|
|||
|
||||
postUpdate: function ()
|
||||
{
|
||||
if (this.drawDebug)
|
||||
if (!this.drawDebug)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var graphics = this.debugGraphic;
|
||||
var bodies = Composite.allBodies(this.localWorld);
|
||||
|
||||
|
@ -337,7 +340,6 @@ var World = new Class({
|
|||
|
||||
graphics.strokePath();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
fromPath: function (path, points)
|
||||
|
@ -362,7 +364,6 @@ var World = new Class({
|
|||
|
||||
destroy: function ()
|
||||
{
|
||||
// TODO
|
||||
this.shutdown();
|
||||
}
|
||||
|
||||
|
|
12
src/physics/matter-js/index.js
Normal file
12
src/physics/matter-js/index.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Phaser.Physics.Matter
|
||||
|
||||
module.exports = {
|
||||
|
||||
Factory: require('./Factory'),
|
||||
Image: require('./MatterImage'),
|
||||
Matter: require('./CustomMain'),
|
||||
MatterPhysics: require('./MatterPhysics'),
|
||||
Sprite: require('./MatterSprite'),
|
||||
World: require('./World')
|
||||
|
||||
};
|
Loading…
Reference in a new issue