Skip to content

Commit

Permalink
🐛 Fix oddball orphan subclass; resolves #630
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Feb 3, 2025
1 parent e3b3323 commit f23b3aa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import dev.ebullient.convert.qute.ImageRef;
import dev.ebullient.convert.tools.JsonNodeReader;
import dev.ebullient.convert.tools.Tags;
import dev.ebullient.convert.tools.ToolsIndex.TtrpgValue;
import dev.ebullient.convert.tools.dnd5e.OptionalFeatureIndex.OptionalFeatureType;
import dev.ebullient.convert.tools.dnd5e.qute.QuteClass;
import dev.ebullient.convert.tools.dnd5e.qute.QuteClass.HitPointDie;
Expand Down Expand Up @@ -133,7 +134,13 @@ public List<QuteSubclass> buildSubclasses() {
List<ImageRef> images = new ArrayList<>();
List<String> text = getFluff(scNode, Tools5eIndexType.subclassFluff, "##", images);

if (scSources.isClassic() && !getSources().isClassic()) {
// A bit hacky, but the isClassic setting won't always be present for homebrew
// Homebrew based on the phb is considered classic
boolean scIsClassic = scSources.isClassic()
|| (TtrpgValue.isHomebrew.booleanOrDefault(scNode, false)
&& Tools5eFields.classSource.getTextOrDefault(scNode, "phb").equalsIgnoreCase("phb"));

if (scIsClassic && !getSources().isClassic()) {
// insert warning about mixed edition content
text.add(0,
"> This subclass is from a different game edition. You will need to do some adjustment to resolve differences.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ public static Tools5eIndex getInstance() {
return instance;
}

// classfeature|ability score improvement|monk|phb|12
static final String classFeature_1 = "classfeature\\|[^|]+\\|[^|]+\\|";
static final String classFeature_2 = "\\|\\d+\\|?";
// subclassfeature|blessed strikes|cleric|phb|death|dmg|8|uaclassfeaturevariants
static final String subclassFeature_1 = "subclassfeature\\|[^|]+\\|[^|]+\\|";
static final String subclassFeature_2 = "\\|[^|]+\\|";
static final String subclassFeature_3 = "\\|\\d+\\|?";

final CompendiumConfig config;

// Initialization
Expand Down Expand Up @@ -685,7 +677,7 @@ private boolean processDependentType(final String key) {
String classReprint = reprints.get(classKey);

tui().debugf(Msg.CLASSES, "%s\n\t(%5s) %s -> %s\n\t(%5s) %s -> %s", key,
classReprint, classKey, classReprint,
classReprint != null, classKey, classReprint,
scReprint, scKey, reprints.get(scKey));

if (classReprint != null) {
Expand All @@ -699,6 +691,8 @@ private boolean processDependentType(final String key) {

// We found the class reprint.
// The reprinted class is the new resource anchor for generated notes
classKey = classReprint;

// Change the class source for the subclass feature
keyData.classSource = altSources.primarySource();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.jupiter.api.AfterAll;
Expand All @@ -12,6 +13,7 @@

import dev.ebullient.convert.TestUtils;
import dev.ebullient.convert.tools.dnd5e.CommonDataTests.TestInput;
import dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteBase;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
Expand Down Expand Up @@ -340,11 +342,50 @@ public void testKeyIndex() throws Exception {
commonTests.assert_MISSING("subrace|tiefling (zariel)|tiefling|phb|mtf");
commonTests.assert_MISSING("subrace|tiefling|tiefling|phb|phb");
commonTests.assert_MISSING("subrace|vampire (ixalan)|vampire|psz|psx");

// specific for this combination of features (homebrew)
var dirgeSinger = "subclass|college of the dirge singer|bard|phb|exploringeberron";
commonTests.assert_Present(dirgeSinger);

// homebrew subclass should be moved to xphb class version (as xphb is present)

// the phb version of the subclass should not be present in this configuration
var subclasses = commonTests.index.findSubclasses("classtype|bard|phb");
assertThat(subclasses).isNotNull();
assertThat(subclasses).isEmpty();

// the xphb version should be present
subclasses = commonTests.index.findSubclasses("classtype|bard|xphb");
assertThat(subclasses).isNotNull();
assertThat(subclasses).isNotEmpty();
assertThat(subclasses).contains(dirgeSinger);

// dirge singer should have features
var features = commonTests.index.findClassFeatures(dirgeSinger);
assertThat(features).isNotNull();
assertThat(features).isNotEmpty();
}
}

@Test
public void testClassList() {
public void testClassList() throws IOException {
if (!commonTests.dataPresent) {
return;
}

commonTests.testClassList(outputPath);

String filename = Tools5eQuteBase.getSubclassResource(
"college of the dirge singer", "bard", "xphb", "exploringeberron")
+ ".md";

Path dirgeSinger = outputPath
.resolve(commonTests.index.compendiumFilePath())
.resolve(Tools5eIndexType.classtype.getRelativePath())
.resolve(filename);
assertThat(dirgeSinger).exists();

String content = Files.readString(dirgeSinger);
assertThat(content).contains("Mixed edition content");
}
}

0 comments on commit f23b3aa

Please sign in to comment.