From 516a7111a7d0982bfb3848c63ef38b20355e6bc4 Mon Sep 17 00:00:00 2001 From: DanMB Date: Mon, 16 May 2022 23:34:58 -0700 Subject: [PATCH] f --- .../volmit/iris/core/edit/JigsawEditor.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java b/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java index 477e73591..d4b2db1f4 100644 --- a/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java +++ b/src/main/java/com/volmit/iris/core/edit/JigsawEditor.java @@ -27,6 +27,7 @@ import com.volmit.iris.engine.object.IrisJigsawPiece; import com.volmit.iris.engine.object.IrisJigsawPieceConnector; import com.volmit.iris.engine.object.IrisObject; import com.volmit.iris.engine.object.IrisPosition; +import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.Cuboid; import com.volmit.iris.util.io.IO; @@ -48,6 +49,7 @@ import org.bukkit.util.Vector; import java.io.File; import java.io.IOException; +import java.util.List; import java.util.concurrent.ExecutionException; public class JigsawEditor implements Listener { @@ -155,15 +157,48 @@ public class JigsawEditor implements Listener { } } + private void removeKey(JSONObject o, String... path) + { + if(path.length == 1) + { + o.remove(path[0]); + return; + } + + List s = new java.util.ArrayList<>(List.of(path)); + s.remove(0); + removeKey(o.getJSONObject(path[0]), s.toArray(new String[0])); + } + + private List getObjectsInArray(JSONObject a, String key) + { + KList o = new KList<>(); + + for(int i = 0; i < a.getJSONArray(key).length(); i++) + { + o.add(a.getJSONArray(key).getJSONObject(i)); + } + + return o; + } + public void close() { exit(); try { JSONObject j = new JSONObject(new Gson().toJson(piece)); // Remove sub-key - // J.attempt(() -> j.getJSONObject("placementOptions").remove("translateCenter")); + removeKey(j, "placementOptions", "translateCenter"); // should work + J.attempt(() -> j.getJSONObject("placementOptions").remove("translateCenter")); // otherwise // remove root key - // j.remove("placementOptions"); + removeKey(j, "placementOptions"); // should work + j.remove("placementOptions"); // otherwise + + // Remove key in all objects in array + for(JSONObject i : getObjectsInArray(j, "connectors")) + { + removeKey(i, "rotateConnector"); + } IO.writeAll(targetSaveLocation, j.toString(4)); } catch(IOException e) {