Skip to content

Commit

Permalink
🎨💥 Use Pf2eStat for creature skill bonuses
Browse files Browse the repository at this point in the history
Avoids a small amount of repetition and keeps the interface consistent
  • Loading branch information
miscoined authored and ebullient committed May 13, 2024
1 parent a11fa92 commit d88787f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -19,30 +17,33 @@
* </p>
*
* @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<String, Integer> otherBonuses,
String note) implements QuteUtil {
List<String> 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.<String> 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();
}
}

0 comments on commit d88787f

Please sign in to comment.