package com.whoshuu.artbox.component;

import org.jbox2d.dynamics.Body;

import com.whoshuu.artbox.artemis.Component;
import com.whoshuu.artbox.artemis.Entity;

public class BodyComponent extends Component {

    public BodyComponent(Body body, Entity entity) {
        this.body = body;
        this.body.setUserData(entity);
    }

    public Body getBody() {
        return this.body;
    }

    private Body body;
}

@@ -54,21 +54,366 @@
 x2d.
-dynamics.Body
+collision.shapes.CircleShape;%0Aimport org.jbox2d.collision.shapes.EdgeShape;%0Aimport org.jbox2d.collision.shapes.PolygonShape;%0Aimport org.jbox2d.common.Vec2;%0Aimport org.jbox2d.dynamics.Body;%0Aimport org.jbox2d.dynamics.BodyDef;%0Aimport org.jbox2d.dynamics.BodyType;%0Aimport org.jbox2d.dynamics.FixtureDef;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject
 ;%0A%0Ai
@@ -441,24 +441,18 @@
 box.
-artemis.Componen
+GameContex
 t;%0Ai
@@ -484,22 +484,35 @@
 artemis.
-Entity
+utils.JSONComponent
 ;%0A%0Apubli
@@ -541,16 +541,20 @@
 extends 
+JSON
 Componen
@@ -587,161 +587,2145 @@
 ent(
-Body body, Entity entity) %7B%0A        this.body = body;%0A        this.body.setUserData(entit
+) %7B%0A        this.body = null;%0A    %7D%0A%0A    public BodyComponent(Body body) %7B%0A        this.body = body;%0A    %7D%0A%0A    public Body getBody() %7B%0A        return this.body;%0A    %7D%0A%0A    @Override%0A    public void fromJSON(JSONObject json, float x, float y, float angle) throws JSONException %7B%0A        BodyDef def = new BodyDef();%0A        def.type = json.optString(%22bodytype%22, %22dynamic%22).equals(%22dynamic%22)%0A                ? BodyType.DYNAMIC : BodyType.STATIC;%0A        def.position.set(x, y);%0A        def.angle = angle;%0A%0A        this.body = GameContext.get().getPhysics().createBody(def);%0A        if (body != null) %7B%0A            // Set shape, density, friction, and restitution%0A            FixtureDef fixture = new FixtureDef();%0A            JSONObject jsonShape = json.getJSONObject(%22shape%22);%0A            String shape = jsonShape.optString(%22type%22, %22circle%22);%0A            if (shape.equals(%22circle%22)) %7B%0A                CircleShape circle = new CircleShape();%0A                circle.setRadius((float) jsonShape.optDouble(%22radius%22, 1.0));%0A                fixture.shape = circle;%0A            %7D else if (shape.equals(%22edge%22)) %7B%0A                EdgeShape edge = new EdgeShape();%0A                edge.set(new Vec2(0, 0),%0A                        new Vec2((float) jsonShape.optDouble(%22x2%22, 1.0) - def.position.x,%0A                                (float) jsonShape.optDouble(%22y2%22, 1.0) - def.position.
 y)
+)
 ;%0A    
-%7D%0A%0A    public Body getBody() %7B%0A        return this.body;
+            fixture.shape = edge;%0A            %7D else if (shape.equals(%22box%22)) %7B%0A                PolygonShape box = new PolygonShape();%0A                box.setAsBox((float) (jsonShape.optDouble(%22w%22, 2.0) / 2.0),%0A                        (float) (jsonShape.optDouble(%22h%22, 2.0) / 2.0));%0A                fixture.shape = box;%0A            %7D else if (shape.equals(%22polygon%22)) %7B%0A                // TODO%0A            %7D else if (shape.equals(%22chain%22)) %7B%0A                // TODO%0A            %7D%0A            fixture.density = (float) json.optDouble(%22density%22, 1.0);%0A            fixture.friction = (float) json.optDouble(%22friction%22, 1.0);%0A            fixture.restitution = (float) json.optDouble(%22restitution%22, 1.0);%0A            this.body.createFixture(fixture);%0A        %7D
 %0A   

Add json support for body construction