1
0
Fork 0
polaris-task-force/src/components/frontend/personnel/NpcCard.tsx
Z8MB1E 2a3ad57bce feat(npc): add weighted activity, level, and dialogue conversations
- GameNpcs: Narrative Activity group (weighted options, forced flag,
  configurable reshuffle interval), level + richText levelDescription,
  canMessage toggle
- New npc-dialogues collection with a purpose-built React Flow dialogue
  editor (dialogue/choice/event/end nodes) in the admin panel
- Frontend: Currently-activity line and level description on the contact
  profile page; NpcConversation messaging surface with a documented
  (disabled) LLM extension seam
- Permissions: npc-dialogues CRUD + admin manage in a new NPC Dialogue
  group; event types for dialogue triggers
- Migration 20261006_000000 (applied to dev DB) with full schema
  snapshot sidecar
2026-10-05 12:51:59 -04:00

123 lines
5.1 KiB
TypeScript

"use client";
import Link from "next/link";
import type { GameNpc } from "@/payload-types";
import { cn } from "@/lib/utils";
import { ClassificationStrip, CornerBrackets, DOSSIER, type ReadoutCell } from "@/components/frontend/operations";
import { NpcStatusChips } from "@/components/frontend/personnel/NpcStatusChips";
import { initialsOf } from "@/components/frontend/personnel/initials";
interface NpcCardProps {
readonly npc: GameNpc;
}
export function NpcCard({ npc }: NpcCardProps) {
const factionName =
typeof npc.faction === "object" && npc.faction !== null ? npc.faction.name : null;
const locationName =
typeof npc.location === "object" && npc.location !== null ? npc.location.name : null;
const vendorEnabled = npc.vendor?.enabled === true;
const goodsCount = (npc.vendor?.sells ?? []).length;
const imageUrl =
typeof npc.image === "object" && npc.image !== null ? (npc.image.url ?? null) : null;
const refCode = String(npc.id).padStart(3, "0");
const monogram = initialsOf(npc.name);
const readoutCells: ReadoutCell[] = [
{ label: "Faction", value: factionName ?? "Unaffiliated" },
{ label: "Station", value: locationName ?? "Unknown" },
{ label: "Goods", value: vendorEnabled ? goodsCount.toString() : "-", mono: true },
];
return (
<Link
href={`/personnel/contacts/${npc.id}`}
aria-label={`Open contact ${npc.name}`}
className="block rounded-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
>
<article className="group relative flex aspect-[4/5] flex-col overflow-hidden rounded-none border border-border/70 bg-card transition-colors duration-300 hover:border-foreground/30 motion-reduce:transition-none">
<div className="relative z-20 shrink-0">
<ClassificationStrip left="Contact" right={`REF ${refCode}`} />
</div>
<div className="relative min-h-0 flex-1 overflow-hidden">
{imageUrl ? (
<img src={imageUrl} alt="" className="absolute inset-0 size-full object-cover" />
) : (
<>
<div className="absolute inset-0 bg-gradient-to-br from-muted/40 via-card to-black/40" />
<div className="absolute inset-0 flex items-center justify-center">
<span className="select-none font-mono text-[3rem] font-bold leading-none tracking-tighter text-white/[0.06] transition-opacity duration-500 group-hover:text-white/[0.1] motion-reduce:transition-none">
{monogram}
</span>
</div>
</>
)}
<div
aria-hidden="true"
className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/55 to-black/25"
/>
<div className="relative z-10 flex h-full items-center justify-center px-3 text-center">
<div className="flex max-w-full flex-col items-center gap-1">
<h2
data-text={npc.name}
className="glitch-hover text-balance text-center text-sm font-bold leading-tight text-white drop-shadow-lg"
>
{npc.name}
<span aria-hidden="true" className="glitch-ghost glitch-shard-a">
{npc.name}
</span>
<span aria-hidden="true" className="glitch-ghost glitch-shard-b">
{npc.name}
</span>
<span aria-hidden="true" className="glitch-ghost glitch-shard-c">
{npc.name}
</span>
</h2>
<p className="glitch-soft line-clamp-1 max-w-full text-pretty text-[10px] text-white/60 drop-shadow">
{npc.occupation ?? "Occupation not recorded"}
</p>
<NpcStatusChips npc={npc} size="compact" className="justify-center" />
</div>
</div>
</div>
<div className="relative z-20 shrink-0">
<footer className="flex items-stretch border-t border-white/15 bg-black/60 px-1 py-1 backdrop-blur-sm">
{readoutCells.map((cell, index) => (
<div
key={cell.label}
className={cn(
"flex min-w-0 flex-1 flex-col items-center justify-center px-1",
index < readoutCells.length - 1 && "border-r border-white/15",
)}
>
<span
className={cn(
"w-full truncate text-center text-[10px] text-white/80",
cell.mono && "font-mono tabular-nums",
)}
>
{cell.value}
</span>
<span className="text-[7px] uppercase tracking-widest text-white/40">
{cell.label}
</span>
</div>
))}
</footer>
</div>
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 z-[5] opacity-[0.04]"
style={DOSSIER.gridTexture}
/>
<CornerBrackets />
</article>
</Link>
);
}