Skip to content

Commit

Permalink
♻️ Move Pf2eWeaponData to Json2QuteItem
Browse files Browse the repository at this point in the history
  • Loading branch information
miscoined authored and ebullient committed Jun 2, 2024
1 parent 4577133 commit c9c9e17
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ private QuteInlineAttack buildAvatarAttack(JsonNode actionNode, Tags tags, Attac
Pf2eAttack.name.getTextOrDefault(actionNode, "attack"),
Pf2eActivity.single.toQuteActivity(this, null),
rangeType,
Pf2eWeaponData.getDamageString(actionNode, this),
Stream.of(Pf2eWeaponData.damageType, Pf2eWeaponData.damageType2)
Json2QuteItem.Pf2eWeaponData.getDamageString(actionNode, this),
Stream.of(Json2QuteItem.Pf2eWeaponData.damageType, Json2QuteItem.Pf2eWeaponData.damageType2)
.map(field -> field.getTextOrEmpty(actionNode))
.filter(StringUtil::isPresent)
.toList(),
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/dev/ebullient/convert/tools/pf2e/Json2QuteItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.fasterxml.jackson.databind.JsonNode;

import dev.ebullient.convert.qute.NamedText;
import dev.ebullient.convert.tools.JsonNodeReader;
import dev.ebullient.convert.tools.Tags;
import dev.ebullient.convert.tools.pf2e.qute.Pf2eQuteBase;
import dev.ebullient.convert.tools.pf2e.qute.QuteDataArmorClass;
Expand Down Expand Up @@ -310,4 +311,89 @@ enum Pf2eItemVariant implements Pf2eJsonNodeReader {
variantType,
craftReq
}

public enum Pf2eWeaponData implements Pf2eJsonNodeReader {
ammunition,
damage,
damageType,
damage2,
damageType2,
group,
range,
reload;

public static QuteItemWeaponData buildWeaponData(JsonNode source,
Pf2eTypeReader convert, Tags tags) {

QuteItemWeaponData weaponData = new QuteItemWeaponData();
weaponData.traits = convert.collectTraitsFrom(source, tags);
weaponData.type = SourceField.type.getTextOrEmpty(source);
weaponData.damage = getDamageString(source, convert);

weaponData.ranged = new ArrayList<>();
String ammunition = Pf2eWeaponData.ammunition.getTextOrNull(source);
if (ammunition != null) {
weaponData.ranged.add(new NamedText("Ammunution", convert.linkify(Pf2eIndexType.item, ammunition)));
}
String range = Pf2eWeaponData.range.getTextOrNull(source);
if (range != null) {
weaponData.ranged.add(new NamedText("Range", range + " ft."));
}
String reload = Pf2eWeaponData.reload.getTextOrNull(source);
if (reload != null) {
weaponData.ranged.add(new NamedText("Reload", convert.replaceText(reload)));
}

String group = Pf2eWeaponData.group.getTextOrNull(source);
if (group != null) {
weaponData.group = convert.linkify(Pf2eIndexType.group, group);
}

return weaponData;
}

public static String getDamageString(JsonNode source, Pf2eTypeReader convert) {
String damage = Pf2eWeaponData.damage.getTextOrNull(source);
String damage2 = Pf2eWeaponData.damage2.getTextOrNull(source);

String result = "";
if (damage != null) {
result += convert.replaceText("{@damage %s} %s".formatted(
damage,
Pf2eWeaponData.damageType.getTextOrEmpty(source)));
}
if (damage2 != null) {
result += convert.replaceText("%s{@damage %s} %s".formatted(
damage == null ? "" : " and ",
damage2,
Pf2eWeaponData.damageType2.getTextOrEmpty(source)));
}
return result;
}

static String getDamageType(JsonNodeReader damageType, JsonNode source) {
String value = damageType.getTextOrEmpty(source);
return switch (value) {
case "A" -> "acid";
case "B" -> "bludgeoning";
case "C" -> "cold";
case "D" -> "bleed";
case "E" -> "electricity";
case "F" -> "fire";
case "H" -> "chaotic";
case "I" -> "poison";
case "L" -> "lawful";
case "M" -> "mental";
case "Mod" -> "modular";
case "N" -> "sonic";
case "O" -> "force";
case "P" -> "piercing";
case "R" -> "precision";
case "S" -> "slashing";
case "+" -> "positive";
case "-" -> "negative";
default -> value;
};
}
}
}
90 changes: 0 additions & 90 deletions src/main/java/dev/ebullient/convert/tools/pf2e/Pf2eTypeReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
import static dev.ebullient.convert.StringUtil.isPresent;
import static dev.ebullient.convert.StringUtil.pluralize;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

