Skip to content

Commit 92d8402

Browse files
jboehm77ebullient
authored andcommitted
♻️ Create common static method to map feature type to full text
1 parent da7dd8c commit 92d8402

4 files changed

Lines changed: 70 additions & 70 deletions

File tree

src/main/java/dev/ebullient/convert/tools/dnd5e/Json2QuteFeat.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dev.ebullient.convert.tools.dnd5e;
22

3-
import static dev.ebullient.convert.StringUtil.isPresent;
4-
53
import java.util.ArrayList;
64
import java.util.List;
75

@@ -27,6 +25,13 @@ protected Tools5eQuteBase buildQuteResource() {
2725

2826
List<ImageRef> images = getFluffImages(Tools5eIndexType.featFluff);
2927

28+
String category = featureTypeToFull(FeatFields.category.getTextOrEmpty(rootNode));
29+
if (category.equalsIgnoreCase("Fighting Style, Paladin")) {
30+
category = "Fighting Style Replacement (Paladin)";
31+
} else if (category.equalsIgnoreCase("Fighting Style, Ranger")) {
32+
category = "Fighting Style Replacement (Ranger)";
33+
}
34+
3035
// Initialize full entries with ability score increases merged
3136
JsonNode fullEntries = initFullEntries();
3237

@@ -41,7 +46,7 @@ protected Tools5eQuteBase buildQuteResource() {
4146
listPrerequisites(rootNode),
4247
null, // Level coming someday..
4348
SkillOrAbility.getAbilityScoreIncreases(FeatFields.ability.getFrom(rootNode)),
44-
categoryToFull(FeatFields.category.getTextOrEmpty(rootNode)),
49+
category,
4550
images,
4651
String.join("\n", text),
4752
tags);
@@ -119,20 +124,6 @@ JsonNode entryToListItemItem(JsonNode abilityNode) {
119124
.put("name", "Ability Score Increase")
120125
.put("entry", SkillOrAbility.getAbilityScoreIncrease(abilityNode));
121126
}
122-
protected String categoryToFull(String category) {
123-
if (!isPresent(category)) {
124-
return "";
125-
}
126-
return switch (category.toUpperCase()) {
127-
case "EB" -> "Epic Boon Feat";
128-
case "FS" -> "Fighting Style Feat";
129-
case "FS:P" -> "Fighting Style Replacement (Paladin)";
130-
case "FS:R" -> "Fighting Style Replacement (Ranger)";
131-
case "G" -> "General Feat";
132-
case "O" -> "Origin Feat";
133-
default -> category;
134-
};
135-
};
136127

137128
enum FeatFields implements JsonNodeReader {
138129
ability,
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dev.ebullient.convert.tools.dnd5e;
22

3-
import static dev.ebullient.convert.StringUtil.isPresent;
4-
53
import java.util.ArrayList;
64
import java.util.List;
75

@@ -25,6 +23,15 @@ protected Tools5eQuteBase buildQuteResource() {
2523
tags.add("optional-feature", featureType);
2624
}
2725

26+
String featureTypeFull = featureTypeToFull(typeList.get(0));
27+
if (featureTypeFull.startsWith("Fighting Style")) {
28+
featureTypeFull = "Fighting Style"; //trim class name, fighting styles can be for multiple classes
29+
} else if (featureTypeFull.equalsIgnoreCase("Maneuver, Battle Master")) {
30+
featureTypeFull = "Battle Master Maneuver";
31+
} else if (featureTypeFull.equalsIgnoreCase("Maneuver, Cavalier V2 (UA)")) {
32+
featureTypeFull = "Cavalier Maneuver, V2 (UA)";
33+
}
34+
2835
List<ImageRef> images = new ArrayList<>();
2936
List<String> text = getFluff(Tools5eIndexType.optionalfeatureFluff, "##", images);
3037
appendToText(text, SourceField.entries.getFrom(rootNode), "##");
@@ -35,27 +42,9 @@ protected Tools5eQuteBase buildQuteResource() {
3542
listPrerequisites(rootNode),
3643
null,
3744
null,
38-
featureTypeToFull(typeList.get(0)),
45+
featureTypeFull,
3946
images,
4047
String.join("\n", text),
4148
tags);
4249
}
43-
44-
protected String featureTypeToFull(String featureType) {
45-
if (!isPresent(featureType)) {
46-
return "";
47-
}
48-
return switch (featureType.toUpperCase()) {
49-
case "AI" -> "Artificer Infusion";
50-
case "AS" -> "Arcane Shot";
51-
case "ED" -> "Elemental Discipline";
52-
case "EI" -> "Eldritch Invocation";
53-
case "FS:B", "FS:F", "FS:P", "FS:R" -> "Fighting Style";
54-
case "MM" -> "Metamagic";
55-
case "MV:B" -> "Battle Master Maneuver";
56-
case "PB" -> "Pact Boon";
57-
case "RN" -> "Rune Knight Rune";
58-
default -> featureType;
59-
};
60-
};
6150
}

