@@ -301,6 +301,14 @@ public void prepare() {
301301
302302 tui ().progressf ("Resolving copies and link sources" );
303303
304+ // Find remaining/included base items
305+ List <JsonNode > baseItems = nodeIndex .values ().stream ()
306+ .filter (n -> TtrpgValue .indexBaseItem .booleanOrDefault (n , false ))
307+ .filter (n -> !ItemField .packContents .existsIn (n ))
308+ .toList ();
309+
310+ Map <String , JsonNode > variants = new HashMap <>();
311+
304312 // For each node: handle copies, link sources
305313 for (Entry <String , JsonNode > entry : nodeIndex .entrySet ()) {
306314 String key = entry .getKey ();
@@ -344,8 +352,20 @@ public void prepare() {
344352 default -> {
345353 }
346354 }
355+
356+ // Reprints do follow specialized variants, so we need to find the variants
357+ // now (and will filter them out based on rules later...)
358+ if (type .hasVariants ()) {
359+ List <Tuple > variantList = findVariants (key , jsonSource , baseItems );
360+ for (Tuple variant : variantList ) {
361+ variants .put (variant .key , variant .node );
362+ }
363+ }
347364 } // end for each entry
348365
366+ nodeIndex .putAll (variants );
367+ variants .clear ();
368+
349369 filteredIndex = new HashMap <>(nodeIndex .size ());
350370
351371 tui ().progressf ("Applying source filters" );
@@ -362,7 +382,8 @@ public void prepare() {
362382 for (var e : nodeIndex .entrySet ()) {
363383 String key = e .getKey ();
364384 Tools5eIndexType type = Tools5eIndexType .getTypeFromKey (key );
365- Tools5eSources sources = Tools5eSources .findSources (key );
385+ // construct source if missing (which it may be for a variant)
386+ Tools5eSources sources = Tools5eSources .constructSources (key , e .getValue ());
366387 Msg msgType = sources .filterRuleApplied () ? Msg .TARGET : Msg .FILTER ;
367388
368389 if (type .isFluffType ()) {
@@ -387,26 +408,6 @@ public void prepare() {
387408 tui ().progressf ("Removing dependent and dangling resources" );
388409 filteredIndex .keySet ().removeIf (k -> otherwiseExcluded (k ));
389410
390- // After we've removed reprints and otherwise excluded items,
391- // let's generate variants for monsters and magic items
392-
393- tui ().progressf ("Populating variants" );
394-
395- // Find remaining/included base items
396- List <JsonNode > baseItems = filteredIndex .values ().stream ()
397- .filter (n -> TtrpgValue .indexBaseItem .booleanOrDefault (n , false ))
398- .filter (n -> !ItemField .packContents .existsIn (n ))
399- .toList ();
400-
401- // Find variant nodes (magic items, monsters)
402- List <Tuple > variantNodes = filteredIndex .entrySet ().stream ()
403- .filter (e -> Tools5eIndexType .getTypeFromKey (e .getKey ()).hasVariants ())
404- .flatMap (e -> findVariants (e .getKey (), e .getValue (), baseItems ).stream ())
405- .toList ();
406-
407- // Add the variants back into the index, which may replace the original
408- variantNodes .forEach (t -> filteredIndex .put (t .key , t .node ));
409-
410411 // Deities have their own glorious reprint mess, which we only need to deal with
411412 // when we aren't hoarding all the things.
412413 if (config .reprintBehavior () != ReprintBehavior .all ) {
0 commit comments