Skip to content

Commit ff7f614

Browse files
committed
renamed to PhysicsEditorParser, added jsdocs
1 parent bcef469 commit ff7f614

3 files changed

Lines changed: 54 additions & 10 deletions

File tree

src/physics/matter-js/PhysicsEditorLoader.js renamed to src/physics/matter-js/PhysicsEditorParser.js

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,34 @@ var Bounds = require('./lib/geometry/Bounds');
1313
var Vector = require('./lib/geometry/Vector');
1414

1515

16-
var PhysicsEditorLoader = {
17-
18-
loadBody: function (x, y, w, h, config)
16+
/**
17+
* Use PhysicsEditorParser.parseBody() to build a Matter body object, based on a physics data file
18+
* created and exported with PhysicsEditor (https://www.codeandweb.com/physicseditor).
19+
*
20+
* @name Phaser.Physics.Matter.PhysicsEditorParser
21+
* @since 3.10.0
22+
*/
23+
var PhysicsEditorParser = {
24+
25+
/**
26+
* Parses a body element exported by PhysicsEditor.
27+
*
28+
* @method Phaser.Physics.Matter.PhysicsEditorParser#parseBody
29+
*
30+
* @param {number} x - x position
31+
* @param {number} y - y position
32+
* @param {number} w - width
33+
* @param {number} h - height
34+
* @param {object} config - body configuration and fixture (child body) definitions
35+
* @return {object} a matter body, consisting of several parts (child bodies)
36+
*/
37+
parseBody: function (x, y, w, h, config)
1938
{
2039
var fixtureConfigs = GetFastValue(config, 'fixtures', []);
2140
var fixtures = [];
2241
for (var fc = 0; fc < fixtureConfigs.length; fc++)
2342
{
24-
var fixtureParts = this.loadFixture(fixtureConfigs[fc]);
43+
var fixtureParts = this.parseFixture(fixtureConfigs[fc]);
2544
for(var i = 0; i < fixtureParts.length; i++)
2645
{
2746
fixtures.push(fixtureParts[i]);
@@ -42,7 +61,15 @@ var PhysicsEditorLoader = {
4261
},
4362

4463

45-
loadFixture: function (fixtureConfig)
64+
/**
65+
* Parses an element of the "fixtures" list exported by PhysicsEditor
66+
*
67+
* @method Phaser.Physics.Matter.PhysicsEditorParser#parseFixture
68+
*
69+
* @param {object} fixtureConfig - the fixture object to parse
70+
* @return {object[]} - a list of matter bodies
71+
*/
72+
parseFixture: function (fixtureConfig)
4673
{
4774
var matterConfig = Common.extend({}, false, fixtureConfig);
4875
delete matterConfig.circle;
@@ -58,13 +85,22 @@ var PhysicsEditorLoader = {
5885
}
5986
else if (fixtureConfig.vertices)
6087
{
61-
fixtures = this.loadVertices(fixtureConfig.vertices, matterConfig);
88+
fixtures = this.parseVertices(fixtureConfig.vertices, matterConfig);
6289
}
6390
return fixtures;
6491
},
6592

6693

67-
loadVertices: function (vertexSets, options)
94+
/**
95+
* Parses the "vertices" lists exported by PhysicsEditor
96+
*
97+
* @method Phaser.Physics.Matter.PhysicsEditorParser#parseVertices
98+
*
99+
* @param {object} vertexSets - the vertex lists to parse
100+
* @param {object} options - matter body options
101+
* @return {object[]} - a list of matter bodies
102+
*/
103+
parseVertices: function (vertexSets, options)
68104
{
69105
var i, j, k, v, z;
70106
var parts = [];
@@ -121,4 +157,4 @@ var PhysicsEditorLoader = {
121157
}
122158
};
123159

124-
module.exports = PhysicsEditorLoader;
160+
module.exports = PhysicsEditorParser;

src/physics/matter-js/components/Mass.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ var Mass = {
4949
return this;
5050
},
5151

52+
/**
53+
* The body's center of mass.
54+
*
55+
* @name Phaser.Physics.Matter.Components.Mass#centerOfMass
56+
* @since 3.10.0
57+
*
58+
* @return {Phaser.Math.Vector2} The center of mass.
59+
*/
5260
centerOfMass: {
5361

5462
get: function ()

src/physics/matter-js/components/SetBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
var Bodies = require('../lib/factory/Bodies');
88
var Body = require('../lib/body/Body');
99
var GetFastValue = require('../../../utils/object/GetFastValue');
10-
var PhysicsEditorLoader = require('../PhysicsEditorLoader');
10+
var PhysicsEditorParser = require('../PhysicsEditorParser');
1111

1212
/**
1313
* [description]
@@ -209,7 +209,7 @@ var SetBody = {
209209
break;
210210

211211
case 'fromPhysicsEditor':
212-
body = PhysicsEditorLoader.loadBody(bodyX, bodyY, bodyWidth, bodyHeight, config);
212+
body = PhysicsEditorParser.parseBody(bodyX, bodyY, bodyWidth, bodyHeight, config);
213213
break;
214214
}
215215

0 commit comments

Comments
 (0)