public double[][][] convertToDoubleArray(JsonValue json, int size, int d) { double[][][] result = new double[size][][]; int i = 0; JsonValue current = json; if (d > 1) current = json.child; do { double[][] l1 = new double[current.size][]; // Fill in last level JsonValue child = current.child; int j = 0; do { double[] l2 = child.asDoubleArray(); l1[j] = l2; child = child.next(); j++; } while (child != null); result[i] = l1; if (d == 1) { current = current.next(); } else { current = json.next() != null ? json.next().child : null; json = json.next(); } i++; } while (current != null); return result; }
public double[][][] convertToDoubleArray(JsonValue json, int size) { double[][][] result = new double[size][][]; int i = 0; do { double[][] l1 = new double[json.size][]; // Fill in last level JsonValue child = json.child; int j = 0; do { double[] l2 = child.asDoubleArray(); l1[j] = l2; child = child.next(); j++; } while (child != null); result[i] = l1; json = json.next(); i++; } while (json != null); return result; }
// ---------------------- // Json reading process // ---------------------- private Model readJson(String str) { Model m = new Model(); JsonValue map = new JsonReader().parse(str); JsonValue bodyElem = map.getChild("rigidBodies"); for (; bodyElem != null; bodyElem = bodyElem.next()) { RigidBodyModel rbModel = readRigidBody(bodyElem); m.rigidBodies.put(rbModel.name, rbModel); } return m; }
@Override public char[][] read(Json json, JsonValue jsonData, Class type) { if(jsonData == null || jsonData.isNull()) return null; int sz = jsonData.size; char[][] data = new char[sz][]; JsonValue c = jsonData.child(); for (int i = 0; i < sz && c != null; i++, c = c.next()) { data[i] = c.asString().toCharArray(); } return data; } });
private Model readJson(String str) { Model model = new Model(); JsonValue map = new JsonReader().parse(str); for (JsonValue rbJson = map.getChild("rigidBodies"); rbJson != null; rbJson = rbJson.next()) { RigidBodyModel rbModel = readRigidBody(rbJson); model.rigidBodies.put(rbModel.name, rbModel); } return model; }
private Model readJson (String str) { Model m = new Model(); JsonValue root = new JsonReader().parse(str); JsonValue bodies = root.get("rigidBodies"); for (JsonValue body = bodies.child(); body != null; body = body.next()) { RigidBodyModel rbModel = readRigidBody(body); m.rigidBodies.put(rbModel.name, rbModel); } return m; }
private Model readJson(String str) { Model m = new Model(); JsonValue root = new JsonReader().parse(str); JsonValue bodies = root.get("rigidBodies"); for (JsonValue body = bodies.child(); body != null; body = body.next()) { RigidBodyModel rbModel = readRigidBody(body); m.rigidBodies.put(rbModel.name, rbModel); } return m; }
private RigidBodyModel readRigidBody (JsonValue bodyElem) { RigidBodyModel rbModel = new RigidBodyModel(); rbModel.name = bodyElem.getString("name"); rbModel.imagePath = bodyElem.getString("imagePath"); JsonValue origin = bodyElem.get("origin"); rbModel.origin.x = origin.getFloat("x"); rbModel.origin.y = origin.getFloat("y"); // polygons JsonValue polygons = bodyElem.get("polygons"); for (JsonValue vertices = polygons.child(); vertices != null; vertices = vertices.next()) { PolygonModel polygon = new PolygonModel(); rbModel.polygons.add(polygon); for (JsonValue vertex = vertices.child(); vertex != null; vertex = vertex.next()) { polygon.vertices.add(new Vector2(vertex.getFloat("x"), vertex.getFloat("y"))); } polygon.buffer = new Vector2[polygon.vertices.size()]; } // circles JsonValue circles = bodyElem.get("circles"); for (JsonValue circle = circles.child(); circle != null; circle = circle.next()) { CircleModel c = new CircleModel(); rbModel.circles.add(c); c.center.x = circle.getFloat("cx"); c.center.y = circle.getFloat("cy"); c.radius = circle.getFloat("r"); } return rbModel; }
private RigidBodyModel readRigidBody (JsonValue bodyElem) { RigidBodyModel rbModel = new RigidBodyModel(); rbModel.name = bodyElem.getString("name"); rbModel.imagePath = bodyElem.getString("imagePath"); JsonValue origin = bodyElem.get("origin"); rbModel.origin.x = origin.getFloat("x"); rbModel.origin.y = origin.getFloat("y"); // polygons JsonValue polygons = bodyElem.get("polygons"); for (JsonValue vertices = polygons.child(); vertices != null; vertices = vertices.next()) { PolygonModel polygon = new PolygonModel(); rbModel.polygons.add(polygon); for (JsonValue vertex = vertices.child(); vertex != null; vertex = vertex.next()) { polygon.vertices.add(new Vector2(vertex.getFloat("x"), vertex.getFloat("y"))); } polygon.buffer = new Vector2[polygon.vertices.size()]; } // circles JsonValue circles = bodyElem.get("circles"); for (JsonValue circle = circles.child(); circle != null; circle = circle.next()) { CircleModel c = new CircleModel(); rbModel.circles.add(c); c.center.x = circle.getFloat("cx"); c.center.y = circle.getFloat("cy"); c.radius = circle.getFloat("r"); } return rbModel; }
for (JsonValue polygonJson = polygonsJson.child(); polygonJson != null; polygonJson = polygonJson.next()) { // Can I use next instead of next() ? PolygonModel polygonModel = new PolygonModel(); rbModel.polygons.add(polygonModel); for (JsonValue vertexJson = polygonJson.child(); vertexJson != null; vertexJson = vertexJson.next()) { float x = vertexJson.get("x").asFloat(); float y = vertexJson.get("y").asFloat(); for (JsonValue circleJson = circlesJson.child(); circleJson != null; circleJson = circleJson.next()) { // Can I use next instead of next() ? CircleModel circleModel = new CircleModel(); rbModel.circles.add(circleModel);