List of usage examples for com.badlogic.gdx.utils JsonWriter array
public JsonWriter array(String name) throws IOException
From source file:com.steelkiwi.patheditor.proj.ProjectDataConverter.java
License:Apache License
private static void savePathToJSON(String projPath, GdxPath gdxPath) throws Exception { String path = projPath + gdxPath.getJsonPath(); File pathFile = new File(path); if (pathFile.exists()) { pathFile.delete();/*from w ww . ja va2 s . c om*/ } pathFile.createNewFile(); StringWriter strWriter = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(strWriter); jsonWriter.object().object("path").set("name", gdxPath.getName()).set("pointsCnt", gdxPath.getPointsCnt()) .set("controlColor", gdxPath.getControlColor()).set("segmentColor", gdxPath.getSegmentColor()) .set("selectColor", gdxPath.getSelectColor()).set("xmlPath", gdxPath.getXmlPath()) .set("jsonPath", gdxPath.getJsonPath()); if ((gdxPath.getPath() != null) && (gdxPath.getPath().getPathVerticesCount() > 0)) { jsonWriter.array("controlVertices"); Vector3 controlVertex; for (int i = 0; i < gdxPath.getControlPath().size(); i++) { controlVertex = gdxPath.getControlPath().get(i); jsonWriter.object().set("id", i).set("x", controlVertex.x).set("y", controlVertex.y).pop(); } jsonWriter.pop(); jsonWriter.array("vertices"); PathVertex vertex; for (int i = 0; i < gdxPath.getPath().getPathVerticesCount(); i++) { vertex = gdxPath.getPath().getPathVertexByIndex(i); jsonWriter.object().set("id", i).set("x", vertex.getPosition().x).set("y", vertex.getPosition().y) .set("tanX", vertex.getTangentNornal().x).set("tanY", vertex.getTangentNornal().y) .set("angle", vertex.getAngle()).pop(); } jsonWriter.pop(); } jsonWriter.pop(); jsonWriter.pop(); jsonWriter.close(); FileWriter writer = new FileWriter(new File(path)); writer.write(strWriter.toString()); writer.close(); }