From d88787ff79bc9c483365c7c079ace52d0e8121ff Mon Sep 17 00:00:00 2001
From: miscoined
Date: Fri, 10 May 2024 02:09:39 +1000
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=F0=9F=92=A5=20Use=20Pf2eStat=20for?=
=?UTF-8?q?=20creature=20skill=20bonuses?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Avoids a small amount of repetition and keeps the interface consistent
---
.../convert/tools/pf2e/Pf2eTypeReader.java | 4 ++-
.../tools/pf2e/qute/QuteDataSkillBonus.java | 31 ++++++++++---------
2 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/src/main/java/dev/ebullient/convert/tools/pf2e/Pf2eTypeReader.java b/src/main/java/dev/ebullient/convert/tools/pf2e/Pf2eTypeReader.java
index fbe34704..65fa61da 100644
--- a/src/main/java/dev/ebullient/convert/tools/pf2e/Pf2eTypeReader.java
+++ b/src/main/java/dev/ebullient/convert/tools/pf2e/Pf2eTypeReader.java
@@ -541,7 +541,9 @@ public static QuteDataSkillBonus createSkillBonus(
.collect(
Collectors.toUnmodifiableMap(
e -> convert.replaceText(e.getKey()), e -> e.getValue().asInt())),
- convert.replaceText(note.getTextOrNull(source)));
+ Optional.ofNullable(note.getTextOrNull(source))
+ .map(s -> List.of(convert.replaceText(s)))
+ .orElse(List.of()));
}
}
diff --git a/src/main/java/dev/ebullient/convert/tools/pf2e/qute/QuteDataSkillBonus.java b/src/main/java/dev/ebullient/convert/tools/pf2e/qute/QuteDataSkillBonus.java
index 35efb4c2..565def62 100644
--- a/src/main/java/dev/ebullient/convert/tools/pf2e/qute/QuteDataSkillBonus.java
+++ b/src/main/java/dev/ebullient/convert/tools/pf2e/qute/QuteDataSkillBonus.java
@@ -1,13 +1,11 @@
package dev.ebullient.convert.tools.pf2e.qute;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import dev.ebullient.convert.qute.QuteUtil;
+import dev.ebullient.convert.tools.pf2e.Pf2eTypeReader;
import io.quarkus.qute.TemplateData;
/**
@@ -19,30 +17,33 @@
*
*
* @param name The name of the skill
- * @param standardBonus The standard bonus associated with this skill
+ * @param value The standard bonus associated with this skill
* @param otherBonuses Any additional bonuses, as a map of descriptions to bonuses. Iterate over all map entries to
* display the values: {@code {#each resource.skills.otherBonuses}{it.key}: {it.value}{/each}}
- * @param note Any note associated with this skill bonus
+ * @param notes Any notes associated with this skill bonus
*/
@TemplateData
public record QuteDataSkillBonus(
String name,
- Integer standardBonus,
+ Integer value,
Map otherBonuses,
- String note) implements QuteUtil {
+ List notes) implements Pf2eTypeReader.Pf2eStat {
public QuteDataSkillBonus(String name, Integer standardBonus) {
- this(name, standardBonus, null, null);
+ this(name, standardBonus, Map.of(), List.of());
}
+ /** Return the standard bonus and any other conditional bonuses. */
@Override
- public String toString() {
- return Stream.of(
- List.of(String.format("%s %+d", name, standardBonus)),
- otherBonuses.entrySet().stream().map(e -> String.format("(%+d %s)", e.getValue(), e.getKey())).toList(),
- note == null ? List. of() : List.of("(" + note + ")"))
- .flatMap(Collection::stream)
- .filter(Objects::nonNull)
+ public String bonus() {
+ return Stream.concat(
+ Stream.of(Pf2eTypeReader.Pf2eStat.super.bonus()),
+ otherBonuses.entrySet().stream().map(e -> String.format("(%+d %s)", e.getValue(), e.getKey())))
.collect(Collectors.joining(" "));
}
+
+ @Override
+ public String toString() {
+ return String.join(" ", name, bonus(), formattedNotes()).trim();
+ }
}