Skip to content

Commit 4c94120

Browse files
committed
Add option to prefix shape name and optimize JSON output
1 parent 61edd1b commit 4c94120

3 files changed

Lines changed: 80 additions & 88 deletions

File tree

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<exporter>
22
<name>phaser-json</name>
33
<displayName>Phaser (JSON)</displayName>
4-
<description>Exporter for Phaser, JSON</description>
4+
<description>Exporter for Phaser, JSON</description>
55
<version>1.0</version>
66
<yAxisDirection>down</yAxisDirection>
77
<physicsEngine>box2d</physicsEngine>
@@ -11,63 +11,73 @@
1111
<enabled>no</enabled>
1212
</anchorPoint>
1313
<origin>
14-
<type>fixed</type>
15-
<relX>0.0</relX>
16-
<relY>1.0</relY>
17-
</origin>
18-
<supportsCircles>yes</supportsCircles>
14+
<type>fixed</type>
15+
<relX>0.0</relX>
16+
<relY>1.0</relY>
17+
</origin>
18+
<supportsCircles>yes</supportsCircles>
19+
<global>
20+
<parameter>
21+
<name>name_prefix</name>
22+
<displayName>Name prefix</displayName>
23+
<shortDescription>Prepend sprite name</shortDescription>
24+
<description>Prepend the sprite name with a string, mimicking the option 'prepend folder name' in TexturePacker.</description>
25+
<type><code>string</code></type>
26+
<default></default>
27+
</parameter>
28+
</global>
1929
<body>
2030
</body>
2131
<fixture>
22-
<parameter>
23-
<name>fixtureKey</name>
24-
<description>Give this fixture a unique KEY so you can retrieve it later in phaser</description>
25-
<displayName>Fixture's Key</displayName>
26-
<type>string</type>
27-
<default></default>
28-
</parameter>
32+
<parameter>
33+
<name>fixtureKey</name>
34+
<description>Give this fixture a unique KEY so you can retrieve it later in Phaser.</description>
35+
<displayName>Fixture's Key</displayName>
36+
<type>string</type>
37+
<default></default>
38+
</parameter>
2939

30-
<parameter>
31-
<name>isSensor</name>
32-
<displayName>Is Sensor</displayName>
33-
<description>If set the physial </description>
34-
<type>bool</type>
35-
<default>false</default>
36-
</parameter>
40+
<parameter>
41+
<name>isSensor</name>
42+
<displayName>Is Sensor</displayName>
43+
<description>If set the physical</description>
44+
<type>bool</type>
45+
<default>false</default>
46+
</parameter>
3747

38-
<parameter>
39-
<name>filter_groupIndex</name>
40-
<displayName>Group</displayName>
41-
<description>Collision group.</description>
42-
<shortDescription></shortDescription>
43-
<type>int</type>
44-
<default>0</default>
45-
</parameter>
48+
<parameter>
49+
<name>filter_groupIndex</name>
50+
<displayName>Group</displayName>
51+
<description>Collision group</description>
52+
<shortDescription></shortDescription>
53+
<type>int</type>
54+
<default>0</default>
55+
</parameter>
4656

47-
<parameter>
48-
<name>filter_bitfield</name>
49-
<type>bitfield</type>
50-
<size>16</size>
51-
</parameter>
57+
<parameter>
58+
<name>filter_bitfield</name>
59+
<type>bitfield</type>
60+
<size>16</size>
61+
</parameter>
5262

