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:
@@ -46,6 +46,7 @@ interface RawDefenses {
|
||||
|
||||
interface RawAbility {
|
||||
name?: string;
|
||||
activity?: { number?: number; unit?: string };
|
||||
traits?: string[];
|
||||
entries?: RawEntry[];
|
||||
}
|
||||
@@ -80,6 +81,22 @@ function capitalize(s: string): string {
|
||||
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 {
|
||||
return s.replaceAll(/<([^>]+)>/g, "$1");
|
||||
}
|
||||
@@ -245,6 +262,7 @@ function normalizeAbilities(
|
||||
.filter((a) => a.name)
|
||||
.map((a) => {
|
||||
const raw = a as Record<string, unknown>;
|
||||
const icon = formatActivityIcon(a.activity);
|
||||
const traits =
|
||||
a.traits && a.traits.length > 0
|
||||
? `(${a.traits.map((t) => capitalize(stripAngleBrackets(stripTags(t)))).join(", ")}) `
|
||||
@@ -252,9 +270,10 @@ function normalizeAbilities(
|
||||
const body = Array.isArray(a.entries)
|
||||
? segmentizeEntries(a.entries)
|
||||
: formatAffliction(raw);
|
||||
const name = icon + stripTags(a.name as string);
|
||||
if (traits && body.length > 0 && body[0].type === "text") {
|
||||
return {
|
||||
name: stripTags(a.name as string),
|
||||
name,
|
||||
segments: [
|
||||
{ type: "text" as const, value: traits + body[0].value },
|
||||
...body.slice(1),
|
||||
@@ -262,7 +281,7 @@ function normalizeAbilities(
|
||||
};
|
||||
}
|
||||
return {
|
||||
name: stripTags(a.name as string),
|
||||
name,
|
||||
segments: traits
|
||||
? [{ type: "text" as const, value: traits }, ...body]
|
||||
: body,
|
||||
|
||||
Reference in New Issue
Block a user