src/main/java/dev/ebullient/convert/tools/dnd5e/JsonSource.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,46 @@ default String convertCurrency(int cp) {
12991299
return String.join(", ", result);
13001300
}
13011301

1302+
default String featureTypeToFull(String featureType) {
1303+
return featureTypeToString(featureType);
1304+
}
1305+
1306+
public static String featureTypeToString(String featureType) {
1307+
if (!isPresent(featureType)) {
1308+
return "";
1309+
}
1310+
return switch (featureType.toUpperCase()) {
1311+
case "EB" -> "Epic Boon Feat";
1312+
case "FS" -> "Fighting Style Feat";
1313+
case "G" -> "General Feat";
1314+
case "O" -> "Origin Feat";
1315+
case "AI" -> "Artificer Infusion";
1316+
case "ED" -> "Elemental Discipline";
1317+
case "EI" -> "Eldritch Invocation";
1318+
case "MM" -> "Metamagic";
1319+
case "MV" -> "Maneuver";
1320+
case "MV:B" -> "Maneuver, Battle Master";
1321+
case "MV:C2-UA" -> "Maneuver, Cavalier V2 (UA)";
1322+
case "AS:V1-UA" -> "Arcane Shot, V1 (UA)";
1323+
case "AS:V2-UA" -> "Arcane Shot, V2 (UA)";
1324+
case "AS" -> "Arcane Shot";
1325+
case "OTH" -> "Other";
1326+
case "FS:F" -> "Fighting Style, Fighter";
1327+
case "FS:B" -> "Fighting Style, Bard";
1328+
case "FS:P" -> "Fighting Style, Paladin";
1329+
case "FS:R" -> "Fighting Style, Ranger";
1330+
case "PB" -> "Pact Boon";
1331+
case "OR" -> "Onomancy Resonant";
1332+
case "RN" -> "Rune Knight Rune";
1333+
case "AF" -> "Alchemical Formula";
1334+
case "TT" -> "Traveler's Trick";
1335+
case "BC" -> "Blood Curse";
1336+
case "CR" -> "Crimson Rite";
1337+
case "MTGN" -> "Mutagen";
1338+
default -> featureType;
1339+
};
1340+
};
1341+
13021342
public static String spellLevelToText(String level) {
13031343
return switch (level) {
13041344
case "0", "c" -> "cantrip";

src/main/java/dev/ebullient/convert/tools/dnd5e/OptionalFeatureIndex.java

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -268,39 +268,19 @@ public boolean testFeaturesInUse(Function<String, Boolean> test) {
268268
}
269269

270270
public String getTitle() {
271-
return switch (abbreviation) {
272-
case "AI" -> "Artificer Infusion";
273-
case "ED" -> "Elemental Discipline";
274-
case "EI" -> "Eldritch Invocation";
275-
case "MM" -> "Metamagic";
276-
case "MV" -> "Maneuver";
277-
case "MV:B" -> "Maneuver, Battle Master";
278-
case "MV:C2-UA" -> "Maneuver, Cavalier V2 (UA)";
279-
case "AS:V1-UA" -> "Arcane Shot, V1 (UA)";
280-
case "AS:V2-UA" -> "Arcane Shot, V2 (UA)";
281-
case "AS" -> "Arcane Shot";
282-
case "OTH" -> "Other";
283-
case "FS:F" -> "Fighting Style, Fighter";
284-
case "FS:B" -> "Fighting Style, Bard";
285-
case "FS:P" -> "Fighting Style, Paladin";
286-
case "FS:R" -> "Fighting Style, Ranger";
287-
case "PB" -> "Pact Boon";
288-
case "OR" -> "Onomancy Resonant";
289-
case "RN" -> "Rune Knight Rune";
290-
case "AF" -> "Alchemical Formula";
291-
case "TT" -> "Traveler's Trick";
292-
default -> {
293-
if (!homebrewMeta.isEmpty()) {
294-
yield homebrewMeta.values().stream()
295-
.map(hb -> hb.getOptionalFeatureType(abbreviation))
296-
.distinct()
297-
.collect(Collectors.joining("; "));
298-
}
299-
Tui.instance().warnf(Msg.NOT_SET, "Missing title for OptionalFeatureType in %s",
300-
abbreviation);
301-
yield abbreviation;
271+
String title = JsonSource.featureTypeToString(abbreviation);
272+
if (title.equalsIgnoreCase(abbreviation)) {
273+
if (!homebrewMeta.isEmpty()) {
274+
return homebrewMeta.values().stream()
275+
.map(hb -> hb.getOptionalFeatureType(abbreviation))
276+
.distinct()
277+
.collect(Collectors.joining("; "));
302278
}
303-
};
279+
Tui.instance().warnf(Msg.NOT_SET, "Missing title for OptionalFeatureType in %s",
280+
abbreviation);
281+
return abbreviation;
282+
}
283+
return title;
304284
}
305285

306286
private String getSource(HomebrewMetaTypes homebrewMeta) {

0 commit comments

Comments
 (0)