From 674ccc6cdb3e74d37fca78fe23ac1a77f7fe88cd Mon Sep 17 00:00:00 2001 From: miscoined Date: Fri, 28 Jun 2024 01:19:09 +1000 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Make=20mergeNodes=20accept?= =?UTF-8?q?=20an=20ObjectNode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mostly to minimize the stuff that needs to be repeated for the Pf2e implementation --- .../dev/ebullient/convert/tools/JsonSourceCopier.java | 9 ++++++--- .../convert/tools/dnd5e/Tools5eJsonSourceCopier.java | 9 +++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/dev/ebullient/convert/tools/JsonSourceCopier.java b/src/main/java/dev/ebullient/convert/tools/JsonSourceCopier.java index 74cdc9c1..820985bc 100644 --- a/src/main/java/dev/ebullient/convert/tools/JsonSourceCopier.java +++ b/src/main/java/dev/ebullient/convert/tools/JsonSourceCopier.java @@ -63,7 +63,10 @@ public JsonNode handleCopy(T type, JsonNode copyTo) { // is the copy a copy? copyFrom = handleCopy(type, copyFrom); try { - copyTo = mergeNodes(type, copyToKey, copyFrom, copyTo); + // edit in place: if you don't, lower-level copies will keep being revisted. + ObjectNode target = (ObjectNode) copyTo; + + copyTo = mergeNodes(type, copyToKey, copyFrom, target); } catch (JsonCopyException | StackOverflowError | UnsupportedOperationException e) { tui().errorf(e, "Error (%s): Unable to merge nodes. CopyTo: %s, CopyFrom: %s", copyToKey, copyTo, copyFrom); } @@ -71,8 +74,8 @@ public JsonNode handleCopy(T type, JsonNode copyTo) { return copyTo; } - protected JsonNode mergeNodes(T type, String copyToKey, JsonNode copyFrom, JsonNode copyTo) { - return copyTo; + protected JsonNode mergeNodes(T type, String copyToKey, JsonNode copyFrom, ObjectNode target) { + return target; } /** diff --git a/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eJsonSourceCopier.java b/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eJsonSourceCopier.java index cceef3f3..fc86bf21 100644 --- a/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eJsonSourceCopier.java +++ b/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eJsonSourceCopier.java @@ -193,11 +193,8 @@ public JsonNode mergeSubrace(JsonNode subraceNode, JsonNode raceNode) { // utils.js: static getCopy (impl, copyFrom, copyTo, templateData,...) { @Override - protected JsonNode mergeNodes(Tools5eIndexType type, String originKey, JsonNode copyFrom, JsonNode copyTo) { - // edit in place: if you don't, lower-level copies will keep being revisted. - ObjectNode target = (ObjectNode) copyTo; - - JsonNode _copy = MetaFields._copy.getFromOrEmptyObjectNode(copyTo); + protected JsonNode mergeNodes(Tools5eIndexType type, String originKey, JsonNode copyFrom, ObjectNode target) { + JsonNode _copy = MetaFields._copy.getFromOrEmptyObjectNode(target); normalizeMods(_copy); // fetch and apply any external template @@ -242,7 +239,7 @@ protected JsonNode mergeNodes(Tools5eIndexType type, String originKey, JsonNode copyValues(type, copyFrom, target, _copy); // apply any root template properties after doing base copy - List copyToRootProps = streamOfFieldNames(copyTo).toList(); + List copyToRootProps = streamOfFieldNames(target).toList(); for (JsonNode template : templates) { if (!MetaFields._root.nestedExistsIn(MetaFields.apply, template)) { continue;