mirror of
https://github.com/photonstorm/phaser
synced 2025-02-26 04:17:08 +00:00
Tidied up the formatting and jsdocs for Physics Editor parser
This commit is contained in:
parent
9a53daa068
commit
c7c104bc2b
2 changed files with 32 additions and 20 deletions
|
@ -6,12 +6,11 @@
|
||||||
|
|
||||||
var Bodies = require('./lib/factory/Bodies');
|
var Bodies = require('./lib/factory/Bodies');
|
||||||
var Body = require('./lib/body/Body');
|
var Body = require('./lib/body/Body');
|
||||||
var GetFastValue = require('../../utils/object/GetFastValue');
|
|
||||||
var Common = require('./lib/core/Common');
|
|
||||||
var Vertices = require('./lib/geometry/Vertices');
|
|
||||||
var Bounds = require('./lib/geometry/Bounds');
|
var Bounds = require('./lib/geometry/Bounds');
|
||||||
|
var Common = require('./lib/core/Common');
|
||||||
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||||
var Vector = require('./lib/geometry/Vector');
|
var Vector = require('./lib/geometry/Vector');
|
||||||
|
var Vertices = require('./lib/geometry/Vertices');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use PhysicsEditorParser.parseBody() to build a Matter body object, based on a physics data file
|
* Use PhysicsEditorParser.parseBody() to build a Matter body object, based on a physics data file
|
||||||
|
@ -25,33 +24,39 @@ var PhysicsEditorParser = {
|
||||||
/**
|
/**
|
||||||
* Parses a body element exported by PhysicsEditor.
|
* Parses a body element exported by PhysicsEditor.
|
||||||
*
|
*
|
||||||
* @method Phaser.Physics.Matter.PhysicsEditorParser#parseBody
|
* @function Phaser.Physics.Matter.PhysicsEditorParser.parseBody
|
||||||
|
* @since 3.10.0
|
||||||
*
|
*
|
||||||
* @param {number} x - x position
|
* @param {number} x - x position.
|
||||||
* @param {number} y - y position
|
* @param {number} y - y position.
|
||||||
* @param {number} w - width
|
* @param {number} w - width.
|
||||||
* @param {number} h - height
|
* @param {number} h - height.
|
||||||
* @param {object} config - body configuration and fixture (child body) definitions
|
* @param {object} config - body configuration and fixture (child body) definitions.
|
||||||
* @return {object} a matter body, consisting of several parts (child bodies)
|
*
|
||||||
|
* @return {object} A matter body, consisting of several parts (child bodies)
|
||||||
*/
|
*/
|
||||||
parseBody: function (x, y, w, h, config)
|
parseBody: function (x, y, w, h, config)
|
||||||
{
|
{
|
||||||
var fixtureConfigs = GetFastValue(config, 'fixtures', []);
|
var fixtureConfigs = GetFastValue(config, 'fixtures', []);
|
||||||
var fixtures = [];
|
var fixtures = [];
|
||||||
|
|
||||||
for (var fc = 0; fc < fixtureConfigs.length; fc++)
|
for (var fc = 0; fc < fixtureConfigs.length; fc++)
|
||||||
{
|
{
|
||||||
var fixtureParts = this.parseFixture(fixtureConfigs[fc]);
|
var fixtureParts = this.parseFixture(fixtureConfigs[fc]);
|
||||||
for(var i = 0; i < fixtureParts.length; i++)
|
|
||||||
|
for (var i = 0; i < fixtureParts.length; i++)
|
||||||
{
|
{
|
||||||
fixtures.push(fixtureParts[i]);
|
fixtures.push(fixtureParts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var matterConfig = Common.extend({}, false, config);
|
var matterConfig = Common.extend({}, false, config);
|
||||||
|
|
||||||
delete matterConfig.fixtures;
|
delete matterConfig.fixtures;
|
||||||
delete matterConfig.type;
|
delete matterConfig.type;
|
||||||
|
|
||||||
var body = Body.create(matterConfig);
|
var body = Body.create(matterConfig);
|
||||||
|
|
||||||
Body.setParts(body, fixtures);
|
Body.setParts(body, fixtures);
|
||||||
body.render.sprite.xOffset = body.position.x / w;
|
body.render.sprite.xOffset = body.position.x / w;
|
||||||
body.render.sprite.yOffset = body.position.y / h;
|
body.render.sprite.yOffset = body.position.y / h;
|
||||||
|
@ -64,18 +69,22 @@ var PhysicsEditorParser = {
|
||||||
/**
|
/**
|
||||||
* Parses an element of the "fixtures" list exported by PhysicsEditor
|
* Parses an element of the "fixtures" list exported by PhysicsEditor
|
||||||
*
|
*
|
||||||
* @method Phaser.Physics.Matter.PhysicsEditorParser#parseFixture
|
* @function Phaser.Physics.Matter.PhysicsEditorParser.parseFixture
|
||||||
|
* @since 3.10.0
|
||||||
*
|
*
|
||||||
* @param {object} fixtureConfig - the fixture object to parse
|
* @param {object} fixtureConfig - the fixture object to parse
|
||||||
* @return {object[]} - a list of matter bodies
|
*
|
||||||
|
* @return {object[]} - A list of matter bodies
|
||||||
*/
|
*/
|
||||||
parseFixture: function (fixtureConfig)
|
parseFixture: function (fixtureConfig)
|
||||||
{
|
{
|
||||||
var matterConfig = Common.extend({}, false, fixtureConfig);
|
var matterConfig = Common.extend({}, false, fixtureConfig);
|
||||||
|
|
||||||
delete matterConfig.circle;
|
delete matterConfig.circle;
|
||||||
delete matterConfig.vertices;
|
delete matterConfig.vertices;
|
||||||
|
|
||||||
var fixtures;
|
var fixtures;
|
||||||
|
|
||||||
if (fixtureConfig.circle)
|
if (fixtureConfig.circle)
|
||||||
{
|
{
|
||||||
var x = GetFastValue(fixtureConfig.circle, 'x');
|
var x = GetFastValue(fixtureConfig.circle, 'x');
|
||||||
|
@ -87,18 +96,20 @@ var PhysicsEditorParser = {
|
||||||
{
|
{
|
||||||
fixtures = this.parseVertices(fixtureConfig.vertices, matterConfig);
|
fixtures = this.parseVertices(fixtureConfig.vertices, matterConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fixtures;
|
return fixtures;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the "vertices" lists exported by PhysicsEditor
|
* Parses the "vertices" lists exported by PhysicsEditor.
|
||||||
*
|
*
|
||||||
* @method Phaser.Physics.Matter.PhysicsEditorParser#parseVertices
|
* @function Phaser.Physics.Matter.PhysicsEditorParser.parseVertices
|
||||||
|
* @since 3.10.0
|
||||||
*
|
*
|
||||||
* @param {object} vertexSets - the vertex lists to parse
|
* @param {object} vertexSets - The vertex lists to parse.
|
||||||
* @param {object} options - matter body options
|
* @param {object} options - Matter body options.
|
||||||
* @return {object[]} - a list of matter bodies
|
*
|
||||||
|
* @return {object[]} - A list of matter bodies.
|
||||||
*/
|
*/
|
||||||
parseVertices: function (vertexSets, options)
|
parseVertices: function (vertexSets, options)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,6 +53,7 @@ var Mass = {
|
||||||
* The body's center of mass.
|
* The body's center of mass.
|
||||||
*
|
*
|
||||||
* @name Phaser.Physics.Matter.Components.Mass#centerOfMass
|
* @name Phaser.Physics.Matter.Components.Mass#centerOfMass
|
||||||
|
* @readOnly
|
||||||
* @since 3.10.0
|
* @since 3.10.0
|
||||||
*
|
*
|
||||||
* @return {Phaser.Math.Vector2} The center of mass.
|
* @return {Phaser.Math.Vector2} The center of mass.
|
||||||
|
|
Loading…
Add table
Reference in a new issue