Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1eaeecad32 |
@@ -541,6 +541,288 @@ describe("normalizeFoundryCreature", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("equipment normalization", () => {
|
||||||
|
it("normalizes a weapon with traits and description", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "w1",
|
||||||
|
name: "Flaming Longsword",
|
||||||
|
type: "weapon",
|
||||||
|
system: {
|
||||||
|
level: { value: 5 },
|
||||||
|
traits: { value: ["magical", "fire"] },
|
||||||
|
description: {
|
||||||
|
value: "<p>This sword blazes with fire.</p>",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.equipment).toHaveLength(1);
|
||||||
|
const item = creature.equipment?.[0];
|
||||||
|
expect(item?.name).toBe("Flaming Longsword");
|
||||||
|
expect(item?.level).toBe(5);
|
||||||
|
expect(item?.traits).toEqual(["magical", "fire"]);
|
||||||
|
expect(item?.description).toBe("This sword blazes with fire.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("normalizes a consumable potion with description", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "c1",
|
||||||
|
name: "Healing Potion (Moderate)",
|
||||||
|
type: "consumable",
|
||||||
|
system: {
|
||||||
|
level: { value: 6 },
|
||||||
|
traits: { value: ["consumable", "healing", "magical"] },
|
||||||
|
description: {
|
||||||
|
value: "<p>Restores 3d8+10 Hit Points.</p>",
|
||||||
|
},
|
||||||
|
category: "potion",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.equipment).toHaveLength(1);
|
||||||
|
const item = creature.equipment?.[0];
|
||||||
|
expect(item?.name).toBe("Healing Potion (Moderate)");
|
||||||
|
expect(item?.category).toBe("potion");
|
||||||
|
expect(item?.description).toBe("Restores 3d8+10 Hit Points.");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts scroll embedded spell name and rank", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "s1",
|
||||||
|
name: "Scroll of Teleport (Rank 6)",
|
||||||
|
type: "consumable",
|
||||||
|
system: {
|
||||||
|
level: { value: 11 },
|
||||||
|
traits: { value: ["consumable", "magical", "scroll"] },
|
||||||
|
description: { value: "<p>A scroll.</p>" },
|
||||||
|
category: "scroll",
|
||||||
|
spell: {
|
||||||
|
name: "Teleport",
|
||||||
|
system: { level: { value: 6 } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const item = creature.equipment?.[0];
|
||||||
|
expect(item?.spellName).toBe("Teleport");
|
||||||
|
expect(item?.spellRank).toBe(6);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("extracts wand embedded spell name and rank", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "w1",
|
||||||
|
name: "Wand of Dispel Magic (Rank 2)",
|
||||||
|
type: "consumable",
|
||||||
|
system: {
|
||||||
|
level: { value: 5 },
|
||||||
|
traits: { value: ["consumable", "magical", "wand"] },
|
||||||
|
description: { value: "<p>A wand.</p>" },
|
||||||
|
category: "wand",
|
||||||
|
spell: {
|
||||||
|
name: "Dispel Magic",
|
||||||
|
system: { level: { value: 2 } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const item = creature.equipment?.[0];
|
||||||
|
expect(item?.spellName).toBe("Dispel Magic");
|
||||||
|
expect(item?.spellRank).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters magical equipment into equipment field", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "e1",
|
||||||
|
name: "Ring of Energy Resistance (Fire)",
|
||||||
|
type: "equipment",
|
||||||
|
system: {
|
||||||
|
level: { value: 6 },
|
||||||
|
traits: { value: ["magical", "invested"] },
|
||||||
|
description: {
|
||||||
|
value: "<p>Grants fire resistance 5.</p>",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.equipment).toHaveLength(1);
|
||||||
|
expect(creature.equipment?.[0]?.name).toBe(
|
||||||
|
"Ring of Energy Resistance (Fire)",
|
||||||
|
);
|
||||||
|
expect(creature.items).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters mundane items into items string", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "w1",
|
||||||
|
name: "Longsword",
|
||||||
|
type: "weapon",
|
||||||
|
system: {
|
||||||
|
level: { value: 0 },
|
||||||
|
traits: { value: [] },
|
||||||
|
description: { value: "" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
_id: "a1",
|
||||||
|
name: "Leather Armor",
|
||||||
|
type: "armor",
|
||||||
|
system: {
|
||||||
|
level: { value: 0 },
|
||||||
|
traits: { value: [] },
|
||||||
|
description: { value: "" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.items).toBe("Longsword, Leather Armor");
|
||||||
|
expect(creature.equipment).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("omits equipment when no detailed items exist", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "w1",
|
||||||
|
name: "Dagger",
|
||||||
|
type: "weapon",
|
||||||
|
system: {
|
||||||
|
level: { value: 0 },
|
||||||
|
traits: { value: [] },
|
||||||
|
description: { value: "" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.equipment).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("omits items when no mundane items exist", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "c1",
|
||||||
|
name: "Giant Wasp Venom",
|
||||||
|
type: "consumable",
|
||||||
|
system: {
|
||||||
|
level: { value: 7 },
|
||||||
|
traits: { value: ["consumable", "poison"] },
|
||||||
|
description: {
|
||||||
|
value: "<p>A deadly poison.</p>",
|
||||||
|
},
|
||||||
|
category: "poison",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.items).toBeUndefined();
|
||||||
|
expect(creature.equipment).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("includes armor with special material in equipment", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "a1",
|
||||||
|
name: "Adamantine Full Plate",
|
||||||
|
type: "armor",
|
||||||
|
system: {
|
||||||
|
level: { value: 0 },
|
||||||
|
traits: { value: [] },
|
||||||
|
description: {
|
||||||
|
value: "<p>Full plate made of adamantine.</p>",
|
||||||
|
},
|
||||||
|
material: { type: "adamantine", grade: "standard" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.equipment).toHaveLength(1);
|
||||||
|
expect(creature.equipment?.[0]?.name).toBe("Adamantine Full Plate");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("excludes mundane armor from equipment (goes to items)", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "a1",
|
||||||
|
name: "Chain Mail",
|
||||||
|
type: "armor",
|
||||||
|
system: {
|
||||||
|
level: { value: 0 },
|
||||||
|
traits: { value: [] },
|
||||||
|
description: { value: "" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(creature.equipment).toBeUndefined();
|
||||||
|
expect(creature.items).toBe("Chain Mail");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("strips Foundry HTML tags from equipment descriptions", () => {
|
||||||
|
const creature = normalizeFoundryCreature(
|
||||||
|
minimalCreature({
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
_id: "c1",
|
||||||
|
name: "Potion of Speed",
|
||||||
|
type: "consumable",
|
||||||
|
system: {
|
||||||
|
level: { value: 10 },
|
||||||
|
traits: { value: ["consumable", "magical"] },
|
||||||
|
description: {
|
||||||
|
value:
|
||||||
|
"<p>Gain @UUID[Compendium.pf2e.conditionitems.Item.Quickened]{quickened} for 1 minute.</p>",
|
||||||
|
},
|
||||||
|
category: "potion",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
const desc = creature.equipment?.[0]?.description;
|
||||||
|
expect(desc).toBe("Gain quickened for 1 minute.");
|
||||||
|
expect(desc).not.toContain("@UUID");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("spellcasting normalization", () => {
|
describe("spellcasting normalization", () => {
|
||||||
it("normalizes prepared spells by rank", () => {
|
it("normalizes prepared spells by rank", () => {
|
||||||
const creature = normalizeFoundryCreature(
|
const creature = normalizeFoundryCreature(
|
||||||
@@ -597,7 +879,8 @@ describe("normalizeFoundryCreature", () => {
|
|||||||
expect(sc?.daily?.[0]?.spells.map((s) => s.name)).toEqual(["Earthquake"]);
|
expect(sc?.daily?.[0]?.spells.map((s) => s.name)).toEqual(["Earthquake"]);
|
||||||
expect(sc?.daily?.[1]?.spells.map((s) => s.name)).toEqual(["Heal"]);
|
expect(sc?.daily?.[1]?.spells.map((s) => s.name)).toEqual(["Heal"]);
|
||||||
expect(sc?.atWill?.map((s) => s.name)).toEqual(["Detect Magic"]);
|
expect(sc?.atWill?.map((s) => s.name)).toEqual(["Detect Magic"]);
|
||||||
expect(sc?.atWill?.[0]?.rank).toBe(1);
|
// Cantrip rank auto-heightens to ceil(creatureLevel / 2) = ceil(3/2) = 2
|
||||||
|
expect(sc?.atWill?.[0]?.rank).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("normalizes innate spells with uses", () => {
|
it("normalizes innate spells with uses", () => {
|
||||||
|
|||||||
@@ -99,9 +99,15 @@ describe("stripFoundryTags", () => {
|
|||||||
expect(stripFoundryTags("before<hr />after")).toBe("before\nafter");
|
expect(stripFoundryTags("before<hr />after")).toBe("before\nafter");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("strips strong and em tags", () => {
|
it("preserves strong and em tags", () => {
|
||||||
expect(stripFoundryTags("<strong>bold</strong> <em>italic</em>")).toBe(
|
expect(stripFoundryTags("<strong>bold</strong> <em>italic</em>")).toBe(
|
||||||
"bold italic",
|
"<strong>bold</strong> <em>italic</em>",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("preserves list tags", () => {
|
||||||
|
expect(stripFoundryTags("<ul><li>first</li><li>second</li></ul>")).toBe(
|
||||||
|
"<ul><li>first</li><li>second</li></ul>",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import { type IDBPDatabase, openDB } from "idb";
|
|||||||
|
|
||||||
const DB_NAME = "initiative-bestiary";
|
const DB_NAME = "initiative-bestiary";
|
||||||
const STORE_NAME = "sources";
|
const STORE_NAME = "sources";
|
||||||
// v6 (2026-04-09): SpellReference per-spell data added; old caches are cleared
|
// v7 (2026-04-10): Equipment items added to PF2e creatures; old caches are cleared
|
||||||
const DB_VERSION = 6;
|
const DB_VERSION = 7;
|
||||||
|
|
||||||
interface CachedSourceInfo {
|
interface CachedSourceInfo {
|
||||||
readonly sourceCode: string;
|
readonly sourceCode: string;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type {
|
import type {
|
||||||
CreatureId,
|
CreatureId,
|
||||||
|
EquipmentItem,
|
||||||
Pf2eCreature,
|
Pf2eCreature,
|
||||||
SpellcastingBlock,
|
SpellcastingBlock,
|
||||||
SpellReference,
|
SpellReference,
|
||||||
@@ -114,6 +115,73 @@ interface SpellSystem {
|
|||||||
>;
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ConsumableSystem {
|
||||||
|
level?: { value: number };
|
||||||
|
traits?: { value: string[] };
|
||||||
|
description?: { value: string };
|
||||||
|
category?: string;
|
||||||
|
spell?: {
|
||||||
|
name: string;
|
||||||
|
system?: { level?: { value: number } };
|
||||||
|
} | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EQUIPMENT_TYPES = new Set(["weapon", "consumable", "equipment", "armor"]);
|
||||||
|
|
||||||
|
/** Items shown in the Equipment section with popovers. */
|
||||||
|
function isDetailedEquipment(item: RawFoundryItem): boolean {
|
||||||
|
if (!EQUIPMENT_TYPES.has(item.type)) return false;
|
||||||
|
const sys = item.system;
|
||||||
|
const level = (sys.level as { value: number } | undefined)?.value ?? 0;
|
||||||
|
const traits = (sys.traits as { value: string[] } | undefined)?.value ?? [];
|
||||||
|
// All consumables are tactically relevant (potions, scrolls, poisons, etc.)
|
||||||
|
if (item.type === "consumable") return true;
|
||||||
|
// Magical/invested items
|
||||||
|
if (traits.includes("magical") || traits.includes("invested")) return true;
|
||||||
|
// Special material armor/equipment
|
||||||
|
const material = sys.material as { type: string | null } | undefined;
|
||||||
|
if (material?.type) return true;
|
||||||
|
// Higher-level items
|
||||||
|
if (level > 0) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Items shown on the "Items" line as plain names. */
|
||||||
|
function isMundaneItem(item: RawFoundryItem): boolean {
|
||||||
|
return EQUIPMENT_TYPES.has(item.type) && !isDetailedEquipment(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeEquipmentItem(item: RawFoundryItem): EquipmentItem {
|
||||||
|
const sys = item.system;
|
||||||
|
const level = (sys.level as { value: number } | undefined)?.value ?? 0;
|
||||||
|
const traits = (sys.traits as { value: string[] } | undefined)?.value;
|
||||||
|
const rawDesc = (sys.description as { value: string } | undefined)?.value;
|
||||||
|
const description = rawDesc
|
||||||
|
? stripFoundryTags(rawDesc) || undefined
|
||||||
|
: undefined;
|
||||||
|
const category = sys.category as string | undefined;
|
||||||
|
|
||||||
|
let spellName: string | undefined;
|
||||||
|
let spellRank: number | undefined;
|
||||||
|
if (item.type === "consumable") {
|
||||||
|
const spell = (sys as unknown as ConsumableSystem).spell;
|
||||||
|
if (spell) {
|
||||||
|
spellName = spell.name;
|
||||||
|
spellRank = spell.system?.level?.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: item.name,
|
||||||
|
level,
|
||||||
|
category: category || undefined,
|
||||||
|
traits: traits && traits.length > 0 ? traits : undefined,
|
||||||
|
description,
|
||||||
|
spellName,
|
||||||
|
spellRank,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const SIZE_MAP: Record<string, string> = {
|
const SIZE_MAP: Record<string, string> = {
|
||||||
tiny: "tiny",
|
tiny: "tiny",
|
||||||
sm: "small",
|
sm: "small",
|
||||||
@@ -402,16 +470,25 @@ function formatOverlays(overlays: SpellSystem["overlays"]): string | undefined {
|
|||||||
*/
|
*/
|
||||||
const HEIGHTENED_SUFFIX = /\s*Heightened\s*\([^)]*\)[\s\S]*$/;
|
const HEIGHTENED_SUFFIX = /\s*Heightened\s*\([^)]*\)[\s\S]*$/;
|
||||||
|
|
||||||
function normalizeSpell(item: RawFoundryItem): SpellReference {
|
function normalizeSpell(
|
||||||
|
item: RawFoundryItem,
|
||||||
|
creatureLevel: number,
|
||||||
|
): SpellReference {
|
||||||
const sys = item.system as unknown as SpellSystem;
|
const sys = item.system as unknown as SpellSystem;
|
||||||
const usesMax = sys.location?.uses?.max;
|
const usesMax = sys.location?.uses?.max;
|
||||||
const rank = sys.location?.heightenedLevel ?? sys.level?.value ?? 0;
|
const isCantrip = sys.traits?.value?.includes("cantrip") ?? false;
|
||||||
|
const rank =
|
||||||
|
sys.location?.heightenedLevel ??
|
||||||
|
(isCantrip ? Math.ceil(creatureLevel / 2) : (sys.level?.value ?? 0));
|
||||||
const heightening =
|
const heightening =
|
||||||
formatHeightening(sys.heightening) ?? formatOverlays(sys.overlays);
|
formatHeightening(sys.heightening) ?? formatOverlays(sys.overlays);
|
||||||
|
|
||||||
let description: string | undefined;
|
let description: string | undefined;
|
||||||
if (sys.description?.value) {
|
if (sys.description?.value) {
|
||||||
let text = stripFoundryTags(sys.description.value);
|
let text = stripFoundryTags(sys.description.value);
|
||||||
|
// Resolve Foundry Roll formula references to the spell's actual rank.
|
||||||
|
// The parenthesized form (e.g., "(@item.level)d4") is most common.
|
||||||
|
text = text.replaceAll(/\(?@item\.(?:rank|level)\)?/g, String(rank));
|
||||||
if (heightening) {
|
if (heightening) {
|
||||||
text = text.replace(HEIGHTENED_SUFFIX, "").trim();
|
text = text.replace(HEIGHTENED_SUFFIX, "").trim();
|
||||||
}
|
}
|
||||||
@@ -439,6 +516,7 @@ function normalizeSpell(item: RawFoundryItem): SpellReference {
|
|||||||
function normalizeSpellcastingEntry(
|
function normalizeSpellcastingEntry(
|
||||||
entry: RawFoundryItem,
|
entry: RawFoundryItem,
|
||||||
allSpells: readonly RawFoundryItem[],
|
allSpells: readonly RawFoundryItem[],
|
||||||
|
creatureLevel: number,
|
||||||
): SpellcastingBlock {
|
): SpellcastingBlock {
|
||||||
const sys = entry.system as unknown as SpellcastingEntrySystem;
|
const sys = entry.system as unknown as SpellcastingEntrySystem;
|
||||||
const tradition = capitalize(sys.tradition?.value ?? "");
|
const tradition = capitalize(sys.tradition?.value ?? "");
|
||||||
@@ -457,7 +535,7 @@ function normalizeSpellcastingEntry(
|
|||||||
const cantrips: SpellReference[] = [];
|
const cantrips: SpellReference[] = [];
|
||||||
|
|
||||||
for (const spell of linkedSpells) {
|
for (const spell of linkedSpells) {
|
||||||
const ref = normalizeSpell(spell);
|
const ref = normalizeSpell(spell, creatureLevel);
|
||||||
const isCantrip =
|
const isCantrip =
|
||||||
(spell.system as unknown as SpellSystem).traits?.value?.includes(
|
(spell.system as unknown as SpellSystem).traits?.value?.includes(
|
||||||
"cantrip",
|
"cantrip",
|
||||||
@@ -490,10 +568,13 @@ function normalizeSpellcastingEntry(
|
|||||||
|
|
||||||
function normalizeSpellcasting(
|
function normalizeSpellcasting(
|
||||||
items: readonly RawFoundryItem[],
|
items: readonly RawFoundryItem[],
|
||||||
|
creatureLevel: number,
|
||||||
): SpellcastingBlock[] {
|
): SpellcastingBlock[] {
|
||||||
const entries = items.filter((i) => i.type === "spellcastingEntry");
|
const entries = items.filter((i) => i.type === "spellcastingEntry");
|
||||||
const spells = items.filter((i) => i.type === "spell");
|
const spells = items.filter((i) => i.type === "spell");
|
||||||
return entries.map((entry) => normalizeSpellcastingEntry(entry, spells));
|
return entries.map((entry) =>
|
||||||
|
normalizeSpellcastingEntry(entry, spells, creatureLevel),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- Main normalization --
|
// -- Main normalization --
|
||||||
@@ -632,7 +713,17 @@ export function normalizeFoundryCreature(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
abilitiesBot: orUndefined(actionsByCategory(items, "offensive")),
|
abilitiesBot: orUndefined(actionsByCategory(items, "offensive")),
|
||||||
spellcasting: orUndefined(normalizeSpellcasting(items)),
|
spellcasting: orUndefined(
|
||||||
|
normalizeSpellcasting(items, sys.details?.level?.value ?? 0),
|
||||||
|
),
|
||||||
|
items:
|
||||||
|
items
|
||||||
|
.filter(isMundaneItem)
|
||||||
|
.map((i) => i.name)
|
||||||
|
.join(", ") || undefined,
|
||||||
|
equipment: orUndefined(
|
||||||
|
items.filter(isDetailedEquipment).map(normalizeEquipmentItem),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,13 @@
|
|||||||
|
|
||||||
function formatDamage(params: string): string {
|
function formatDamage(params: string): string {
|
||||||
// "3d6+10[fire]" → "3d6+10 fire"
|
// "3d6+10[fire]" → "3d6+10 fire"
|
||||||
return params.replaceAll(/\[([^\]]*)\]/g, " $1").trim();
|
// "d4[persistent,fire]" → "d4 persistent fire"
|
||||||
|
return params
|
||||||
|
.replaceAll(
|
||||||
|
/\[([^\]]*)\]/g,
|
||||||
|
(_, type: string) => ` ${type.replaceAll(",", " ")}`,
|
||||||
|
)
|
||||||
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCheck(params: string): string {
|
function formatCheck(params: string): string {
|
||||||
@@ -80,11 +86,11 @@ export function stripFoundryTags(html: string): string {
|
|||||||
// Strip action-glyph spans (content is a number the renderer handles)
|
// Strip action-glyph spans (content is a number the renderer handles)
|
||||||
result = result.replaceAll(/<span class="action-glyph">[^<]*<\/span>/gi, "");
|
result = result.replaceAll(/<span class="action-glyph">[^<]*<\/span>/gi, "");
|
||||||
|
|
||||||
// Strip HTML tags
|
// Strip HTML tags (preserve <strong> for UI rendering)
|
||||||
result = result.replaceAll(/<br\s*\/?>/gi, "\n");
|
result = result.replaceAll(/<br\s*\/?>/gi, "\n");
|
||||||
result = result.replaceAll(/<hr\s*\/?>/gi, "\n");
|
result = result.replaceAll(/<hr\s*\/?>/gi, "\n");
|
||||||
result = result.replaceAll(/<\/p>\s*<p[^>]*>/gi, "\n");
|
result = result.replaceAll(/<\/p>\s*<p[^>]*>/gi, "\n");
|
||||||
result = result.replaceAll(/<[^>]+>/g, "");
|
result = result.replaceAll(/<(?!\/?(?:strong|em|ul|ol|li)\b)[^>]+>/g, "");
|
||||||
|
|
||||||
// Decode common HTML entities
|
// Decode common HTML entities
|
||||||
result = result.replaceAll("&", "&");
|
result = result.replaceAll("&", "&");
|
||||||
@@ -92,6 +98,11 @@ export function stripFoundryTags(html: string): string {
|
|||||||
result = result.replaceAll(">", ">");
|
result = result.replaceAll(">", ">");
|
||||||
result = result.replaceAll(""", '"');
|
result = result.replaceAll(""", '"');
|
||||||
|
|
||||||
|
// Collapse whitespace around list tags so they don't create extra
|
||||||
|
// line breaks when rendered with whitespace-pre-line
|
||||||
|
result = result.replaceAll(/\s*(<\/?(?:ul|ol)>)\s*/g, "$1");
|
||||||
|
result = result.replaceAll(/\s*(<\/?li>)\s*/g, "$1");
|
||||||
|
|
||||||
// Collapse whitespace
|
// Collapse whitespace
|
||||||
result = result.replaceAll(/[ \t]+/g, " ");
|
result = result.replaceAll(/[ \t]+/g, " ");
|
||||||
result = result.replaceAll(/\n\s*\n/g, "\n");
|
result = result.replaceAll(/\n\s*\n/g, "\n");
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
// @vitest-environment jsdom
|
||||||
|
import "@testing-library/jest-dom/vitest";
|
||||||
|
|
||||||
|
import type { EquipmentItem } from "@initiative/domain";
|
||||||
|
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { EquipmentDetailPopover } from "../equipment-detail-popover.js";
|
||||||
|
|
||||||
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
const POISON: EquipmentItem = {
|
||||||
|
name: "Giant Wasp Venom",
|
||||||
|
level: 7,
|
||||||
|
category: "poison",
|
||||||
|
traits: ["consumable", "poison", "injury"],
|
||||||
|
description: "A deadly poison extracted from giant wasps.",
|
||||||
|
};
|
||||||
|
|
||||||
|
const SCROLL: EquipmentItem = {
|
||||||
|
name: "Scroll of Teleport",
|
||||||
|
level: 11,
|
||||||
|
category: "scroll",
|
||||||
|
traits: ["consumable", "magical", "scroll"],
|
||||||
|
description: "A scroll containing Teleport.",
|
||||||
|
spellName: "Teleport",
|
||||||
|
spellRank: 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
const ANCHOR: DOMRect = new DOMRect(100, 100, 50, 20);
|
||||||
|
const SCROLL_SPELL_REGEX = /Teleport \(Rank 6\)/;
|
||||||
|
const DIALOG_LABEL_REGEX = /Equipment details: Giant Wasp Venom/;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
Object.defineProperty(globalThis, "matchMedia", {
|
||||||
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
value: vi.fn().mockImplementation(() => ({
|
||||||
|
matches: true,
|
||||||
|
media: "(min-width: 1024px)",
|
||||||
|
onchange: null,
|
||||||
|
addEventListener: vi.fn(),
|
||||||
|
removeEventListener: vi.fn(),
|
||||||
|
addListener: vi.fn(),
|
||||||
|
removeListener: vi.fn(),
|
||||||
|
dispatchEvent: vi.fn(),
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("EquipmentDetailPopover", () => {
|
||||||
|
it("renders item name, level, traits, and description", () => {
|
||||||
|
render(
|
||||||
|
<EquipmentDetailPopover
|
||||||
|
item={POISON}
|
||||||
|
anchorRect={ANCHOR}
|
||||||
|
onClose={() => {}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(screen.getByText("Giant Wasp Venom")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("7")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("consumable")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("poison")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("injury")).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.getByText("A deadly poison extracted from giant wasps."),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders scroll/wand spell info", () => {
|
||||||
|
render(
|
||||||
|
<EquipmentDetailPopover
|
||||||
|
item={SCROLL}
|
||||||
|
anchorRect={ANCHOR}
|
||||||
|
onClose={() => {}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(screen.getByText(SCROLL_SPELL_REGEX)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("calls onClose when Escape is pressed", () => {
|
||||||
|
const onClose = vi.fn();
|
||||||
|
render(
|
||||||
|
<EquipmentDetailPopover
|
||||||
|
item={POISON}
|
||||||
|
anchorRect={ANCHOR}
|
||||||
|
onClose={onClose}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
fireEvent.keyDown(document, { key: "Escape" });
|
||||||
|
expect(onClose).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses the dialog role with the item name as label", () => {
|
||||||
|
render(
|
||||||
|
<EquipmentDetailPopover
|
||||||
|
item={POISON}
|
||||||
|
anchorRect={ANCHOR}
|
||||||
|
onClose={() => {}}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
screen.getByRole("dialog", {
|
||||||
|
name: DIALOG_LABEL_REGEX,
|
||||||
|
}),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -31,6 +31,7 @@ const RK_DC_25_REGEX = /DC 25/;
|
|||||||
const RK_HUMANOID_SOCIETY_REGEX = /Humanoid \(Society\)/;
|
const RK_HUMANOID_SOCIETY_REGEX = /Humanoid \(Society\)/;
|
||||||
const RK_UNDEAD_RELIGION_REGEX = /Undead \(Religion\)/;
|
const RK_UNDEAD_RELIGION_REGEX = /Undead \(Religion\)/;
|
||||||
const RK_BEAST_SKILLS_REGEX = /Beast \(Arcana\/Nature\)/;
|
const RK_BEAST_SKILLS_REGEX = /Beast \(Arcana\/Nature\)/;
|
||||||
|
const SCROLL_NAME_REGEX = /Scroll of Teleport/;
|
||||||
|
|
||||||
const GOBLIN_WARRIOR: Pf2eCreature = {
|
const GOBLIN_WARRIOR: Pf2eCreature = {
|
||||||
system: "pf2e",
|
system: "pf2e",
|
||||||
@@ -338,6 +339,79 @@ describe("Pf2eStatBlock", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("equipment section", () => {
|
||||||
|
const CREATURE_WITH_EQUIPMENT: Pf2eCreature = {
|
||||||
|
...GOBLIN_WARRIOR,
|
||||||
|
id: creatureId("test:equipped"),
|
||||||
|
name: "Equipped NPC",
|
||||||
|
items: "longsword, leather armor",
|
||||||
|
equipment: [
|
||||||
|
{
|
||||||
|
name: "Giant Wasp Venom",
|
||||||
|
level: 7,
|
||||||
|
category: "poison",
|
||||||
|
traits: ["consumable", "poison"],
|
||||||
|
description: "A deadly poison extracted from giant wasps.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Scroll of Teleport",
|
||||||
|
level: 11,
|
||||||
|
category: "scroll",
|
||||||
|
traits: ["consumable", "magical", "scroll"],
|
||||||
|
description: "A scroll containing Teleport.",
|
||||||
|
spellName: "Teleport",
|
||||||
|
spellRank: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Plain Talisman",
|
||||||
|
level: 1,
|
||||||
|
traits: ["magical"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
it("renders Equipment section with item names", () => {
|
||||||
|
renderStatBlock(CREATURE_WITH_EQUIPMENT);
|
||||||
|
expect(
|
||||||
|
screen.getByRole("heading", { name: "Equipment" }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Giant Wasp Venom")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders scroll name as-is from Foundry data", () => {
|
||||||
|
renderStatBlock(CREATURE_WITH_EQUIPMENT);
|
||||||
|
expect(screen.getByText(SCROLL_NAME_REGEX)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not render Equipment section when creature has no equipment", () => {
|
||||||
|
renderStatBlock(GOBLIN_WARRIOR);
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("heading", { name: "Equipment" }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders equipment items with descriptions as clickable buttons", () => {
|
||||||
|
renderStatBlock(CREATURE_WITH_EQUIPMENT);
|
||||||
|
expect(
|
||||||
|
screen.getByRole("button", { name: "Giant Wasp Venom" }),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders equipment items without descriptions as plain text", () => {
|
||||||
|
renderStatBlock(CREATURE_WITH_EQUIPMENT);
|
||||||
|
expect(
|
||||||
|
screen.queryByRole("button", { name: "Plain Talisman" }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Plain Talisman")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders Items line with mundane item names", () => {
|
||||||
|
renderStatBlock(CREATURE_WITH_EQUIPMENT);
|
||||||
|
expect(screen.getByText("Items")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("longsword, leather armor")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("clickable spells", () => {
|
describe("clickable spells", () => {
|
||||||
const SPELLCASTER: Pf2eCreature = {
|
const SPELLCASTER: Pf2eCreature = {
|
||||||
...NAUNET,
|
...NAUNET,
|
||||||
|
|||||||
141
apps/web/src/components/detail-popover.tsx
Normal file
141
apps/web/src/components/detail-popover.tsx
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
import type { ReactNode } from "react";
|
||||||
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
import { useClickOutside } from "../hooks/use-click-outside.js";
|
||||||
|
import { useSwipeToDismissDown } from "../hooks/use-swipe-to-dismiss.js";
|
||||||
|
import { cn } from "../lib/utils.js";
|
||||||
|
|
||||||
|
interface DetailPopoverProps {
|
||||||
|
readonly anchorRect: DOMRect;
|
||||||
|
readonly onClose: () => void;
|
||||||
|
readonly ariaLabel: string;
|
||||||
|
readonly children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DesktopPanel({
|
||||||
|
anchorRect,
|
||||||
|
onClose,
|
||||||
|
ariaLabel,
|
||||||
|
children,
|
||||||
|
}: Readonly<DetailPopoverProps>) {
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
const [pos, setPos] = useState<{ top: number; left: number } | null>(null);
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
const el = ref.current;
|
||||||
|
if (!el) return;
|
||||||
|
const popover = el.getBoundingClientRect();
|
||||||
|
const vw = document.documentElement.clientWidth;
|
||||||
|
const vh = document.documentElement.clientHeight;
|
||||||
|
// Prefer placement to the LEFT of the anchor (panel is on the right edge)
|
||||||
|
let left = anchorRect.left - popover.width - 8;
|
||||||
|
if (left < 8) {
|
||||||
|
left = anchorRect.right + 8;
|
||||||
|
}
|
||||||
|
if (left + popover.width > vw - 8) {
|
||||||
|
left = vw - popover.width - 8;
|
||||||
|
}
|
||||||
|
let top = anchorRect.top;
|
||||||
|
if (top + popover.height > vh - 8) {
|
||||||
|
top = vh - popover.height - 8;
|
||||||
|
}
|
||||||
|
if (top < 8) top = 8;
|
||||||
|
setPos({ top, left });
|
||||||
|
}, [anchorRect]);
|
||||||
|
|
||||||
|
useClickOutside(ref, onClose);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
className="card-glow fixed z-50 max-h-[calc(100vh-16px)] w-80 max-w-[calc(100vw-16px)] overflow-y-auto rounded-lg border border-border bg-card p-4 shadow-lg"
|
||||||
|
style={pos ? { top: pos.top, left: pos.left } : { visibility: "hidden" }}
|
||||||
|
role="dialog"
|
||||||
|
aria-label={ariaLabel}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MobileSheet({
|
||||||
|
onClose,
|
||||||
|
ariaLabel,
|
||||||
|
children,
|
||||||
|
}: Readonly<Omit<DetailPopoverProps, "anchorRect">>) {
|
||||||
|
const { offsetY, isSwiping, handlers } = useSwipeToDismissDown(onClose);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const handler = (e: KeyboardEvent) => {
|
||||||
|
if (e.key === "Escape") onClose();
|
||||||
|
};
|
||||||
|
document.addEventListener("keydown", handler);
|
||||||
|
return () => document.removeEventListener("keydown", handler);
|
||||||
|
}, [onClose]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-50">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="fade-in absolute inset-0 animate-in bg-black/50"
|
||||||
|
onClick={onClose}
|
||||||
|
aria-label="Close details"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"panel-glow absolute right-0 bottom-0 left-0 max-h-[80vh] rounded-t-2xl border-border border-t bg-card",
|
||||||
|
!isSwiping && "animate-slide-in-bottom",
|
||||||
|
)}
|
||||||
|
style={
|
||||||
|
isSwiping ? { transform: `translateY(${offsetY}px)` } : undefined
|
||||||
|
}
|
||||||
|
{...handlers}
|
||||||
|
role="dialog"
|
||||||
|
aria-label={ariaLabel}
|
||||||
|
>
|
||||||
|
<div className="flex justify-center pt-2 pb-1">
|
||||||
|
<div className="h-1 w-10 rounded-full bg-muted-foreground/40" />
|
||||||
|
</div>
|
||||||
|
<div className="max-h-[calc(80vh-24px)] overflow-y-auto p-4">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DetailPopover({
|
||||||
|
anchorRect,
|
||||||
|
onClose,
|
||||||
|
ariaLabel,
|
||||||
|
children,
|
||||||
|
}: Readonly<DetailPopoverProps>) {
|
||||||
|
const [isDesktop, setIsDesktop] = useState(
|
||||||
|
() => globalThis.matchMedia("(min-width: 1024px)").matches,
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const mq = globalThis.matchMedia("(min-width: 1024px)");
|
||||||
|
const handler = (e: MediaQueryListEvent) => setIsDesktop(e.matches);
|
||||||
|
mq.addEventListener("change", handler);
|
||||||
|
return () => mq.removeEventListener("change", handler);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Portal to document.body to escape any CSS transforms on ancestors
|
||||||
|
// (the side panel uses translate-x for collapse animation, which would
|
||||||
|
// otherwise become the containing block for fixed-positioned children).
|
||||||
|
const content = isDesktop ? (
|
||||||
|
<DesktopPanel
|
||||||
|
anchorRect={anchorRect}
|
||||||
|
onClose={onClose}
|
||||||
|
ariaLabel={ariaLabel}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</DesktopPanel>
|
||||||
|
) : (
|
||||||
|
<MobileSheet onClose={onClose} ariaLabel={ariaLabel}>
|
||||||
|
{children}
|
||||||
|
</MobileSheet>
|
||||||
|
);
|
||||||
|
return createPortal(content, document.body);
|
||||||
|
}
|
||||||
72
apps/web/src/components/equipment-detail-popover.tsx
Normal file
72
apps/web/src/components/equipment-detail-popover.tsx
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import type { EquipmentItem } from "@initiative/domain";
|
||||||
|
import { DetailPopover } from "./detail-popover.js";
|
||||||
|
import { RichDescription } from "./rich-description.js";
|
||||||
|
|
||||||
|
interface EquipmentDetailPopoverProps {
|
||||||
|
readonly item: EquipmentItem;
|
||||||
|
readonly anchorRect: DOMRect;
|
||||||
|
readonly onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EquipmentDetailContent({ item }: Readonly<{ item: EquipmentItem }>) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-2 text-sm">
|
||||||
|
<h3 className="font-bold text-lg text-stat-heading">{item.name}</h3>
|
||||||
|
{item.traits && item.traits.length > 0 && (
|
||||||
|
<div className="flex flex-wrap gap-1">
|
||||||
|
{item.traits.map((t) => (
|
||||||
|
<span
|
||||||
|
key={t}
|
||||||
|
className="rounded border border-border bg-card px-1.5 py-0.5 text-foreground text-xs"
|
||||||
|
>
|
||||||
|
{t}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className="space-y-0.5 text-xs">
|
||||||
|
<div>
|
||||||
|
<span className="font-semibold">Level</span> {item.level}
|
||||||
|
</div>
|
||||||
|
{item.category ? (
|
||||||
|
<div>
|
||||||
|
<span className="font-semibold">Category</span>{" "}
|
||||||
|
{item.category.charAt(0).toUpperCase() + item.category.slice(1)}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{item.spellName ? (
|
||||||
|
<div>
|
||||||
|
<span className="font-semibold">Spell</span> {item.spellName}
|
||||||
|
{item.spellRank === undefined ? "" : ` (Rank ${item.spellRank})`}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
{item.description ? (
|
||||||
|
<RichDescription
|
||||||
|
text={item.description}
|
||||||
|
className="whitespace-pre-line text-foreground"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<p className="text-muted-foreground italic">
|
||||||
|
No description available.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EquipmentDetailPopover({
|
||||||
|
item,
|
||||||
|
anchorRect,
|
||||||
|
onClose,
|
||||||
|
}: Readonly<EquipmentDetailPopoverProps>) {
|
||||||
|
return (
|
||||||
|
<DetailPopover
|
||||||
|
anchorRect={anchorRect}
|
||||||
|
onClose={onClose}
|
||||||
|
ariaLabel={`Equipment details: ${item.name}`}
|
||||||
|
>
|
||||||
|
<EquipmentDetailContent item={item} />
|
||||||
|
</DetailPopover>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
import type { Pf2eCreature, SpellReference } from "@initiative/domain";
|
import type {
|
||||||
|
EquipmentItem,
|
||||||
|
Pf2eCreature,
|
||||||
|
SpellReference,
|
||||||
|
} from "@initiative/domain";
|
||||||
import { formatInitiativeModifier, recallKnowledge } from "@initiative/domain";
|
import { formatInitiativeModifier, recallKnowledge } from "@initiative/domain";
|
||||||
import { useCallback, useRef, useState } from "react";
|
import { useCallback, useRef, useState } from "react";
|
||||||
|
import { EquipmentDetailPopover } from "./equipment-detail-popover.js";
|
||||||
import { SpellDetailPopover } from "./spell-detail-popover.js";
|
import { SpellDetailPopover } from "./spell-detail-popover.js";
|
||||||
import {
|
import {
|
||||||
PropertyLine,
|
PropertyLine,
|
||||||
@@ -102,6 +107,35 @@ function SpellListLine({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EquipmentLinkProps {
|
||||||
|
readonly item: EquipmentItem;
|
||||||
|
readonly onOpen: (item: EquipmentItem, rect: DOMRect) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EquipmentLink({ item, onOpen }: Readonly<EquipmentLinkProps>) {
|
||||||
|
const ref = useRef<HTMLButtonElement>(null);
|
||||||
|
const handleClick = useCallback(() => {
|
||||||
|
if (!item.description) return;
|
||||||
|
const rect = ref.current?.getBoundingClientRect();
|
||||||
|
if (rect) onOpen(item, rect);
|
||||||
|
}, [item, onOpen]);
|
||||||
|
|
||||||
|
if (!item.description) {
|
||||||
|
return <span>{item.name}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
ref={ref}
|
||||||
|
type="button"
|
||||||
|
onClick={handleClick}
|
||||||
|
className="cursor-pointer text-foreground underline decoration-dotted underline-offset-2 hover:text-hover-neutral"
|
||||||
|
>
|
||||||
|
{item.name}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
|
export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
|
||||||
const [openSpell, setOpenSpell] = useState<{
|
const [openSpell, setOpenSpell] = useState<{
|
||||||
spell: SpellReference;
|
spell: SpellReference;
|
||||||
@@ -112,6 +146,15 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
const handleCloseSpell = useCallback(() => setOpenSpell(null), []);
|
const handleCloseSpell = useCallback(() => setOpenSpell(null), []);
|
||||||
|
const [openEquipment, setOpenEquipment] = useState<{
|
||||||
|
item: EquipmentItem;
|
||||||
|
rect: DOMRect;
|
||||||
|
} | null>(null);
|
||||||
|
const handleOpenEquipment = useCallback(
|
||||||
|
(item: EquipmentItem, rect: DOMRect) => setOpenEquipment({ item, rect }),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
const handleCloseEquipment = useCallback(() => setOpenEquipment(null), []);
|
||||||
|
|
||||||
const rk = recallKnowledge(creature.level, creature.traits);
|
const rk = recallKnowledge(creature.level, creature.traits);
|
||||||
|
|
||||||
@@ -256,6 +299,19 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
|
|||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{creature.equipment && creature.equipment.length > 0 && (
|
||||||
|
<>
|
||||||
|
<SectionDivider />
|
||||||
|
<h3 className="font-bold text-base text-stat-heading">Equipment</h3>
|
||||||
|
<div className="space-y-1 text-sm">
|
||||||
|
{creature.equipment.map((item) => (
|
||||||
|
<div key={item.name}>
|
||||||
|
<EquipmentLink item={item} onOpen={handleOpenEquipment} />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
{openSpell ? (
|
{openSpell ? (
|
||||||
<SpellDetailPopover
|
<SpellDetailPopover
|
||||||
spell={openSpell.spell}
|
spell={openSpell.spell}
|
||||||
@@ -263,6 +319,13 @@ export function Pf2eStatBlock({ creature }: Readonly<Pf2eStatBlockProps>) {
|
|||||||
onClose={handleCloseSpell}
|
onClose={handleCloseSpell}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
{openEquipment ? (
|
||||||
|
<EquipmentDetailPopover
|
||||||
|
item={openEquipment.item}
|
||||||
|
anchorRect={openEquipment.rect}
|
||||||
|
onClose={handleCloseEquipment}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
20
apps/web/src/components/rich-description.tsx
Normal file
20
apps/web/src/components/rich-description.tsx
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { cn } from "../lib/utils.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders text containing safe HTML formatting tags (strong, em, ul, ol, li)
|
||||||
|
* preserved by the stripFoundryTags pipeline. All other HTML is already
|
||||||
|
* stripped before reaching this component.
|
||||||
|
*/
|
||||||
|
export function RichDescription({
|
||||||
|
text,
|
||||||
|
className,
|
||||||
|
}: Readonly<{ text: string; className?: string }>) {
|
||||||
|
const props = {
|
||||||
|
className: cn(
|
||||||
|
"[&_ol]:list-decimal [&_ol]:pl-4 [&_ul]:list-disc [&_ul]:pl-4",
|
||||||
|
className,
|
||||||
|
),
|
||||||
|
dangerouslySetInnerHTML: { __html: text },
|
||||||
|
};
|
||||||
|
return <div {...props} />;
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
import type { ActivityCost, SpellReference } from "@initiative/domain";
|
import type { ActivityCost, SpellReference } from "@initiative/domain";
|
||||||
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
import { DetailPopover } from "./detail-popover.js";
|
||||||
import { createPortal } from "react-dom";
|
import { RichDescription } from "./rich-description.js";
|
||||||
import { useClickOutside } from "../hooks/use-click-outside.js";
|
|
||||||
import { useSwipeToDismissDown } from "../hooks/use-swipe-to-dismiss.js";
|
|
||||||
import { cn } from "../lib/utils.js";
|
|
||||||
import { ActivityIcon } from "./stat-block-parts.js";
|
import { ActivityIcon } from "./stat-block-parts.js";
|
||||||
|
|
||||||
interface SpellDetailPopoverProps {
|
interface SpellDetailPopoverProps {
|
||||||
@@ -138,24 +135,6 @@ function SpellMeta({ spell }: Readonly<{ spell: SpellReference }>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SAVE_OUTCOME_REGEX =
|
|
||||||
/(Critical Success|Critical Failure|Success|Failure)/g;
|
|
||||||
|
|
||||||
function SpellDescription({ text }: Readonly<{ text: string }>) {
|
|
||||||
const parts = text.split(SAVE_OUTCOME_REGEX);
|
|
||||||
const elements: React.ReactNode[] = [];
|
|
||||||
let offset = 0;
|
|
||||||
for (const part of parts) {
|
|
||||||
if (SAVE_OUTCOME_REGEX.test(part)) {
|
|
||||||
elements.push(<strong key={`b-${offset}`}>{part}</strong>);
|
|
||||||
} else if (part) {
|
|
||||||
elements.push(<span key={`t-${offset}`}>{part}</span>);
|
|
||||||
}
|
|
||||||
offset += part.length;
|
|
||||||
}
|
|
||||||
return <p className="whitespace-pre-line text-foreground">{elements}</p>;
|
|
||||||
}
|
|
||||||
|
|
||||||
function SpellDetailContent({ spell }: Readonly<{ spell: SpellReference }>) {
|
function SpellDetailContent({ spell }: Readonly<{ spell: SpellReference }>) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2 text-sm">
|
<div className="space-y-2 text-sm">
|
||||||
@@ -163,107 +142,21 @@ function SpellDetailContent({ spell }: Readonly<{ spell: SpellReference }>) {
|
|||||||
<SpellTraits traits={spell.traits ?? []} />
|
<SpellTraits traits={spell.traits ?? []} />
|
||||||
<SpellMeta spell={spell} />
|
<SpellMeta spell={spell} />
|
||||||
{spell.description ? (
|
{spell.description ? (
|
||||||
<SpellDescription text={spell.description} />
|
<RichDescription
|
||||||
|
text={spell.description}
|
||||||
|
className="whitespace-pre-line text-foreground"
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<p className="text-muted-foreground italic">
|
<p className="text-muted-foreground italic">
|
||||||
No description available.
|
No description available.
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
{spell.heightening ? (
|
{spell.heightening ? (
|
||||||
<p className="whitespace-pre-line text-foreground text-xs">
|
<RichDescription
|
||||||
{spell.heightening}
|
text={spell.heightening}
|
||||||
</p>
|
className="whitespace-pre-line text-foreground text-xs"
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function DesktopPopover({
|
|
||||||
spell,
|
|
||||||
anchorRect,
|
|
||||||
onClose,
|
|
||||||
}: Readonly<SpellDetailPopoverProps>) {
|
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
|
||||||
const [pos, setPos] = useState<{ top: number; left: number } | null>(null);
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
|
||||||
const el = ref.current;
|
|
||||||
if (!el) return;
|
|
||||||
const popover = el.getBoundingClientRect();
|
|
||||||
const vw = document.documentElement.clientWidth;
|
|
||||||
const vh = document.documentElement.clientHeight;
|
|
||||||
// Prefer placement to the LEFT of the anchor (panel is on the right edge)
|
|
||||||
let left = anchorRect.left - popover.width - 8;
|
|
||||||
if (left < 8) {
|
|
||||||
left = anchorRect.right + 8;
|
|
||||||
}
|
|
||||||
if (left + popover.width > vw - 8) {
|
|
||||||
left = vw - popover.width - 8;
|
|
||||||
}
|
|
||||||
let top = anchorRect.top;
|
|
||||||
if (top + popover.height > vh - 8) {
|
|
||||||
top = vh - popover.height - 8;
|
|
||||||
}
|
|
||||||
if (top < 8) top = 8;
|
|
||||||
setPos({ top, left });
|
|
||||||
}, [anchorRect]);
|
|
||||||
|
|
||||||
useClickOutside(ref, onClose);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
ref={ref}
|
|
||||||
className="card-glow fixed z-50 max-h-[calc(100vh-16px)] w-80 max-w-[calc(100vw-16px)] overflow-y-auto rounded-lg border border-border bg-card p-4 shadow-lg"
|
|
||||||
style={pos ? { top: pos.top, left: pos.left } : { visibility: "hidden" }}
|
|
||||||
role="dialog"
|
|
||||||
aria-label={`Spell details: ${spell.name}`}
|
|
||||||
>
|
|
||||||
<SpellDetailContent spell={spell} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function MobileSheet({
|
|
||||||
spell,
|
|
||||||
onClose,
|
|
||||||
}: Readonly<{ spell: SpellReference; onClose: () => void }>) {
|
|
||||||
const { offsetY, isSwiping, handlers } = useSwipeToDismissDown(onClose);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const handler = (e: KeyboardEvent) => {
|
|
||||||
if (e.key === "Escape") onClose();
|
|
||||||
};
|
|
||||||
document.addEventListener("keydown", handler);
|
|
||||||
return () => document.removeEventListener("keydown", handler);
|
|
||||||
}, [onClose]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="fixed inset-0 z-50">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="fade-in absolute inset-0 animate-in bg-black/50"
|
|
||||||
onClick={onClose}
|
|
||||||
aria-label="Close spell details"
|
|
||||||
/>
|
/>
|
||||||
<div
|
) : null}
|
||||||
className={cn(
|
|
||||||
"panel-glow absolute right-0 bottom-0 left-0 max-h-[80vh] rounded-t-2xl border-border border-t bg-card",
|
|
||||||
!isSwiping && "animate-slide-in-bottom",
|
|
||||||
)}
|
|
||||||
style={
|
|
||||||
isSwiping ? { transform: `translateY(${offsetY}px)` } : undefined
|
|
||||||
}
|
|
||||||
{...handlers}
|
|
||||||
role="dialog"
|
|
||||||
aria-label={`Spell details: ${spell.name}`}
|
|
||||||
>
|
|
||||||
<div className="flex justify-center pt-2 pb-1">
|
|
||||||
<div className="h-1 w-10 rounded-full bg-muted-foreground/40" />
|
|
||||||
</div>
|
|
||||||
<div className="max-h-[calc(80vh-24px)] overflow-y-auto p-4">
|
|
||||||
<SpellDetailContent spell={spell} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -273,24 +166,13 @@ export function SpellDetailPopover({
|
|||||||
anchorRect,
|
anchorRect,
|
||||||
onClose,
|
onClose,
|
||||||
}: Readonly<SpellDetailPopoverProps>) {
|
}: Readonly<SpellDetailPopoverProps>) {
|
||||||
const [isDesktop, setIsDesktop] = useState(
|
return (
|
||||||
() => globalThis.matchMedia("(min-width: 1024px)").matches,
|
<DetailPopover
|
||||||
|
anchorRect={anchorRect}
|
||||||
|
onClose={onClose}
|
||||||
|
ariaLabel={`Spell details: ${spell.name}`}
|
||||||
|
>
|
||||||
|
<SpellDetailContent spell={spell} />
|
||||||
|
</DetailPopover>
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const mq = globalThis.matchMedia("(min-width: 1024px)");
|
|
||||||
const handler = (e: MediaQueryListEvent) => setIsDesktop(e.matches);
|
|
||||||
mq.addEventListener("change", handler);
|
|
||||||
return () => mq.removeEventListener("change", handler);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Portal to document.body to escape any CSS transforms on ancestors
|
|
||||||
// (the side panel uses translate-x for collapse animation, which would
|
|
||||||
// otherwise become the containing block for fixed-positioned children).
|
|
||||||
const content = isDesktop ? (
|
|
||||||
<DesktopPopover spell={spell} anchorRect={anchorRect} onClose={onClose} />
|
|
||||||
) : (
|
|
||||||
<MobileSheet spell={spell} onClose={onClose} />
|
|
||||||
);
|
|
||||||
return createPortal(content, document.body);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type {
|
|||||||
TraitBlock,
|
TraitBlock,
|
||||||
TraitSegment,
|
TraitSegment,
|
||||||
} from "@initiative/domain";
|
} from "@initiative/domain";
|
||||||
|
import { RichDescription } from "./rich-description.js";
|
||||||
|
|
||||||
export function PropertyLine({
|
export function PropertyLine({
|
||||||
label,
|
label,
|
||||||
@@ -39,20 +40,22 @@ function TraitSegments({
|
|||||||
{segments.map((seg, i) => {
|
{segments.map((seg, i) => {
|
||||||
if (seg.type === "text") {
|
if (seg.type === "text") {
|
||||||
return (
|
return (
|
||||||
<span key={segmentKey(seg)}>
|
<RichDescription
|
||||||
{i === 0 ? ` ${seg.value}` : seg.value}
|
key={segmentKey(seg)}
|
||||||
</span>
|
text={i === 0 ? ` ${seg.value}` : seg.value}
|
||||||
|
className="inline whitespace-pre-line"
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div key={segmentKey(seg)} className="mt-1 space-y-0.5">
|
<div key={segmentKey(seg)} className="mt-1 space-y-0.5">
|
||||||
{seg.items.map((item) => (
|
{seg.items.map((item) => (
|
||||||
<p key={item.label ?? item.text}>
|
<div key={item.label ?? item.text}>
|
||||||
{item.label != null && (
|
{item.label != null && (
|
||||||
<span className="font-semibold">{item.label}. </span>
|
<span className="font-semibold">{item.label}. </span>
|
||||||
)}
|
)}
|
||||||
{item.text}
|
<RichDescription text={item.text} className="inline" />
|
||||||
</p>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -86,6 +86,19 @@ export interface SpellReference {
|
|||||||
readonly usesPerDay?: number;
|
readonly usesPerDay?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A carried equipment item on a PF2e creature (weapon, consumable, magic item, etc.). */
|
||||||
|
export interface EquipmentItem {
|
||||||
|
readonly name: string;
|
||||||
|
readonly level: number;
|
||||||
|
readonly category?: string;
|
||||||
|
readonly traits?: readonly string[];
|
||||||
|
readonly description?: string;
|
||||||
|
/** For scrolls/wands: the embedded spell name. */
|
||||||
|
readonly spellName?: string;
|
||||||
|
/** For scrolls/wands: the embedded spell rank. */
|
||||||
|
readonly spellRank?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DailySpells {
|
export interface DailySpells {
|
||||||
readonly uses: number;
|
readonly uses: number;
|
||||||
readonly each: boolean;
|
readonly each: boolean;
|
||||||
@@ -201,6 +214,7 @@ export interface Pf2eCreature {
|
|||||||
readonly abilitiesMid?: readonly TraitBlock[];
|
readonly abilitiesMid?: readonly TraitBlock[];
|
||||||
readonly abilitiesBot?: readonly TraitBlock[];
|
readonly abilitiesBot?: readonly TraitBlock[];
|
||||||
readonly spellcasting?: readonly SpellcastingBlock[];
|
readonly spellcasting?: readonly SpellcastingBlock[];
|
||||||
|
readonly equipment?: readonly EquipmentItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AnyCreature = Creature | Pf2eCreature;
|
export type AnyCreature = Creature | Pf2eCreature;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export {
|
|||||||
type CreatureId,
|
type CreatureId,
|
||||||
creatureId,
|
creatureId,
|
||||||
type DailySpells,
|
type DailySpells,
|
||||||
|
type EquipmentItem,
|
||||||
type LegendaryBlock,
|
type LegendaryBlock,
|
||||||
type Pf2eBestiaryIndex,
|
type Pf2eBestiaryIndex,
|
||||||
type Pf2eBestiaryIndexEntry,
|
type Pf2eBestiaryIndexEntry,
|
||||||
|
|||||||
@@ -108,10 +108,15 @@ As a DM running a PF2e encounter, I want to see the Recall Knowledge DC and asso
|
|||||||
|
|
||||||
The Recall Knowledge line appears below the trait tags, showing the DC (calculated from the creature's level using the PF2e standard DC-by-level table, adjusted for rarity) and the skill determined by the creature's type trait. The line is omitted for creatures with no recognized type trait and never shown for D&D creatures.
|
The Recall Knowledge line appears below the trait tags, showing the DC (calculated from the creature's level using the PF2e standard DC-by-level table, adjusted for rarity) and the skill determined by the creature's type trait. The line is omitted for creatures with no recognized type trait and never shown for D&D creatures.
|
||||||
|
|
||||||
|
**US-D6 — View NPC Equipment and Consumables (P2)**
|
||||||
|
As a DM running a PF2e encounter, I want to see a creature's carried equipment — magic weapons, potions, scrolls, wands, and other items — displayed on its stat block so I can use these tactical options in combat without consulting external tools.
|
||||||
|
|
||||||
|
An "Equipment" section appears on the stat block listing each carried item with its name and relevant details (level, traits, activation description). Scrolls additionally show the embedded spell name and rank (e.g., "Scroll of Teleport (Rank 6)"). The section is omitted entirely for creatures that carry no equipment. Equipment data is extracted from the existing cached creature JSON — no additional fetch is required.
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
- **FR-016**: The system MUST display a stat block panel with full creature information when a creature is selected.
|
- **FR-016**: The system MUST display a stat block panel with full creature information when a creature is selected.
|
||||||
- **FR-017**: For D&D creatures, the stat block MUST include: name, size, type, alignment, AC (with armor source if applicable), HP (average + formula), speed, ability scores with modifiers, saving throws, skills, damage vulnerabilities, damage resistances, damage immunities, condition immunities, senses, languages, challenge rating, proficiency bonus, passive perception, traits, actions, bonus actions, reactions, spellcasting, and legendary actions. For PF2e creatures, the stat block MUST include: name, level, traits (as tags), Perception and senses, languages, skills, ability modifiers (Str/Dex/Con/Int/Wis/Cha as modifiers, not scores), items, AC, saving throws (Fort/Ref/Will), HP (with optional immunities/resistances/weaknesses), speed, attacks, top abilities, mid abilities (reactions/auras), bot abilities (active), and spellcasting.
|
- **FR-017**: For D&D creatures, the stat block MUST include: name, size, type, alignment, AC (with armor source if applicable), HP (average + formula), speed, ability scores with modifiers, saving throws, skills, damage vulnerabilities, damage resistances, damage immunities, condition immunities, senses, languages, challenge rating, proficiency bonus, passive perception, traits, actions, bonus actions, reactions, spellcasting, and legendary actions. For PF2e creatures, the stat block MUST include: name, level, traits (as tags), Perception and senses, languages, skills, ability modifiers (Str/Dex/Con/Int/Wis/Cha as modifiers, not scores), items, AC, saving throws (Fort/Ref/Will), HP (with optional immunities/resistances/weaknesses), speed, attacks, top abilities, mid abilities (reactions/auras), bot abilities (active), spellcasting, and equipment (weapons, consumables, and other carried items).
|
||||||
- **FR-018**: Optional stat block sections (traits, legendary actions, bonus actions, reactions, etc.) MUST be omitted entirely when the creature has none.
|
- **FR-018**: Optional stat block sections (traits, legendary actions, bonus actions, reactions, etc.) MUST be omitted entirely when the creature has none.
|
||||||
- **FR-019**: The system MUST strip bestiary markup tags (spell references, dice notation, attack tags) and render them as plain readable text (e.g., `{@spell fireball|XPHB}` -> "fireball", `{@dice 3d6}` -> "3d6").
|
- **FR-019**: The system MUST strip bestiary markup tags (spell references, dice notation, attack tags) and render them as plain readable text (e.g., `{@spell fireball|XPHB}` -> "fireball", `{@dice 3d6}` -> "3d6").
|
||||||
- **FR-020**: On wide viewports (desktop), the layout MUST be side-by-side with the encounter tracker on the left and stat block on the right.
|
- **FR-020**: On wide viewports (desktop), the layout MUST be side-by-side with the encounter tracker on the left and stat block on the right.
|
||||||
@@ -157,6 +162,11 @@ The Recall Knowledge line appears below the trait tags, showing the DC (calculat
|
|||||||
19. **Given** a PF2e creature with rare rarity is displayed, **When** the DM views the stat block, **Then** the Recall Knowledge DC is the standard DC for its level +5.
|
19. **Given** a PF2e creature with rare rarity is displayed, **When** the DM views the stat block, **Then** the Recall Knowledge DC is the standard DC for its level +5.
|
||||||
20. **Given** a PF2e creature with the "Undead" type trait is displayed, **When** the DM views the stat block, **Then** the Recall Knowledge line shows "Religion" as the associated skill.
|
20. **Given** a PF2e creature with the "Undead" type trait is displayed, **When** the DM views the stat block, **Then** the Recall Knowledge line shows "Religion" as the associated skill.
|
||||||
21. **Given** a D&D creature is displayed, **When** the DM views the stat block, **Then** no Recall Knowledge line is shown.
|
21. **Given** a D&D creature is displayed, **When** the DM views the stat block, **Then** no Recall Knowledge line is shown.
|
||||||
|
22. **Given** a PF2e creature carrying a Staff of Fire and an Invisibility Potion is displayed, **When** the DM views the stat block, **Then** an "Equipment" section appears listing both items with their names and relevant details.
|
||||||
|
23. **Given** a PF2e creature carrying a Scroll of Teleport Rank 6 is displayed, **When** the DM views the stat block, **Then** the Equipment section shows the scroll with the embedded spell name and rank (e.g., "Scroll of Teleport (Rank 6)").
|
||||||
|
24. **Given** a PF2e creature with no equipment items is displayed, **When** the DM views the stat block, **Then** no Equipment section is shown.
|
||||||
|
25. **Given** a PF2e creature with equipment is displayed, **When** the DM views the stat block, **Then** equipment item descriptions have HTML tags stripped and render as plain readable text.
|
||||||
|
26. **Given** a D&D creature is displayed, **When** the DM views the stat block, **Then** no Equipment section is shown (equipment display is PF2e-only).
|
||||||
|
|
||||||
### Edge Cases
|
### Edge Cases
|
||||||
|
|
||||||
@@ -164,6 +174,8 @@ The Recall Knowledge line appears below the trait tags, showing the DC (calculat
|
|||||||
- Very long content (e.g., a Lich with extensive spellcasting): the stat block panel scrolls independently of the encounter tracker.
|
- Very long content (e.g., a Lich with extensive spellcasting): the stat block panel scrolls independently of the encounter tracker.
|
||||||
- Viewport resized from wide to narrow while stat block is open: the layout transitions from panel to drawer.
|
- Viewport resized from wide to narrow while stat block is open: the layout transitions from panel to drawer.
|
||||||
- Embedded spell item missing description text: the popover/sheet shows the available metadata (level, traits, range, etc.) and a placeholder note for the missing description.
|
- Embedded spell item missing description text: the popover/sheet shows the available metadata (level, traits, range, etc.) and a placeholder note for the missing description.
|
||||||
|
- Scroll item with missing or empty `system.spell` data: the scroll is displayed by name only, without spell name or rank.
|
||||||
|
- Equipment item with empty description: the item is displayed with its name and metadata (level, traits) but no description text.
|
||||||
- Cached source data from before the spell description feature was added: existing cached entries lack the new per-spell data fields. The IndexedDB schema version MUST be bumped to invalidate old caches and trigger re-fetch (re-normalization from raw Foundry data is not possible because the original raw JSON is not retained).
|
- Cached source data from before the spell description feature was added: existing cached entries lack the new per-spell data fields. The IndexedDB schema version MUST be bumped to invalidate old caches and trigger re-fetch (re-normalization from raw Foundry data is not possible because the original raw JSON is not retained).
|
||||||
- Creature with no recognized type trait (e.g., a creature whose only traits are not in the type-to-skill mapping): the Recall Knowledge line is omitted entirely.
|
- Creature with no recognized type trait (e.g., a creature whose only traits are not in the type-to-skill mapping): the Recall Knowledge line is omitted entirely.
|
||||||
- Creature with a type trait that maps to multiple skills (e.g., Beast → Arcana/Nature): both skills are shown.
|
- Creature with a type trait that maps to multiple skills (e.g., Beast → Arcana/Nature): both skills are shown.
|
||||||
@@ -233,6 +245,11 @@ A DM wants to see which sources are cached, find a specific source, clear a spec
|
|||||||
- **FR-087**: The Recall Knowledge skill MUST be derived from the creature's type trait using the standard PF2e mapping (e.g., Aberration → Occultism, Animal → Nature, Astral → Occultism, Beast → Arcana/Nature, Celestial → Religion, Construct → Arcana/Crafting, Dragon → Arcana, Dream → Occultism, Elemental → Arcana/Nature, Ethereal → Occultism, Fey → Nature, Fiend → Religion, Fungus → Nature, Giant → Society, Humanoid → Society, Monitor → Religion, Ooze → Occultism, Plant → Nature, Undead → Religion).
|
- **FR-087**: The Recall Knowledge skill MUST be derived from the creature's type trait using the standard PF2e mapping (e.g., Aberration → Occultism, Animal → Nature, Astral → Occultism, Beast → Arcana/Nature, Celestial → Religion, Construct → Arcana/Crafting, Dragon → Arcana, Dream → Occultism, Elemental → Arcana/Nature, Ethereal → Occultism, Fey → Nature, Fiend → Religion, Fungus → Nature, Giant → Society, Humanoid → Society, Monitor → Religion, Ooze → Occultism, Plant → Nature, Undead → Religion).
|
||||||
- **FR-088**: Creatures with no recognized type trait MUST omit the Recall Knowledge line entirely rather than showing incorrect data.
|
- **FR-088**: Creatures with no recognized type trait MUST omit the Recall Knowledge line entirely rather than showing incorrect data.
|
||||||
- **FR-089**: The Recall Knowledge line MUST NOT be shown for D&D creatures.
|
- **FR-089**: The Recall Knowledge line MUST NOT be shown for D&D creatures.
|
||||||
|
- **FR-090**: The PF2e normalization pipeline MUST extract `weapon` and `consumable` item types from the Foundry VTT `items[]` array, in addition to the existing `melee`, `action`, `spell`, and `spellcastingEntry` types. Each extracted equipment item MUST include name, level, traits, and description text.
|
||||||
|
- **FR-091**: PF2e stat blocks MUST display an "Equipment" section listing all extracted equipment items. Each item MUST show its name and relevant details (e.g., level, traits, activation description).
|
||||||
|
- **FR-092**: For scroll items, the stat block MUST display the embedded spell name and rank derived from the `system.spell` data on the item (e.g., "Scroll of Teleport (Rank 6)").
|
||||||
|
- **FR-093**: The Equipment section MUST be omitted entirely when the creature has no equipment items, consistent with FR-018 (optional sections omitted when empty).
|
||||||
|
- **FR-094**: Equipment item descriptions MUST be processed through the existing Foundry tag-stripping utility before display, consistent with FR-068 and FR-081.
|
||||||
|
|
||||||
### Acceptance Scenarios
|
### Acceptance Scenarios
|
||||||
|
|
||||||
@@ -334,7 +351,7 @@ As a DM with a creature pinned, I want to collapse the right (browse) panel inde
|
|||||||
- **Search Index (D&D)** (`BestiaryIndex`): Pre-shipped lightweight dataset keyed by name + source, containing mechanical facts (name, source code, AC, HP average, DEX score, CR, initiative proficiency multiplier, size, type) for all creatures. Sufficient for adding combatants; insufficient for rendering a full stat block.
|
- **Search Index (D&D)** (`BestiaryIndex`): Pre-shipped lightweight dataset keyed by name + source, containing mechanical facts (name, source code, AC, HP average, DEX score, CR, initiative proficiency multiplier, size, type) for all creatures. Sufficient for adding combatants; insufficient for rendering a full stat block.
|
||||||
- **Search Index (PF2e)** (`Pf2eBestiaryIndex`): Pre-shipped lightweight dataset for PF2e creatures, containing name, source code, AC, HP, level, Perception modifier, size, and creature type. Parallel to the D&D search index but with PF2e-specific fields (level instead of CR, Perception instead of DEX/proficiency).
|
- **Search Index (PF2e)** (`Pf2eBestiaryIndex`): Pre-shipped lightweight dataset for PF2e creatures, containing name, source code, AC, HP, level, Perception modifier, size, and creature type. Parallel to the D&D search index but with PF2e-specific fields (level instead of CR, Perception instead of DEX/proficiency).
|
||||||
- **Source** (`BestiarySource`): A D&D or PF2e publication identified by a code (e.g., "XMM") with a display name (e.g., "Monster Manual (2025)"). Caching and fetching operate at the source level.
|
- **Source** (`BestiarySource`): A D&D or PF2e publication identified by a code (e.g., "XMM") with a display name (e.g., "Monster Manual (2025)"). Caching and fetching operate at the source level.
|
||||||
- **Creature (Full)** (`Creature`): A complete creature record with all stat block data (traits, actions, legendary actions, spellcasting, etc.), available only after source data is fetched/uploaded and cached. Identified by a branded `CreatureId`. For PF2e creatures, each spell entry inside `spellcasting` carries full per-spell data (slug, level, traits, range, action cost, target/area, duration, defense, description, heightening) extracted from the embedded `items[type=spell]` data on the source NPC, enabling inline spell description display without additional fetches.
|
- **Creature (Full)** (`Creature`): A complete creature record with all stat block data (traits, actions, legendary actions, spellcasting, etc.), available only after source data is fetched/uploaded and cached. Identified by a branded `CreatureId`. For PF2e creatures, each spell entry inside `spellcasting` carries full per-spell data (slug, level, traits, range, action cost, target/area, duration, defense, description, heightening) extracted from the embedded `items[type=spell]` data on the source NPC, enabling inline spell description display without additional fetches. PF2e creatures also carry an `equipment` list of carried items (weapons, consumables) extracted from `items[type=weapon]` and `items[type=consumable]` entries, each with name, level, traits, description, and (for scrolls) embedded spell data.
|
||||||
- **Cached Source Data**: The full normalized bestiary data for a single source, stored in IndexedDB. Contains complete creature stat blocks.
|
- **Cached Source Data**: The full normalized bestiary data for a single source, stored in IndexedDB. Contains complete creature stat blocks.
|
||||||
- **Combatant** (extended): Gains an optional `creatureId` reference to a `Creature`, enabling stat block lookup and stat pre-fill on creation.
|
- **Combatant** (extended): Gains an optional `creatureId` reference to a `Creature`, enabling stat block lookup and stat pre-fill on creation.
|
||||||
- **Queued Creature**: Transient UI-only state representing a bestiary creature selected for batch-add, containing the creature reference and a count (1+). Not persisted.
|
- **Queued Creature**: Transient UI-only state representing a bestiary creature selected for batch-add, containing the creature reference and a count (1+). Not persisted.
|
||||||
|
|||||||
Reference in New Issue
Block a user