Add option to prefix shape name and optimize JSON output

This commit is contained in:
Christoph Dörfel 2015-09-16 14:00:24 +02:00
parent 61edd1b458
commit 4c9412088c
3 changed files with 80 additions and 88 deletions

View file

@ -1,7 +1,7 @@
<exporter>
<name>phaser-json</name>
<displayName>Phaser (JSON)</displayName>
<description>Exporter for Phaser, JSON</description>
<description>Exporter for Phaser, JSON</description>
<version>1.0</version>
<yAxisDirection>down</yAxisDirection>
<physicsEngine>box2d</physicsEngine>
@ -11,63 +11,73 @@
<enabled>no</enabled>
</anchorPoint>
<origin>
<type>fixed</type>
<relX>0.0</relX>
<relY>1.0</relY>
</origin>
<supportsCircles>yes</supportsCircles>
<type>fixed</type>
<relX>0.0</relX>
<relY>1.0</relY>
</origin>
<supportsCircles>yes</supportsCircles>
<global>
<parameter>
<name>name_prefix</name>
<displayName>Name prefix</displayName>
<shortDescription>Prepend sprite name</shortDescription>
<description>Prepend the sprite name with a string, mimicking the option 'prepend folder name' in TexturePacker.</description>
<type><code>string</code></type>
<default></default>
</parameter>
</global>
<body>
</body>
<fixture>
<parameter>
<name>fixtureKey</name>
<description>Give this fixture a unique KEY so you can retrieve it later in phaser</description>
<displayName>Fixture's Key</displayName>
<type>string</type>
<default></default>
</parameter>
<parameter>
<name>fixtureKey</name>
<description>Give this fixture a unique KEY so you can retrieve it later in Phaser.</description>
<displayName>Fixture's Key</displayName>
<type>string</type>
<default></default>
</parameter>
<parameter>
<name>isSensor</name>
<displayName>Is Sensor</displayName>
<description>If set the physial </description>
<type>bool</type>
<default>false</default>
</parameter>
<parameter>
<name>isSensor</name>
<displayName>Is Sensor</displayName>
<description>If set the physical</description>
<type>bool</type>
<default>false</default>
</parameter>
<parameter>
<name>filter_groupIndex</name>
<displayName>Group</displayName>
<description>Collision group.</description>
<shortDescription></shortDescription>
<type>int</type>
<default>0</default>
</parameter>
<parameter>
<name>filter_groupIndex</name>
<displayName>Group</displayName>
<description>Collision group</description>
<shortDescription></shortDescription>
<type>int</type>
<default>0</default>
</parameter>
<parameter>
<name>filter_bitfield</name>
<type>bitfield</type>
<size>16</size>
</parameter>
<parameter>
<name>filter_bitfield</name>
<type>bitfield</type>
<size>16</size>
</parameter>
<parameter>
<name>filter_categoryBits</name>
<displayName>Cat.</displayName>
<description>Collision category</description>
<shortDescription>Collision category</shortDescription>
<type>uint16</type>
<default>1</default>
<bitfield>yes</bitfield>
</parameter>
<parameter>
<name>filter_maskBits</name>
<displayName>Mask</displayName>
<description>Collision mask</description>
<shortDescription>Collision mask</shortDescription>
<type>uint16</type>
<default>65535</default>
<bitfield>yes</bitfield>
</parameter>
</fixture>
<parameter>
<name>filter_categoryBits</name>
<displayName>Cat.</displayName>
<description>Collision category</description>
<shortDescription>Collision category</shortDescription>
<type>uint16</type>
<default>1</default>
<bitfield>yes</bitfield>
</parameter>
<parameter>
<name>filter_maskBits</name>
<displayName>Mask</displayName>
<description>Collision mask</description>
<shortDescription>Collision mask</shortDescription>
<type>uint16</type>
<default>65535</default>
<bitfield>yes</bitfield>
</parameter>
</fixture>
</exporter>

View file

@ -1,35 +1,15 @@
{ {% for body in bodies %}
{% if not forloop.first %}, {% endif %}
"{{body.name}}": [
{% for fixture in body.fixtures %}{% if not forloop.first %} ,{% endif %}
{
{% if fixture.fixtureKey %}
"fixtureKey": "{{fixture.fixtureKey}}",
{% endif %}
"isSensor": {{fixture.isSensor}},
"filter": {
"group": {{fixture.filter_groupIndex}},
"categoryBits": {{fixture.filter_categoryBits}},
"maskBits": {{fixture.filter_maskBits}}
},
{% if fixture.isCircle %}
"circle": {
"radius": {{fixture.radius|floatformat:3}},
"position": [
{{fixture.center.x|floatformat:3}},
{{fixture.center.y|floatformat:3}}
]
}
{% else %}
"polygons":[
{% for polygon in fixture.polygons %}{% if not forloop.first %} ,{% endif %}
[ {% for point in polygon %} {% if not forloop.first %}, {% endif %} {{point.x}}, {{point.y}} {% endfor %} ]
{% endfor %}
]
{% endif %}
}
{% endfor %}
]
{% endfor %}
}
{{% for body in bodies %}{% if not forloop.first %},{% endif %}
"{% if global.name_prefix %}{{global.name_prefix}}/{% endif %}{{body.name}}": [{% for fixture in body.fixtures %}{% if not forloop.first %},{% endif %}
{
{% if fixture.fixtureKey %}"fixtureKey": "{{fixture.fixtureKey}}",
{% endif %}"isSensor": {{fixture.isSensor}},
"filter": { "group": {{fixture.filter_groupIndex}}, "categoryBits": {{fixture.filter_categoryBits}}, "maskBits": {{fixture.filter_maskBits}} },
{% if fixture.isCircle %}"circle": {
"radius": {{fixture.radius|floatformat:3}},
"position": [ {{fixture.center.x|floatformat:3}}, {{fixture.center.y|floatformat:3}} ]
}{% else %}"polygons":[ {% for polygon in fixture.polygons %}{% if not forloop.first %},{% endif %}
[ {% for point in polygon %}{% if not forloop.first %} , {% endif %} {{point.x}}, {{point.y}} {% endfor %} ]{% endfor %}
]{% endif %}
}{% endfor %}
]{% endfor %}
}

View file

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