{% load defold %}
{% for body in bodies %}

--- {{body.name}}.go ---

embedded_components {
  id: "sprite"
  type: "sprite"
  data: "default_animation: \"{{body.name}}\"\n"
  "material: \"/builtins/materials/sprite.material\"\n"
  "blend_mode: BLEND_MODE_ALPHA\n"
  "textures {\n"
  "  sampler: \"texture_sampler\"\n"
  "  texture: \"{{global.atlas_path}}\"\n"
  "}\n"
  ""
  position {
    x: 0.0
    y: 0.0
    z: 0.0
  }
  rotation {
    x: 0.0
    y: 0.0
    z: 0.0
    w: 1.0
  }
}
  {% for fixture in body.fixtures|polygonFixtures %}
    {% for polygon in fixture.polygons %}
embedded_components {
  id: "{{body.name}}_polygon_{{forloop.parentloop.counter0}}_{{forloop.counter0}}"
  type: "collisionobject"
  data: "collision_shape: \"{{global.shape_path}}/{{body.name}}/fixture{{forloop.parentloop.counter0}}_poly{{forloop.counter0}}.convexshape\"\n"
  "type: {{fixture.shape_type}}\n"
  "mass: {{fixture.mass|floatformat:-2}}\n"
  "friction: {{fixture.friction|floatformat:-2}}\n"
  "restitution: {{fixture.restitution|floatformat:-2}}\n"
  "group: \"{{fixture.group}}\"\n"
  "mask: \"{{fixture.mask}}\"\n"
  "linear_damping: {{fixture.linear_damping|floatformat:-2}}\n"
  "angular_damping: {{fixture.angular_damping|floatformat:-2}}\n"
  "locked_rotation: {{fixture.locked_rotation}}\n"
  "bullet: {{fixture.bullet}}\n"
  ""
  position {
    x: 0.0
    y: 0.0
    z: 0.0
  }
  rotation {
    x: 0.0
    y: 0.0
    z: 0.0
    w: 1.0
  }
}
    {% endfor %}
  {% endfor %}
  {% if body.fixtures|circleFixtures %}
    {% for fixture in body.fixtures|circleFixtures %}
embedded_components {
  id: "{{body.name}}_circle_{{forloop.counter0}}"
  type: "collisionobject"
  data: "collision_shape: \"\"\n"
  "type: {{fixture.shape_type}}\n"
  "mass: {{fixture.mass|floatformat:-2}}\n"
  "friction: {{fixture.friction|floatformat:-2}}\n"
  "restitution: {{fixture.restitution|floatformat:-2}}\n"
  "group: \"{{fixture.group}}\"\n"
  "mask: \"{{fixture.mask}}\"\n"
  "embedded_collision_shape {\n"
  "  shapes {\n"
  "    shape_type: TYPE_SPHERE\n"
  "    position {\n"
  "      x: {{fixture.center.x|floatformat:-4}}\n"
  "      y: {{fixture.center.y|floatformat:-4}}\n"
  "      z: 0.0\n"
  "    }\n"
  "    rotation {\n"
  "      x: 0.0\n"
  "      y: 0.0\n"
  "      z: 0.0\n"
  "      w: 1.0\n"
  "    }\n"
  "    index: 0\n"
  "    count: 1\n"
  "    id: \"\"\n"
  "  }\n"
  "  data: {{fixture.radius|floatformat:-4}}\n"
  "}\n"
  "linear_damping: {{fixture.linear_damping|floatformat:-2}}\n"
  "angular_damping: {{fixture.angular_damping|floatformat:-2}}\n"
  "locked_rotation: {{fixture.locked_rotation}}\n"
  "bullet: {{fixture.bullet}}\n"
  ""
  position {
    x: 0.0
    y: 0.0
    z: 0.0
  }
  rotation {
    x: 0.0
    y: 0.0
    z: 0.0
    w: 1.0
  }
}
    {% endfor %}
  {% endif %}
{% endfor %}


{% for body in bodies %}
  {% for fixture in body.fixtures|polygonFixtures %}
    {% for polygon in fixture.polygons %}

--- {{body.name}}/fixture{{forloop.parentloop.counter0}}_poly{{forloop.counter0}}.convexshape ---

shape_type: TYPE_HULL{% for point in polygon %}
data: {{point.x|floatformat:-4}}
data: {{point.y|floatformat:-4}}
data: 0{% endfor %}

      {% endfor %}
  {% endfor %}
{% endfor %}
