@@ -13,15 +13,34 @@ var Bounds = require('./lib/geometry/Bounds');
1313var 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 ;
0 commit comments