Skip to content

Commit

Permalink
🎨 Suppress `* (Base)' notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Nov 30, 2023
1 parent 7ab3296 commit d15604d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
68 changes: 36 additions & 32 deletions src/main/java/dev/ebullient/convert/tools/dnd5e/Json2QuteRace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -229,8 +233,8 @@ public static void prepareBaseRace(Tools5eIndex tools5eIndex, JsonNode jsonSourc

public static void updateBaseRace(Tools5eIndex tools5eIndex, JsonNode jsonSource, Set<JsonNode> inputSubraces,
List<JsonNode> 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.
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,14 @@ public List<JsonNode> originNodesMatching(Function<JsonNode, Boolean> 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) {
Expand Down

0 comments on commit d15604d

Please sign in to comment.