From be5efc5fa790cf74a85a3b6bafb06a8354c1d746 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Thu, 6 May 2021 15:31:59 -0700 Subject: [PATCH] [libgdx] Update version for JsonRollback. --- .../esotericsoftware/spine/JsonRollback.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/JsonRollback.java b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/JsonRollback.java index b4c06f111..9f68bc17e 100644 --- a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/JsonRollback.java +++ b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/JsonRollback.java @@ -67,6 +67,21 @@ public class JsonRollback { JsonValue root = new Json().fromJson(null, new FileHandle(args[0])); + // Update Spine version. + JsonValue skeleton = root.get("skeleton"); + if (skeleton == null) { + skeleton = new JsonValue(ValueType.object); + skeleton.name = "skeleton"; + JsonValue first = root.child; + root.child = skeleton; + skeleton.next = first; + } + JsonValue spine = skeleton.get("spine"); + if (spine != null) + spine.set(version + "-from-" + spine.asString()); + else + skeleton.addChild("spine", new JsonValue(version)); + if (version.equals("2.1")) { // In 3.2 skinnedmesh was renamed to weightedmesh. setValue(root, "skinnedmesh", "skins", "*", "*", "*", "type", "weightedmesh"); @@ -78,26 +93,26 @@ public class JsonRollback { 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")) + 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")) { + 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, + 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")) + 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")) { + 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; @@ -106,7 +121,7 @@ public class JsonRollback { } // In 3.3 IK constraint timelines no longer require bendPositive. - for (JsonValue value : find(root, new Array(), 0, "animations", "*", "ik", "*")) + 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)); @@ -138,6 +153,7 @@ public class JsonRollback { } if (args.length == 3) { + System.out.println("Writing: " + args[2]); BufferedWriter fileWriter = new BufferedWriter(new FileHandle(args[2]).writer(false, "UTF-8"), 16 * 1024); root.prettyPrint(OutputType.json, fileWriter); fileWriter.close(); @@ -150,7 +166,7 @@ public class JsonRollback { } static private void constraintNames (JsonValue root, String... path) { - for (JsonValue map : find(root, new Array(), 0, path)) { + for (JsonValue map : find(root, new Array(), 0, path)) { for (JsonValue constraint = map.child; constraint != null; constraint = constraint.next) { for (JsonValue child = constraint.child; child != null; child = child.next) { if (child.name.equals("mixRotate")) @@ -232,17 +248,17 @@ public class JsonRollback { } static void setValue (JsonValue root, String newValue, String... path) { - for (JsonValue value : find(root, new Array(), 0, path)) + for (JsonValue value : find(root, new Array(), 0, path)) value.set(newValue); } static void rename (JsonValue root, String newName, String... path) { - for (JsonValue value : find(root, new Array(), 0, path)) + for (JsonValue value : find(root, new Array(), 0, path)) value.name = newName; } static void delete (JsonValue root, String... path) { - for (JsonValue value : find(root, new Array(), 0, path)) + for (JsonValue value : find(root, new Array(), 0, path)) value.parent.remove(value.name); }