List of usage examples for com.badlogic.gdx.utils JsonValue prettyPrint
public String prettyPrint(OutputType outputType, int singleLineColumns)
From source file:com.esotericsoftware.spine.JsonRollback.java
License:Open Source License
static public void main(String[] args) throws Exception { if (args.length == 0) { System.out.println("Usage: <inputFile> [outputFile]"); System.exit(0);/*from w ww . ja va 2s . c o m*/ } JsonValue root = new Json().fromJson(null, new FileHandle(args[0])); // In 3.2 skinnedmesh was renamed to weightedmesh. setValue(root, "skinnedmesh", "skins", "*", "*", "*", "type", "weightedmesh"); // In 3.2 shear was added. delete(root, "animations", "*", "bones", "*", "shear"); // In 3.3 ffd was renamed to deform. rename(root, "ffd", "animations", "*", "deform"); // In 3.3 mesh is now a single type, previously they were skinnedmesh if they had weights. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "mesh")) if (value.parent.get("uvs").size != value.parent.get("vertices").size) value.set("skinnedmesh"); // In 3.3 linkedmesh is now a single type, previously they were linkedweightedmesh if they had weights. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "linkedmesh")) { String slot = value.parent.parent.name.replaceAll("", ""); String skinName = value.parent.getString("skin", "default"); String parentName = value.parent.getString("parent"); if (find(root, new Array(), 0, ("skins~~" + skinName + "~~" + slot + "~~" + parentName + "~~type~~skinnedmesh") .split("~~")).size > 0) value.set("weightedlinkedmesh"); } // In 3.3 bounding boxes can be weighted. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "boundingbox")) if (value.parent.getInt("vertexCount") * 2 != value.parent.get("vertices").size) value.parent.parent.remove(value.parent.name); // In 3.3 paths were added. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "path")) { String attachment = value.parent.name; value.parent.parent.remove(attachment); String slot = value.parent.parent.name; // Also remove path deform timelines. delete(root, "animations", "*", "ffd", "*", slot, attachment); } // In 3.3 IK constraint timelines no longer require bendPositive. for (JsonValue value : find(root, new Array(), 0, "animations", "*", "ik", "*")) for (JsonValue child = value.child; child != null; child = child.next) if (!child.has("bendPositive")) child.addChild("bendPositive", new JsonValue(true)); // In 3.3 transform constraints can have more than 1 bone. for (JsonValue child = root.getChild("transform"); child != null; child = child.next) { JsonValue bones = child.remove("bones"); if (bones != null) child.addChild("bone", new JsonValue(bones.child.asString())); } if (args.length > 1) new FileHandle(args[1]).writeString(root.prettyPrint(OutputType.json, 130), false, "UTF-8"); else System.out.println(root.prettyPrint(OutputType.json, 130)); }
From source file:com.o2d.pkayjava.editor.data.migrations.migrators.VersionMigTo009.java
License:Apache License
@Override public boolean doMigration() { // run through scene files and modify their content to new one // this is list of libraryItems for later HashMap<String, JsonValue> libraryItems = new HashMap<>(); // fixing animations format (frameRange) and moving library items File scenesDir = new File(projectPath + File.separator + "scenes"); for (File entry : scenesDir.listFiles()) { if (!entry.isDirectory()) { try { String content = FileUtils.readFileToString(new FileHandle(entry).file()); JsonValue value = jsonReader.parse(content); fixAnimations(value.get("composite")); if (value.get("libraryItems") != null) { JsonValue.JsonIterator libraryArr = value.get("libraryItems").iterator(); while (libraryArr.hasNext()) { JsonValue libItem = libraryArr.next(); fixAnimations(libItem.get("composite")); libraryItems.put(libItem.name, libItem); }//from w w w.j a v a 2 s .co m value.remove("libraryItems"); } content = value.prettyPrint(JsonWriter.OutputType.json, 1); FileUtils.writeStringToFile(new File(entry.getAbsolutePath()), content, "utf-8"); } catch (IOException e) { e.printStackTrace(); } } } fixLibraryItemsLocation(libraryItems); return true; }
From source file:com.o2d.pkayjava.editor.data.migrations.migrators.VersionMigTo009.java
License:Apache License
private void fixLibraryItemsLocation(HashMap<String, JsonValue> libraryItems) { if (libraryItems.size() == 0) return;/*from w w w . ja v a 2 s .co m*/ //creating libraryArrayJsonString String libraryArrayJsonString = "{"; for (JsonValue entry : libraryItems.values()) { libraryArrayJsonString += "\"" + entry.name + "\": " + entry.prettyPrint(JsonWriter.OutputType.json, 1) + ", "; } libraryArrayJsonString = libraryArrayJsonString.substring(0, libraryArrayJsonString.length() - 2) + "}"; //ProjectInfo data String prjInfoFilePath = projectPath + "/project.dt"; FileHandle projectInfoFile = Gdx.files.internal(prjInfoFilePath); try { String projectInfoContents = FileUtils.readFileToString(projectInfoFile.file()); JsonValue value = jsonReader.parse(projectInfoContents); JsonValue newVal = jsonReader.parse(libraryArrayJsonString); newVal.name = "libraryItems"; newVal.prev = value.get("scenes"); newVal.next = newVal.prev.next; newVal.prev.next = newVal; String content = value.prettyPrint(JsonWriter.OutputType.json, 1); FileUtils.writeStringToFile(new File(prjInfoFilePath), content, "utf-8"); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.tussle.stream.JsonDistributingWriter.java
License:Open Source License
public void write(JsonValue jsonVal) { try {/* www . j av a 2s . co m*/ for (JsonValue i : jsonVal) { //Not a typo, we're iterating over the jsonValue we were handed if (writers.containsKey(i.name())) { try { writers.get(i.name()) .write(i.prettyPrint(JsonWriter.OutputType.json, Integer.MAX_VALUE) + "\n"); } catch (IOException ex) { JsonValue value = Utility.exceptionToJson(ex); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } else { JsonValue value = new JsonValue(JsonValue.ValueType.object); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } } catch (IOException ex) { throw new SerializationException(ex); } }
From source file:es.eucm.gleaner.viewer.TraceViewer.java
License:Apache License
@Override public void trace(String trace) { if (!tracker.isReady()) { return;//from www.j a v a2 s .co m } Table xAPI = new Table(); xAPI.add(new Label("[#000000]" + ++count + "[]", traceStyle)); xAPI.row(); xAPI.add(); LabelStyle style = skin.get("xapi", LabelStyle.class); if (style == null) { style = traceStyle; } JsonValue statement = new Json().fromJson(null, trace); System.out.println(statement.prettyPrint(OutputType.json, 0)); xAPI.add(new Label(statement.prettyPrint(OutputType.json, 0), style)).expandX().fillX(); detailed.addActor(xAPI); }