mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[libgdx] Updated JsonRollback tool to go from 3.8 JSON to 3.7.
This commit is contained in:
parent
2cc92a6f7c
commit
c98ed30ebb
@ -33,10 +33,12 @@ import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
import com.badlogic.gdx.utils.JsonValue.ValueType;
|
||||
import com.badlogic.gdx.utils.JsonWriter.OutputType;
|
||||
|
||||
/** Takes Spine JSON data and transforms it to work with an older version of Spine. It supports going from version 3.3.xx to
|
||||
* 2.1.27.
|
||||
/** Takes Spine JSON data and transforms it to work with an older version of Spine. Target versions:<br>
|
||||
* 2.1: supports going from version 3.3.xx to 2.1.27.<br>
|
||||
* 3.7: supports going from version 3.8.xx to 3.7.94.
|
||||
* <p>
|
||||
* Data can be exported from a Spine project, processed with JsonRollback, then imported into an older version of Spine. However,
|
||||
* JsonRollback may remove data for features not supported by the older Spine version. Because of this, JsonRollback is only
|
||||
@ -47,13 +49,21 @@ import com.badlogic.gdx.utils.JsonWriter.OutputType;
|
||||
* the runtime is updated to support a newer Spine version should animators update their Spine editor version to match. */
|
||||
public class JsonRollback {
|
||||
static public void main (String[] args) throws Exception {
|
||||
if (args.length == 0) {
|
||||
System.out.println("Usage: <inputFile> [outputFile]");
|
||||
if (args.length != 2 && args.length != 3) {
|
||||
System.out.println("Usage: <inputFile> <targetVersion> [outputFile]");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
String version = args[1];
|
||||
if (!version.equals("2.1") && !version.equals("3.7")) {
|
||||
System.out.println("ERROR: Target version must be: 2.1 or 3.7");
|
||||
System.out.println("Usage: <inputFile> <toVersion> [outputFile]");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
JsonValue root = new Json().fromJson(null, new FileHandle(args[0]));
|
||||
|
||||
if (version.equals("2.1")) {
|
||||
// In 3.2 skinnedmesh was renamed to weightedmesh.
|
||||
setValue(root, "skinnedmesh", "skins", "*", "*", "*", "type", "weightedmesh");
|
||||
|
||||
@ -101,13 +111,47 @@ public class JsonRollback {
|
||||
JsonValue bones = child.remove("bones");
|
||||
if (bones != null) child.addChild("bone", new JsonValue(bones.child.asString()));
|
||||
}
|
||||
} else if (version.equals("3.7")) {
|
||||
JsonValue skins = root.get("skins");
|
||||
if (skins != null && skins.isArray()) {
|
||||
JsonValue newSkins = new JsonValue(ValueType.object);
|
||||
for (JsonValue skinMap = skins.child; skinMap != null; skinMap = skinMap.next) {
|
||||
JsonValue newSkin = skinMap.get("attachments");
|
||||
newSkins.addChild(skinMap.getString("name"), newSkin);
|
||||
}
|
||||
root.remove("skins");
|
||||
root.addChild("skins", newSkins);
|
||||
}
|
||||
|
||||
if (args.length > 1)
|
||||
new FileHandle(args[1]).writeString(root.prettyPrint(OutputType.json, 130), false, "UTF-8");
|
||||
rollbackCurves(root.get("animations"));
|
||||
}
|
||||
|
||||
if (args.length == 3)
|
||||
new FileHandle(args[2]).writeString(root.prettyPrint(OutputType.json, 130), false, "UTF-8");
|
||||
else
|
||||
System.out.println(root.prettyPrint(OutputType.json, 130));
|
||||
}
|
||||
|
||||
static private void rollbackCurves (JsonValue map) {
|
||||
if (map == null) return;
|
||||
JsonValue curve = map.get("curve");
|
||||
if (curve == null) {
|
||||
for (map = map.child; map != null; map = map.next)
|
||||
rollbackCurves(map);
|
||||
return;
|
||||
}
|
||||
if (curve.isNumber()) {
|
||||
curve.addChild(new JsonValue(curve.asFloat()));
|
||||
curve.setType(ValueType.array);
|
||||
curve.addChild(new JsonValue(map.getFloat("c2", 0)));
|
||||
curve.addChild(new JsonValue(map.getFloat("c3", 0)));
|
||||
curve.addChild(new JsonValue(map.getFloat("c4", 0)));
|
||||
map.remove("c2");
|
||||
map.remove("c3");
|
||||
map.remove("c4");
|
||||
}
|
||||
}
|
||||
|
||||
static void setValue (JsonValue root, String newValue, String... path) {
|
||||
for (JsonValue value : find(root, new Array<JsonValue>(), 0, path))
|
||||
value.set(newValue);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user