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:
@@ -170,6 +170,68 @@ describe("normalizePf2eBestiary", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("ability traits formatting", () => {
|
||||||
|
it("includes traits from abilities in the text", () => {
|
||||||
|
const [creature] = normalizePf2eBestiary({
|
||||||
|
creature: [
|
||||||
|
minimalCreature({
|
||||||
|
abilities: {
|
||||||
|
bot: [
|
||||||
|
{
|
||||||
|
name: "Change Shape",
|
||||||
|
traits: [
|
||||||
|
"concentrate",
|
||||||
|
"divine",
|
||||||
|
"polymorph",
|
||||||
|
"transmutation",
|
||||||
|
],
|
||||||
|
entries: [
|
||||||
|
"The naunet can take the appearance of any creature.",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const ability = creature.abilitiesBot?.[0];
|
||||||
|
expect(ability).toBeDefined();
|
||||||
|
expect(ability?.segments[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: "text",
|
||||||
|
value: expect.stringContaining(
|
||||||
|
"(Concentrate, Divine, Polymorph, Transmutation)",
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders ability without traits normally", () => {
|
||||||
|
const [creature] = normalizePf2eBestiary({
|
||||||
|
creature: [
|
||||||
|
minimalCreature({
|
||||||
|
abilities: {
|
||||||
|
bot: [
|
||||||
|
{
|
||||||
|
name: "Constrict",
|
||||||
|
entries: ["1d8+8 bludgeoning, DC 26"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const ability = creature.abilitiesBot?.[0];
|
||||||
|
expect(ability).toBeDefined();
|
||||||
|
expect(ability?.segments[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: "text",
|
||||||
|
value: "1d8+8 bludgeoning, DC 26",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("resistances formatting", () => {
|
describe("resistances formatting", () => {
|
||||||
it("formats resistance without amount", () => {
|
it("formats resistance without amount", () => {
|
||||||
const [creature] = normalizePf2eBestiary({
|
const [creature] = normalizePf2eBestiary({
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ interface RawDefenses {
|
|||||||
|
|
||||||
interface RawAbility {
|
interface RawAbility {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
traits?: string[];
|
||||||
entries?: RawEntry[];
|
entries?: RawEntry[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,11 +245,27 @@ function normalizeAbilities(
|
|||||||
.filter((a) => a.name)
|
.filter((a) => a.name)
|
||||||
.map((a) => {
|
.map((a) => {
|
||||||
const raw = a as Record<string, unknown>;
|
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 {
|
return {
|
||||||
name: stripTags(a.name as string),
|
name: stripTags(a.name as string),
|
||||||
segments: Array.isArray(a.entries)
|
segments: [
|
||||||
? segmentizeEntries(a.entries)
|
{ type: "text" as const, value: traits + body[0].value },
|
||||||
: formatAffliction(raw),
|
...body.slice(1),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
name: stripTags(a.name as string),
|
||||||
|
segments: traits
|
||||||
|
? [{ type: "text" as const, value: traits }, ...body]
|
||||||
|
: body,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user