From 9dbe2339c91b6146251ad16388166b0effb3753a Mon Sep 17 00:00:00 2001 From: Erin Schnabel Date: Thu, 12 Dec 2024 19:01:43 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20resolve=20magic/monster=20varian?= =?UTF-8?q?ts=20before=20reprints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/tools/dnd5e/Tools5eIndex.java | 43 ++++++++++--------- src/main/resources/convertData.json | 1 + 2 files changed, 23 insertions(+), 21 deletions(-) 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 cd6128757..41c8dbf5c 100644 --- a/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eIndex.java +++ b/src/main/java/dev/ebullient/convert/tools/dnd5e/Tools5eIndex.java @@ -301,6 +301,14 @@ public void prepare() { tui().progressf("Resolving copies and link sources"); + // Find remaining/included base items + List baseItems = nodeIndex.values().stream() + .filter(n -> TtrpgValue.indexBaseItem.booleanOrDefault(n, false)) + .filter(n -> !ItemField.packContents.existsIn(n)) + .toList(); + + Map variants = new HashMap<>(); + // For each node: handle copies, link sources for (Entry entry : nodeIndex.entrySet()) { String key = entry.getKey(); @@ -344,8 +352,20 @@ public void prepare() { default -> { } } + + // Reprints do follow specialized variants, so we need to find the variants + // now (and will filter them out based on rules later...) + if (type.hasVariants()) { + List variantList = findVariants(key, jsonSource, baseItems); + for (Tuple variant : variantList) { + variants.put(variant.key, variant.node); + } + } } // end for each entry + nodeIndex.putAll(variants); + variants.clear(); + filteredIndex = new HashMap<>(nodeIndex.size()); tui().progressf("Applying source filters"); @@ -362,7 +382,8 @@ public void prepare() { for (var e : nodeIndex.entrySet()) { String key = e.getKey(); Tools5eIndexType type = Tools5eIndexType.getTypeFromKey(key); - Tools5eSources sources = Tools5eSources.findSources(key); + // construct source if missing (which it may be for a variant) + Tools5eSources sources = Tools5eSources.constructSources(key, e.getValue()); Msg msgType = sources.filterRuleApplied() ? Msg.TARGET : Msg.FILTER; if (type.isFluffType()) { @@ -387,26 +408,6 @@ public void prepare() { tui().progressf("Removing dependent and dangling resources"); filteredIndex.keySet().removeIf(k -> otherwiseExcluded(k)); - // After we've removed reprints and otherwise excluded items, - // let's generate variants for monsters and magic items - - tui().progressf("Populating variants"); - - // Find remaining/included base items - List baseItems = filteredIndex.values().stream() - .filter(n -> TtrpgValue.indexBaseItem.booleanOrDefault(n, false)) - .filter(n -> !ItemField.packContents.existsIn(n)) - .toList(); - - // Find variant nodes (magic items, monsters) - List variantNodes = filteredIndex.entrySet().stream() - .filter(e -> Tools5eIndexType.getTypeFromKey(e.getKey()).hasVariants()) - .flatMap(e -> findVariants(e.getKey(), e.getValue(), baseItems).stream()) - .toList(); - - // Add the variants back into the index, which may replace the original - variantNodes.forEach(t -> filteredIndex.put(t.key, t.node)); - // Deities have their own glorious reprint mess, which we only need to deal with // when we aren't hoarding all the things. if (config.reprintBehavior() != ReprintBehavior.all) { diff --git a/src/main/resources/convertData.json b/src/main/resources/convertData.json index eada461ba..fb68a2841 100644 --- a/src/main/resources/convertData.json +++ b/src/main/resources/convertData.json @@ -580,6 +580,7 @@ "item|shield, +1|dmg": "item|+1 shield|dmg", "item|thieves tools|phb": "item|thieves' tools|phb", "item|wands of magic missiles|dmg": "item|wand of magic missiles|dmg", + "itemgroup|spell scroll|xphb": "itemgroup|spell scroll|xdmg", "spell|acid arrow|phb": "spell|melf's acid arrow|phb", "spell|bane spell|phb": "spell|bane|phb", "spell|ceremony|phb": "spell|ceremony|xge",