diff --git a/src/main/java/dev/ebullient/convert/tools/dnd5e/Json2QuteRace.java b/src/main/java/dev/ebullient/convert/tools/dnd5e/Json2QuteRace.java index 5055f980e..719c26fef 100644 --- a/src/main/java/dev/ebullient/convert/tools/dnd5e/Json2QuteRace.java +++ b/src/main/java/dev/ebullient/convert/tools/dnd5e/Json2QuteRace.java @@ -27,6 +27,10 @@ public class Json2QuteRace extends Json2QuteCommon { @Override protected QuteRace buildQuteResource() { + if (RaceFields._rawName.existsIn(rootNode)) { + tui().debugf("Skipping output of base race %s", sources.getKey()); + return null; + } String name = type.decoratedName(rootNode); Tags tags = new Tags(getSources()); @@ -229,8 +233,8 @@ public static void prepareBaseRace(Tools5eIndex tools5eIndex, JsonNode jsonSourc public static void updateBaseRace(Tools5eIndex tools5eIndex, JsonNode jsonSource, Set inputSubraces, List subraces) { - if (!RaceFields._isBaseRace.existsIn(jsonSource)) { + if (!RaceFields._isBaseRace.existsIn(jsonSource)) { // If one of the original subraces was missing a name, it shares // the base race name. Update the base race name to differentiate // it from the subrace. @@ -243,37 +247,37 @@ public static void updateBaseRace(Tools5eIndex tools5eIndex, JsonNode jsonSource TtrpgValue.indexKey.getTextOrThrow(jsonSource)); } - subraces.sort((a, b) -> { - String aName = SourceField.name.getTextOrThrow(a); - String bName = SourceField.name.getTextOrThrow(b); - return aName.compareTo(bName); - }); - - ArrayNode entries = SourceField.entries.readArrayFrom(jsonSource); - - ArrayNode subraceList = entries.arrayNode(); - subraces.forEach(x -> subraceList.add(String.format("{@race %s|%s|%s (%s)}", - SourceField.name.getTextOrThrow(x), - SourceField.source.getTextOrThrow(x), - SourceField.name.getTextOrThrow(x), - SourceField.source.getTextOrThrow(x)))); - - ArrayNode sections = entries.arrayNode() - .add(entries.objectNode() - .put("type", "section") - .set("entries", entries.arrayNode() - .add("This race has multiple subraces, as listed below:") - .add(entries.objectNode() - .put("type", "list") - .set("items", subraceList)))) - .add(entries.objectNode() - .put("type", "section") - .set("entries", entries.objectNode() - .put("type", "entries") - .put("name", "Traits") - .set("entries", entries))); - - SourceField.entries.setIn(jsonSource, sections); + // subraces.sort((a, b) -> { + // String aName = SourceField.name.getTextOrThrow(a); + // String bName = SourceField.name.getTextOrThrow(b); + // return aName.compareTo(bName); + // }); + + // ArrayNode entries = SourceField.entries.readArrayFrom(jsonSource); + + // ArrayNode subraceList = entries.arrayNode(); + // subraces.forEach(x -> subraceList.add(String.format("{@race %s|%s|%s (%s)}", + // SourceField.name.getTextOrThrow(x), + // SourceField.source.getTextOrThrow(x), + // SourceField.name.getTextOrThrow(x), + // SourceField.source.getTextOrThrow(x)))); + + // ArrayNode sections = entries.arrayNode() + // .add(entries.objectNode() + // .put("type", "section") + // .set("entries", entries.arrayNode() + // .add("This race has multiple subraces, as listed below:") + // .add(entries.objectNode() + // .put("type", "list") + // .set("items", subraceList)))) + // .add(entries.objectNode() + // .put("type", "section") + // .set("entries", entries.objectNode() + // .put("type", "entries") + // .put("name", "Traits") + // .set("entries", entries))); + + // SourceField.entries.setIn(jsonSource, sections); RaceFields._isBaseRace.setIn(jsonSource, BooleanNode.TRUE); } } diff --git a/src/main/java/dev/ebullient/convert/tools/dnd5e/JsonSourceCopier.java b/src/main/java/dev/ebullient/convert/tools/dnd5e/JsonSourceCopier.java index c8fac9d56..1e0f90def 100644 --- a/src/main/java/dev/ebullient/convert/tools/dnd5e/JsonSourceCopier.java +++ b/src/main/java/dev/ebullient/convert/tools/dnd5e/JsonSourceCopier.java @@ -88,7 +88,7 @@ JsonNode handleCopy(Tools5eIndexType type, JsonNode copyTo) { JsonNode _copy = MetaFields._copy.getFrom(copyTo); if (_copy != null) { String copyFromKey = type.createKey(_copy); - JsonNode copyFrom = index().getOrigin(copyFromKey); + JsonNode copyFrom = index().getOriginNoFallback(copyFromKey); if (copyToKey.equals(copyFromKey)) { tui().errorf("Error (%s): Self-referencing copy. This is a data entry error. %s", copyToKey, _copy); return copyTo; @@ -115,7 +115,7 @@ public JsonNode mergeSubrace(JsonNode subraceNode, JsonNode raceNode) { List.of("name", "source", "srd", "basicRules") .forEach(p -> subraceOut.set("_base" + toTitleCase(p), subraceOut.get(p))); - List.of("subraces", "srd", "basicRules", "_versions", "hasFluff", "hasFluffImages") + List.of("subraces", "srd", "basicRules", "_versions", "hasFluff", "hasFluffImages", "_rawName") .forEach(subraceOut::remove); copyFrom.remove("__prop"); // cleanup: we copy remainder later @@ -167,7 +167,8 @@ public JsonNode mergeSubrace(JsonNode subraceNode, JsonNode raceNode) { JsonNode data = MetaFields.data.getFrom(entry); if (MetaFields.overwrite.existsIn(data)) { // overwrite - int index = findIndexByName("subracething", entries, MetaFields.overwrite.getTextOrThrow(data)); + int index = findIndexByName("subrace-merge:" + SourceField.name.getTextOrThrow(subraceOut), + entries, MetaFields.overwrite.getTextOrThrow(data)); if (index >= 0) { entries.set(index, entry); } else { @@ -225,7 +226,7 @@ JsonNode mergeNodes(Tools5eIndexType type, String originKey, JsonNode copyFrom, if (_trait != null) { // fetch and apply external template mods String templateKey = Tools5eIndexType.monsterTemplate.createKey(_trait); - JsonNode template = index.getOrigin(templateKey); + JsonNode template = index.getOriginNoFallback(templateKey); if (template == null) { tui().warn("Unable to find trait for " + templateKey); } else { @@ -315,6 +316,7 @@ JsonNode mergeNodes(Tools5eIndexType type, String originKey, JsonNode copyFrom, // indicate that this is a copy, and remove copy metadata (avoid revisit) target.put("isCopy", true); + target.remove("_rawName"); MetaFields._copiedFrom.setIn(target, String.format("%s (%s)", SourceField.name.getTextOrEmpty(copyFrom), SourceField.source.getTextOrEmpty(copyFrom))); diff --git a/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eIndex.java b/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eIndex.java index 907bbc200..61ad74c6a 100644 --- a/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eIndex.java +++ b/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eIndex.java @@ -844,6 +844,14 @@ public List originNodesMatching(Function filter) { .collect(Collectors.toList()); } + public JsonNode getOriginNoFallback(String finalKey) { + JsonNode result = nodeIndex.get(finalKey); + if (result == null) { + result = variantIndex.get(finalKey); + } + return result; + } + public JsonNode getOrigin(String finalKey) { JsonNode result = nodeIndex.get(finalKey); if (result == null) {