Improve PF2e stat block action icons, triggers, and tag handling

- Replace unicode action cost chars with custom SVG icons (diamond
  with chevron for actions, outlined diamond for free, curved arrow
  for reaction) rendered inline via ActivityCost on TraitBlock
- Add activity icons to attacks (all Strikes default to single action)
- Add trigger/effect rendering for reaction abilities (bold labels)
- Fix nested tag stripping ({@b ...{@spell ...}...}) by looping
- Move icon after ability name to match AoN format

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-04-08 10:36:30 +02:00
parent 57278e0c82
commit 0c235112ee
7 changed files with 187 additions and 44 deletions

View File

@@ -47,6 +47,7 @@ interface RawDefenses {
interface RawAbility {
name?: string;
activity?: { number?: number; unit?: string };
trigger?: string;
traits?: string[];
entries?: RawEntry[];
}
@@ -81,20 +82,15 @@ function capitalize(s: string): string {
return s.charAt(0).toUpperCase() + s.slice(1);
}
function formatActivityIcon(
function parseActivity(
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 "";
): { number: number; unit: "action" | "free" | "reaction" } | undefined {
if (!activity?.unit) return undefined;
const unit = activity.unit;
if (unit === "action" || unit === "free" || unit === "reaction") {
return { number: activity.number ?? 1, unit };
}
return undefined;
}
function stripAngleBrackets(s: string): string {
@@ -262,28 +258,34 @@ function normalizeAbilities(
.filter((a) => a.name)
.map((a) => {
const raw = a as Record<string, unknown>;
const icon = formatActivityIcon(a.activity);
const activity = parseActivity(a.activity);
const trigger = a.trigger ? stripTags(a.trigger) : undefined;
const traits =
a.traits && a.traits.length > 0
? `(${a.traits.map((t) => capitalize(stripAngleBrackets(stripTags(t)))).join(", ")}) `
: "";
const prefix = traits;
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") {
const name = stripTags(a.name as string);
if (prefix && body.length > 0 && body[0].type === "text") {
return {
name,
activity,
trigger,
segments: [
{ type: "text" as const, value: traits + body[0].value },
{ type: "text" as const, value: prefix + body[0].value },
...body.slice(1),
],
};
}
return {
name,
segments: traits
? [{ type: "text" as const, value: traits }, ...body]
activity,
trigger,
segments: prefix
? [{ type: "text" as const, value: prefix }, ...body]
: body,
};
});
@@ -306,6 +308,7 @@ function normalizeAttacks(
: "";
return {
name: capitalize(stripTags(a.name)),
activity: { number: 1, unit: "action" as const },
segments: [
{
type: "text" as const,