Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #283

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ protected String findSourceText(IndexType type, JsonNode jsonElement) {
JsonNode copyElement = Fields._copy.getFrom(jsonElement);
String copyOf = SourceField.name.getTextOrNull(copyElement);
String copySrc = SourceField.source.getTextOrNull(copyElement);
String copiedFrom = Fields._copiedFrom.getTextOrNull(copyElement);

if (copyOf != null) {
srcText.add(String.format("Derived from %s (%s)", copyOf, copySrc));
} else if (Fields._copiedFrom.existsIn(jsonElement)) {
srcText.add(String.format("Derived from %s", Fields._copiedFrom.getTextOrEmpty(copyElement)));
} else if (copiedFrom != null) {
srcText.add(String.format("Derived from %s", copiedFrom));
}

// find/add additional sources
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ public String createKey(JsonNode x) {
SourceField.source.getTextOrEmpty(x));
}

String name = SourceField.name.getTextOrEmpty(x);
String source = SourceField.source.getTextOrEmpty(x);
String name = SourceField.name.getTextOrEmpty(x).trim();
String source = SourceField.source.getTextOrEmpty(x).trim();

switch (this) {
case classfeature -> {
Expand All @@ -152,24 +152,24 @@ public String createKey(JsonNode x) {
.toLowerCase();
}
case card -> {
String set = DeckFields.set.getTextOrThrow(x);
String set = DeckFields.set.getTextOrThrow(x).trim();
return String.format("%s|%s|%s|%s",
this.name(),
name.trim(),
set.trim(),
name,
set,
source)
.toLowerCase();
}
case deity -> {
return String.format("%s|%s|%s|%s",
this.name(),
name,
IndexFields.pantheon.getTextOrEmpty(x),
IndexFields.pantheon.getTextOrEmpty(x).trim(),
source)
.toLowerCase();
}
case itemType, itemProperty -> {
String abbreviation = IndexFields.abbreviation.getTextOrDefault(x, name);
String abbreviation = IndexFields.abbreviation.getTextOrDefault(x, name).trim();
return String.format("%s|%s|%s",
this.name(),
abbreviation,
Expand Down Expand Up @@ -197,7 +197,7 @@ public String createKey(JsonNode x) {
return String.format("%s|%s|%s|%s|%s",
this.name(),
name,
IndexFields.className.getTextOrEmpty(x),
IndexFields.className.getTextOrEmpty(x).trim(),
classSource,
scSource.equalsIgnoreCase(classSource) ? "" : scSource)
.toLowerCase();
Expand All @@ -208,9 +208,9 @@ public String createKey(JsonNode x) {
return String.format("%s|%s|%s|%s|%s|%s|%s%s",
this.name(),
name,
IndexFields.className.getTextOrEmpty(x),
IndexFields.className.getTextOrEmpty(x).trim(),
"phb".equalsIgnoreCase(classSource) ? "" : classSource,
IndexFields.subclassShortName.getTextOrEmpty(x),
IndexFields.subclassShortName.getTextOrEmpty(x).trim(),
"phb".equalsIgnoreCase(scSource) ? "" : scSource,
IndexFields.level.getTextOrEmpty(x),
source.equalsIgnoreCase(scSource) ? "" : "|" + source)
Expand All @@ -221,7 +221,7 @@ public String createKey(JsonNode x) {
return String.format("%s|%s|%s|%s%s",
this.name(),
name,
IndexFields.raceName.getTextOrThrow(x),
IndexFields.raceName.getTextOrEmpty(x).trim(),
raceSource,
source.equalsIgnoreCase(raceSource) ? "" : "|" + source)
.toLowerCase();
Expand Down Expand Up @@ -254,7 +254,7 @@ public String createKey(String name, String source) {

public String fromRawKey(String crossRef) {
if (this.equals(subclassFeature)) {
String[] parts = crossRef.split("\\|");
String[] parts = crossRef.trim().split("\s?\\|\\s?");
// 0 name,
// 1 IndexFields.className.getTextOrEmpty(x),
// 2 "phb".equalsIgnoreCase(classSource) ? "" : classSource,
Expand All @@ -267,7 +267,7 @@ public String fromRawKey(String crossRef) {
parts[5]);
}
if (this.equals(classfeature)) {
String[] parts = crossRef.split("\\|");
String[] parts = crossRef.trim().split("\s?\\|\\s?");
// 0 name,
// 1 IndexFields.className.getTextOrEmpty(x),
// 2 "phb".equalsIgnoreCase(classSource) ? "" : classSource,
Expand All @@ -277,7 +277,7 @@ public String fromRawKey(String crossRef) {
return getClassFeatureKey(parts[0], featureSource, parts[1], parts[2], parts[3]);
}
if (this.equals(card)) {
String[] parts = crossRef.split("\\|");
String[] parts = crossRef.trim().split("\s?\\|\\s?");
// 0 name,
// 1 set,
// 2 source
Expand Down