Fix "undefined" in PF2e stat block weaknesses/resistances
Some PF2e creatures (e.g. Giant Mining Bee) have qualitative weaknesses without a numeric amount, causing "undefined" to render in the stat block. Handle missing amounts gracefully. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -40,8 +40,8 @@ interface RawDefenses {
|
||||
};
|
||||
hp?: { hp?: number }[];
|
||||
immunities?: (string | { name: string })[];
|
||||
resistances?: { amount: number; name: string; note?: string }[];
|
||||
weaknesses?: { amount: number; name: string; note?: string }[];
|
||||
resistances?: { amount?: number; name: string; note?: string }[];
|
||||
weaknesses?: { amount?: number; name: string; note?: string }[];
|
||||
}
|
||||
|
||||
interface RawAbility {
|
||||
@@ -150,31 +150,35 @@ function formatImmunities(
|
||||
|
||||
function formatResistances(
|
||||
resistances:
|
||||
| readonly { amount: number; name: string; note?: string }[]
|
||||
| readonly { amount?: number; name: string; note?: string }[]
|
||||
| undefined,
|
||||
): string | undefined {
|
||||
if (!resistances || resistances.length === 0) return undefined;
|
||||
return resistances
|
||||
.map((r) =>
|
||||
r.note
|
||||
? `${capitalize(r.name)} ${r.amount} (${r.note})`
|
||||
: `${capitalize(r.name)} ${r.amount}`,
|
||||
)
|
||||
.map((r) => {
|
||||
const base =
|
||||
r.amount == null
|
||||
? capitalize(r.name)
|
||||
: `${capitalize(r.name)} ${r.amount}`;
|
||||
return r.note ? `${base} (${r.note})` : base;
|
||||
})
|
||||
.join(", ");
|
||||
}
|
||||
|
||||
function formatWeaknesses(
|
||||
weaknesses:
|
||||
| readonly { amount: number; name: string; note?: string }[]
|
||||
| readonly { amount?: number; name: string; note?: string }[]
|
||||
| undefined,
|
||||
): string | undefined {
|
||||
if (!weaknesses || weaknesses.length === 0) return undefined;
|
||||
return weaknesses
|
||||
.map((w) =>
|
||||
w.note
|
||||
? `${capitalize(w.name)} ${w.amount} (${w.note})`
|
||||
: `${capitalize(w.name)} ${w.amount}`,
|
||||
)
|
||||
.map((w) => {
|
||||
const base =
|
||||
w.amount == null
|
||||
? capitalize(w.name)
|
||||
: `${capitalize(w.name)} ${w.amount}`;
|
||||
return w.note ? `${base} (${w.note})` : base;
|
||||
})
|
||||
.join(", ");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user