Skip to content

Commit

Permalink
🐛 Fix missing source text; magic variant fluff images
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Dec 12, 2024
1 parent 18f256c commit cbc6644
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/dev/ebullient/convert/tools/ToolsIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ enum TtrpgValue implements JsonNodeReader {
indexKey,
indexInputType,
indexBaseItem,
isHomebrew;
isHomebrew,
indexFluffKey,
}

static ToolsIndex createIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import dev.ebullient.convert.qute.ImageRef;
import dev.ebullient.convert.qute.NamedText;
import dev.ebullient.convert.tools.JsonNodeReader;
import dev.ebullient.convert.tools.ToolsIndex.TtrpgValue;
import dev.ebullient.convert.tools.dnd5e.Json2QuteMonster.MonsterFields;
import dev.ebullient.convert.tools.dnd5e.qute.AbilityScores;
import dev.ebullient.convert.tools.dnd5e.qute.AcHp;
Expand Down Expand Up @@ -101,7 +102,11 @@ public String getFluffDescription(Tools5eIndexType fluffType, String heading, Li
public List<String> getFluff(Tools5eIndexType fluffType, String heading, List<ImageRef> images) {
List<String> text = new ArrayList<>();
JsonNode fluffNode = null;
if (Tools5eFields.fluff.existsIn(rootNode)) {
if (TtrpgValue.indexFluffKey.existsIn(rootNode)) {
// Specific variant
String fluffKey = TtrpgValue.indexFluffKey.getTextOrEmpty(rootNode);
fluffNode = index.getOrigin(fluffKey);
} else if (Tools5eFields.fluff.existsIn(rootNode)) {
fluffNode = Tools5eFields.fluff.getFrom(rootNode);
JsonNode monsterFluff = Tools5eFields._monsterFluff.getFrom(fluffNode);
if (monsterFluff != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ private List<Tuple> findVariants(Tools5eIndex index, Tools5eIndexType type,
index.addAlias(key, gvKey);
}

String fluffKey = ItemField.hasFluff.booleanOrDefault(genericVariant, false)
|| ItemField.hasFluffImages.booleanOrDefault(genericVariant, false)
? Tools5eIndexType.itemFluff.createKey(genericVariant)
: null;

for (JsonNode baseItem : baseItems) {
if (ItemField.packContents.existsIn(baseItem)
|| !editionMatch(baseItem, genericVariant)
Expand All @@ -152,6 +157,9 @@ private List<Tuple> findVariants(Tools5eIndex index, Tools5eIndexType type,
String newKey = Tools5eIndexType.item.createKey(specficVariant);
TtrpgValue.indexInputType.setIn(specficVariant, Tools5eIndexType.item.name());
TtrpgValue.indexKey.setIn(specficVariant, newKey);
if (fluffKey != null) {
TtrpgValue.indexFluffKey.setIn(specficVariant, fluffKey);
}
Tools5eSources.constructSources(newKey, specficVariant);
if (spawnNewItems) {
variants.add(new Tuple(newKey, specficVariant));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,10 @@ public JsonNode getOrigin(String finalKey) {
}
}
}
if (result == null) {
tui().debugf(Msg.UNRESOLVED, "No element found for %s",
finalKey);
}
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dev.ebullient.convert.config.CompendiumConfig;
import dev.ebullient.convert.config.TtrpgConfig;
import dev.ebullient.convert.io.FontRef;
import dev.ebullient.convert.io.Msg;
import dev.ebullient.convert.io.Tui;
import dev.ebullient.convert.qute.ImageRef;
import dev.ebullient.convert.qute.QuteBase;
Expand Down Expand Up @@ -289,11 +290,15 @@ public String getSourceText(boolean useSrd) {
}
return String.join(" and ", bits);
}
return sourceText;
return super.getSourceText();
}

public JsonNode findNode() {
return Tools5eIndex.getInstance().getOrigin(this.key);
JsonNode result = Tools5eIndex.getInstance().getNode(key);
if (result == null) {
result = Tools5eIndex.getInstance().getOrigin(this.key);
}
return result;
}

protected String findName(IndexType type, JsonNode jsonElement) {
Expand All @@ -311,6 +316,13 @@ protected String findSourceText(IndexType type, JsonNode jsonElement) {
if (type == Tools5eIndexType.syntheticGroup) {
return this.key.replaceAll(".*\\|([^|]+)\\|", "$1");
}
if (type == Tools5eIndexType.reference) {
return "";
}
if (jsonElement == null) {
Tui.instance().logf(Msg.UNRESOLVED, "Resource %s has no jsonElement", this.key);
return "";
}
String srcText = super.findSourceText(type, jsonElement);

JsonNode basicRules = jsonElement.get("basicRules");
Expand Down

0 comments on commit cbc6644

Please sign in to comment.