import com.fasterxml.jackson.databind.JsonNode;

import dev.ebullient.convert.io.Tui;
import dev.ebullient.convert.qute.NamedText;
import dev.ebullient.convert.tools.JsonNodeReader;
import dev.ebullient.convert.tools.Tags;
import dev.ebullient.convert.tools.pf2e.qute.QuteItem.QuteItemWeaponData;
import io.quarkus.runtime.annotations.RegisterForReflection;

public interface Pf2eTypeReader extends JsonSource {
Expand Down Expand Up @@ -55,91 +50,6 @@ public static Pf2eAlignmentValue fromString(String name) {
}
}

enum Pf2eWeaponData implements Pf2eJsonNodeReader {
ammunition,
damage,
damageType,
damage2,
damageType2,
group,
range,
reload;

public static QuteItemWeaponData buildWeaponData(JsonNode source,
Pf2eTypeReader convert, Tags tags) {

QuteItemWeaponData weaponData = new QuteItemWeaponData();
weaponData.traits = convert.collectTraitsFrom(source, tags);
weaponData.type = SourceField.type.getTextOrEmpty(source);
weaponData.damage = getDamageString(source, convert);

weaponData.ranged = new ArrayList<>();
String ammunition = Pf2eWeaponData.ammunition.getTextOrNull(source);
if (ammunition != null) {
weaponData.ranged.add(new NamedText("Ammunution", convert.linkify(Pf2eIndexType.item, ammunition)));
}
String range = Pf2eWeaponData.range.getTextOrNull(source);
if (range != null) {
weaponData.ranged.add(new NamedText("Range", range + " ft."));
}
String reload = Pf2eWeaponData.reload.getTextOrNull(source);
if (reload != null) {
weaponData.ranged.add(new NamedText("Reload", convert.replaceText(reload)));
}

String group = Pf2eWeaponData.group.getTextOrNull(source);
if (group != null) {
weaponData.group = convert.linkify(Pf2eIndexType.group, group);
}

return weaponData;
}

public static String getDamageString(JsonNode source, Pf2eTypeReader convert) {
String damage = Pf2eWeaponData.damage.getTextOrNull(source);
String damage2 = Pf2eWeaponData.damage2.getTextOrNull(source);

String result = "";
if (damage != null) {
result += convert.replaceText("{@damage %s} %s".formatted(
damage,
Pf2eWeaponData.damageType.getTextOrEmpty(source)));
}
if (damage2 != null) {
result += convert.replaceText("%s{@damage %s} %s".formatted(
damage == null ? "" : " and ",
damage2,
Pf2eWeaponData.damageType2.getTextOrEmpty(source)));
}
return result;
}

static String getDamageType(JsonNodeReader damageType, JsonNode source) {
String value = damageType.getTextOrEmpty(source);
return switch (value) {
case "A" -> "acid";
case "B" -> "bludgeoning";
case "C" -> "cold";
case "D" -> "bleed";
case "E" -> "electricity";
case "F" -> "fire";
case "H" -> "chaotic";
case "I" -> "poison";
case "L" -> "lawful";
case "M" -> "mental";
case "Mod" -> "modular";
case "N" -> "sonic";
case "O" -> "force";
case "P" -> "piercing";
case "R" -> "precision";
case "S" -> "slashing";
case "+" -> "positive";
case "-" -> "negative";
default -> value;
};
}
}

enum Pf2eSpell implements Pf2eJsonNodeReader {
amp,
area,
Expand Down

0 comments on commit c9c9e17

Please sign in to comment.