use of com.badlogic.gdx.physics.box2d.JointDef in project RubeLoader by tescott.
the class JointSerializer method read.
@SuppressWarnings("rawtypes")
@Override
public Joint read(Json json, JsonValue jsonData, Class type) {
if (bodies == null || world == null)
return null;
int indexA = json.readValue("bodyA", int.class, bodies.size, jsonData);
int indexB = json.readValue("bodyB", int.class, bodies.size, jsonData);
if (indexA >= bodies.size || indexB >= bodies.size)
return null;
Joint joint = null;
JointDef jointDef = null;
String jointType = json.readValue("type", String.class, jsonData);
if (jointType == null)
return null;
// First pass
if (joints == null && !jointType.equals("gear")) {
if (jointType.equals("revolute")) {
jointDef = json.readValue(RevoluteJointDef.class, jsonData);
} else if (jointType.equals("prismatic")) {
jointDef = json.readValue(PrismaticJointDef.class, jsonData);
} else if (jointType.equals("distance")) {
jointDef = json.readValue(DistanceJointDef.class, jsonData);
} else if (jointType.equals("pulley")) {
jointDef = json.readValue(PulleyJointDef.class, jsonData);
} else if (jointType.equals("mouse")) {
jointDef = json.readValue(MouseJointDef.class, jsonData);
} else if (jointType.equals("wheel")) {
jointDef = json.readValue(WheelJointDef.class, jsonData);
} else if (jointType.equals("weld")) {
jointDef = json.readValue(WeldJointDef.class, jsonData);
} else if (jointType.equals("friction")) {
jointDef = json.readValue(FrictionJointDef.class, jsonData);
} else if (jointType.equals("rope")) {
jointDef = json.readValue(RopeJointDef.class, jsonData);
}
} else if (// Second pass
joints != null && jointType.equals("gear")) {
jointDef = json.readValue(GearJointDef.class, jsonData);
}
if (jointDef != null) {
jointDef.bodyA = bodies.get(indexA);
jointDef.bodyB = bodies.get(indexB);
jointDef.collideConnected = json.readValue("collideConnected", boolean.class, RubeDefaults.Joint.collideConnected, jsonData);
joint = world.createJoint(jointDef);
if (jointType.equals("mouse")) {
((MouseJoint) joint).setTarget(mouseJointDefSerializer.target);
}
}
scene.parseCustomProperties(json, joint, jsonData);
String name = json.readValue("name", String.class, jsonData);
if (name != null) {
scene.putNamed(name, joint);
}
return joint;
}
Aggregations