53-
<parameter>
54-
<name>filter_categoryBits</name>
55-
<displayName>Cat.</displayName>
56-
<description>Collision category</description>
57-
<shortDescription>Collision category</shortDescription>
58-
<type>uint16</type>
59-
<default>1</default>
60-
<bitfield>yes</bitfield>
61-
</parameter>
62-
<parameter>
63-
<name>filter_maskBits</name>
64-
<displayName>Mask</displayName>
65-
<description>Collision mask</description>
66-
<shortDescription>Collision mask</shortDescription>
67-
<type>uint16</type>
68-
<default>65535</default>
69-
<bitfield>yes</bitfield>
70-
</parameter>
71-
</fixture>
63+
<parameter>
64+
<name>filter_categoryBits</name>
65+
<displayName>Cat.</displayName>
66+
<description>Collision category</description>
67+
<shortDescription>Collision category</shortDescription>
68+
<type>uint16</type>
69+
<default>1</default>
70+
<bitfield>yes</bitfield>
71+
</parameter>
72+
<parameter>
73+
<name>filter_maskBits</name>
74+
<displayName>Mask</displayName>
75+
<description>Collision mask</description>
76+
<shortDescription>Collision mask</shortDescription>
77+
<type>uint16</type>
78+
<default>65535</default>
79+
<bitfield>yes</bitfield>
80+
</parameter>
81+
</fixture>
7282
</exporter>
7383

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,15 @@
1-
{ {% for body in bodies %}
2-
{% if not forloop.first %}, {% endif %}
3-
"{{body.name}}": [
4-
{% for fixture in body.fixtures %}{% if not forloop.first %} ,{% endif %}
5-
{
6-
{% if fixture.fixtureKey %}
7-
"fixtureKey": "{{fixture.fixtureKey}}",
8-
{% endif %}
9-
"isSensor": {{fixture.isSensor}},
10-
"filter": {
11-
"group": {{fixture.filter_groupIndex}},
12-
"categoryBits": {{fixture.filter_categoryBits}},
13-
"maskBits": {{fixture.filter_maskBits}}
14-
},
15-
16-
{% if fixture.isCircle %}
17-
"circle": {
18-
"radius": {{fixture.radius|floatformat:3}},
19-
"position": [
20-
{{fixture.center.x|floatformat:3}},
21-
{{fixture.center.y|floatformat:3}}
22-
]
23-
}
24-
{% else %}
25-
"polygons":[
26-
{% for polygon in fixture.polygons %}{% if not forloop.first %} ,{% endif %}
27-
[ {% for point in polygon %} {% if not forloop.first %}, {% endif %} {{point.x}}, {{point.y}} {% endfor %} ]
28-
{% endfor %}
29-
]
30-
{% endif %}
31-
}
32-
{% endfor %}
33-
]
34-
{% endfor %}
35-
}
1+
{{% for body in bodies %}{% if not forloop.first %},{% endif %}
2+
"{% if global.name_prefix %}{{global.name_prefix}}/{% endif %}{{body.name}}": [{% for fixture in body.fixtures %}{% if not forloop.first %},{% endif %}
3+
{
4+
{% if fixture.fixtureKey %}"fixtureKey": "{{fixture.fixtureKey}}",
5+
{% endif %}"isSensor": {{fixture.isSensor}},
6+
"filter": { "group": {{fixture.filter_groupIndex}}, "categoryBits": {{fixture.filter_categoryBits}}, "maskBits": {{fixture.filter_maskBits}} },
7+
{% if fixture.isCircle %}"circle": {
8+
"radius": {{fixture.radius|floatformat:3}},
9+
"position": [ {{fixture.center.x|floatformat:3}}, {{fixture.center.y|floatformat:3}} ]
10+
}{% else %}"polygons":[ {% for polygon in fixture.polygons %}{% if not forloop.first %},{% endif %}
11+
[ {% for point in polygon %}{% if not forloop.first %} , {% endif %} {{point.x}}, {{point.y}} {% endfor %} ]{% endfor %}
12+
]{% endif %}
13+
}{% endfor %}
14+
]{% endfor %}
15+
}

src/physics/p2/Body.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,9 @@ Phaser.Physics.P2.Body.prototype = {
12751275

12761276
/**
12771277
* Reads the shape data from a physics data file stored in the Game.Cache and adds it as a polygon to this Body.
1278-
* The shape data format is based on the custom phaser export in.
1278+
* The shape data format is based on the output of the
1279+
* {@link https://github.com/photonstorm/phaser/tree/master/resources/PhysicsEditor%20Exporter|custom phaser exporter} for
1280+
* {@link https://www.codeandweb.com/physicseditor|PhysicsEditor}
12791281
*
12801282
* @method Phaser.Physics.P2.Body#addPhaserPolygon
12811283
* @param {string} key - The key of the Physics Data file as stored in Game.Cache.

0 commit comments

Comments
 (0)