Include traits on PF2e ability blocks

Parse and display traits (concentrate, divine, polymorph, etc.)
on ability entries, matching how attack traits are already shown.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-04-07 16:29:08 +02:00
parent 3e62e54274
commit f9cfaa2570
2 changed files with 82 additions and 3 deletions

View File

@@ -46,6 +46,7 @@ interface RawDefenses {
interface RawAbility {
name?: string;
traits?: string[];
entries?: RawEntry[];
}
@@ -244,11 +245,27 @@ function normalizeAbilities(
.filter((a) => a.name)
.map((a) => {
const raw = a as Record<string, unknown>;
const traits =
a.traits && a.traits.length > 0
? `(${a.traits.map((t) => capitalize(stripAngleBrackets(stripTags(t)))).join(", ")}) `
: "";
const body = Array.isArray(a.entries)
? segmentizeEntries(a.entries)
: formatAffliction(raw);
if (traits && body.length > 0 && body[0].type === "text") {
return {
name: stripTags(a.name as string),
segments: [
{ type: "text" as const, value: traits + body[0].value },
...body.slice(1),
],
};
}
return {
name: stripTags(a.name as string),
segments: Array.isArray(a.entries)
? segmentizeEntries(a.entries)
: formatAffliction(raw),
segments: traits
? [{ type: "text" as const, value: traits }, ...body]
: body,
};
});
}