Add PF2e action cost icons to ability names
Show Unicode action icons (◆/◆◆/◆◆◆ for actions, ◇ for free, ↺ for reaction) in ability names from the activity field. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -170,7 +170,7 @@ describe("normalizePf2eBestiary", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ability traits formatting", () => {
|
describe("ability formatting", () => {
|
||||||
it("includes traits from abilities in the text", () => {
|
it("includes traits from abilities in the text", () => {
|
||||||
const [creature] = normalizePf2eBestiary({
|
const [creature] = normalizePf2eBestiary({
|
||||||
creature: [
|
creature: [
|
||||||
@@ -179,6 +179,7 @@ describe("normalizePf2eBestiary", () => {
|
|||||||
bot: [
|
bot: [
|
||||||
{
|
{
|
||||||
name: "Change Shape",
|
name: "Change Shape",
|
||||||
|
activity: { number: 1, unit: "action" },
|
||||||
traits: [
|
traits: [
|
||||||
"concentrate",
|
"concentrate",
|
||||||
"divine",
|
"divine",
|
||||||
@@ -196,6 +197,7 @@ describe("normalizePf2eBestiary", () => {
|
|||||||
});
|
});
|
||||||
const ability = creature.abilitiesBot?.[0];
|
const ability = creature.abilitiesBot?.[0];
|
||||||
expect(ability).toBeDefined();
|
expect(ability).toBeDefined();
|
||||||
|
expect(ability?.name).toBe("\u25C6 Change Shape");
|
||||||
expect(ability?.segments[0]).toEqual(
|
expect(ability?.segments[0]).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
type: "text",
|
type: "text",
|
||||||
@@ -206,7 +208,68 @@ describe("normalizePf2eBestiary", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders ability without traits normally", () => {
|
it("shows free action icon", () => {
|
||||||
|
const [creature] = normalizePf2eBestiary({
|
||||||
|
creature: [
|
||||||
|
minimalCreature({
|
||||||
|
abilities: {
|
||||||
|
bot: [
|
||||||
|
{
|
||||||
|
name: "Adaptive Strike",
|
||||||
|
activity: { number: 1, unit: "free" },
|
||||||
|
entries: ["The naunet chooses adamantine."],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
expect(creature.abilitiesBot?.[0]?.name).toBe("\u25C7 Adaptive Strike");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows reaction icon", () => {
|
||||||
|
const [creature] = normalizePf2eBestiary({
|
||||||
|
creature: [
|
||||||
|
minimalCreature({
|
||||||
|
abilities: {
|
||||||
|
mid: [
|
||||||
|
{
|
||||||
|
name: "Attack of Opportunity",
|
||||||
|
activity: { number: 1, unit: "reaction" },
|
||||||
|
entries: ["Trigger description."],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
expect(creature.abilitiesMid?.[0]?.name).toBe(
|
||||||
|
"\u21BA Attack of Opportunity",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows multi-action icons", () => {
|
||||||
|
const [creature] = normalizePf2eBestiary({
|
||||||
|
creature: [
|
||||||
|
minimalCreature({
|
||||||
|
abilities: {
|
||||||
|
bot: [
|
||||||
|
{
|
||||||
|
name: "Breath Weapon",
|
||||||
|
activity: { number: 2, unit: "action" },
|
||||||
|
entries: ["Fire breath."],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
expect(creature.abilitiesBot?.[0]?.name).toBe(
|
||||||
|
"\u25C6\u25C6 Breath Weapon",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders ability without activity or traits normally", () => {
|
||||||
const [creature] = normalizePf2eBestiary({
|
const [creature] = normalizePf2eBestiary({
|
||||||
creature: [
|
creature: [
|
||||||
minimalCreature({
|
minimalCreature({
|
||||||
@@ -223,6 +286,7 @@ describe("normalizePf2eBestiary", () => {
|
|||||||
});
|
});
|
||||||
const ability = creature.abilitiesBot?.[0];
|
const ability = creature.abilitiesBot?.[0];
|
||||||
expect(ability).toBeDefined();
|
expect(ability).toBeDefined();
|
||||||
|
expect(ability?.name).toBe("Constrict");
|
||||||
expect(ability?.segments[0]).toEqual(
|
expect(ability?.segments[0]).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
type: "text",
|
type: "text",
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ interface RawDefenses {
|
|||||||
|
|
||||||
interface RawAbility {
|
interface RawAbility {
|
||||||
name?: string;
|
name?: string;
|
||||||
|
activity?: { number?: number; unit?: string };
|
||||||
traits?: string[];
|
traits?: string[];
|
||||||
entries?: RawEntry[];
|
entries?: RawEntry[];
|
||||||
}
|
}
|
||||||
@@ -80,6 +81,22 @@ function capitalize(s: string): string {
|
|||||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatActivityIcon(
|
||||||
|
activity: { number?: number; unit?: string } | undefined,
|
||||||
|
): string {
|
||||||
|
if (!activity) return "";
|
||||||
|
switch (activity.unit) {
|
||||||
|
case "free":
|
||||||
|
return "\u25C7 ";
|
||||||
|
case "reaction":
|
||||||
|
return "\u21BA ";
|
||||||
|
case "action":
|
||||||
|
return "\u25C6".repeat(activity.number ?? 1) + " ";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function stripAngleBrackets(s: string): string {
|
function stripAngleBrackets(s: string): string {
|
||||||
return s.replaceAll(/<([^>]+)>/g, "$1");
|
return s.replaceAll(/<([^>]+)>/g, "$1");
|
||||||
}
|
}
|
||||||
@@ -245,6 +262,7 @@ 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 icon = formatActivityIcon(a.activity);
|
||||||
const traits =
|
const traits =
|
||||||
a.traits && a.traits.length > 0
|
a.traits && a.traits.length > 0
|
||||||
? `(${a.traits.map((t) => capitalize(stripAngleBrackets(stripTags(t)))).join(", ")}) `
|
? `(${a.traits.map((t) => capitalize(stripAngleBrackets(stripTags(t)))).join(", ")}) `
|
||||||
@@ -252,9 +270,10 @@ function normalizeAbilities(
|
|||||||
const body = Array.isArray(a.entries)
|
const body = Array.isArray(a.entries)
|
||||||
? segmentizeEntries(a.entries)
|
? segmentizeEntries(a.entries)
|
||||||
: formatAffliction(raw);
|
: formatAffliction(raw);
|
||||||
|
const name = icon + stripTags(a.name as string);
|
||||||
if (traits && body.length > 0 && body[0].type === "text") {
|
if (traits && body.length > 0 && body[0].type === "text") {
|
||||||
return {
|
return {
|
||||||
name: stripTags(a.name as string),
|
name,
|
||||||
segments: [
|
segments: [
|
||||||
{ type: "text" as const, value: traits + body[0].value },
|
{ type: "text" as const, value: traits + body[0].value },
|
||||||
...body.slice(1),
|
...body.slice(1),
|
||||||
@@ -262,7 +281,7 @@ function normalizeAbilities(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
name: stripTags(a.name as string),
|
name,
|
||||||
segments: traits
|
segments: traits
|
||||||
? [{ type: "text" as const, value: traits }, ...body]
|
? [{ type: "text" as const, value: traits }, ...body]
|
||||||
: body,
|
: body,
|
||||||
|
|||||||
Reference in New Issue
Block a user