-- This file is for use with quick-cocos2d-x framework
-- https://github.com/dualface/quick-cocos2d-x
--
-- This file is automatically generated with PhysicsEdtior (http://physicseditor.de). Do not edit
--
-- Usage example:
--			local scaleFactor = 1.0
--			local physicsData = require("shapedefs").physicsData(scaleFactor)
--			local shape = display.newSprite("objectname.png")
--          physics.bindBody(shape, physicsData:get("objectname"))
--

-- copy needed functions to local scope
local pairs = pairs
local ipairs = ipairs

local M = {}

function M.physicsData(scale)
    local physics = {data = {}}

    {% for body in bodies %}

    physics.data["{{body.name}}"] = {
        anchorpoint = { {{body.anchorPointRel.x|floatformat:5}},{{body.anchorPointRel.y|floatformat:5}} },
        fixtures = {
            {% for fixture in body.fixtures %}
            {
                mass = {{fixture.mass}},
                elasticity = {{fixture.elasticity}},
                friction = {{fixture.friction}},
                surface_velocity = { {{fixture.surface_velocity_x|floatformat:5}},{{fixture.surface_velocity_y|floatformat:5}} },
                layers = {{fixture.layers}},
                group = {{fixture.group}},
                collision_type = {{fixture.collision_type}},
                isSensor = {% if fixture.isSensor %}true{% else %}false{% endif %},
                fixture_type = "{{fixture.type}}",
                {% if fixture.isCircle %}
                radius = {{fixture.radius|floatformat:3}},
                position = { {{fixture.center.x|floatformat:3}},{{fixture.center.y|floatformat:3}} }
                {% else %}
                polygons = {
                    {% for polygon in fixture.polygons %}
                    {{% for point in polygon %}{{point.x|floatformat:5}}, {{point.y|floatformat:5}}, {% endfor %}},
                    {% endfor %}
                }
                {% endif %}
            },
            {% endfor %}
        },
    }

    {% endfor %}

    -- apply scale factor
    local s = scale or 1.0
    for bi, body in pairs(physics.data) do
        for fi, fixture in ipairs(body.fixtures) do
            if fixture.polygon then
                for ci, coordinate in ipairs(fixture.polygon) do
                    fixture.polygon[ci] = s * coordinate
                end
            else
                fixture.radius = s * fixture.radius
            end
        end
    end

    function physics:get(name)
        return self.data[name]
    end

    return physics
end

return M
