1
0
Fork 0

feat(personnel): add NPC portraits and rich bio, redesign contact cards

Game NPCs gain an image upload and a Lexical rich-text bio (with data
migration that wraps existing plain text in a paragraph). NPC profile, card
and directory surface the portrait, a status-chip row and initials fallback;
contacts list and detail pages adopt the redesigned cards.
This commit is contained in:
Jason Fraley 2026-10-05 03:22:11 -04:00
parent 4755cb681a
commit 755bd04875
12 changed files with 74166 additions and 193 deletions

View file

@ -150,23 +150,24 @@ export default async function NpcContactPage({ params }: NpcContactPageProps) {
const listings = listingsRes.docs as unknown as MarketListing[];
return (
<div className="grid gap-6 lg:grid-cols-2">
<div className="lg:col-span-2">
<NpcProfile npc={npc} listings={listings} />
</div>
<div className="px-5 pb-5 lg:col-start-2">
<EmploymentCard
employment={employment}
structures={structures}
canManage={canManage}
npcId={npc.id}
npcName={npc.name}
classifications={classifications}
hiringEnabled={Boolean(rules.staffHiringEnabled)}
hiringDisabledMessage={rules.staffHiringDisabledMessage ?? undefined}
currencyConfig={currencyConfig}
/>
</div>
<div className="p-5">
<NpcProfile
npc={npc}
listings={listings}
employmentSlot={
<EmploymentCard
employment={employment}
structures={structures}
canManage={canManage}
npcId={npc.id}
npcName={npc.name}
classifications={classifications}
hiringEnabled={Boolean(rules.staffHiringEnabled)}
hiringDisabledMessage={rules.staffHiringDisabledMessage ?? undefined}
currencyConfig={currencyConfig}
/>
}
/>
</div>
);
}

View file

@ -3,6 +3,11 @@ import { getPayload } from "payload";
import type { GameNpc } from "@/payload-types";
import { UsersIcon } from "lucide-react";
import { NpcDirectory } from "@/components/frontend/personnel/NpcDirectory";
import {
ClassificationStrip,
CornerBrackets,
DOSSIER,
} from "@/components/frontend/operations";
export const metadata = {
title: "Contacts: Polaris Task Force",
@ -19,15 +24,28 @@ export default async function ContactsPage() {
return (
<div className="flex flex-col gap-6 p-5">
<div className="flex flex-col gap-1">
<div className="flex items-center gap-2">
<UsersIcon className="size-5 text-muted-foreground" />
<h1 className="text-lg font-semibold">Contacts</h1>
<header className="group relative overflow-hidden rounded-none border border-border/70 bg-card">
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 z-[5] opacity-[0.04]"
style={DOSSIER.gridTexture}
/>
<ClassificationStrip
left="Theater Contacts // Personnel"
right={`${npcs.length} Recorded`}
/>
<CornerBrackets />
<div className="relative z-10 flex items-center gap-3 px-5 py-4">
<UsersIcon className="size-5 shrink-0 text-white/50" />
<div className="flex flex-col gap-0.5">
<h1 className="text-xl font-bold tracking-tight text-white">Contacts</h1>
<p className="text-sm text-white/60">
{npcs.length} contact{npcs.length !== 1 ? "s" : ""} recorded in the theater of
operations.
</p>
</div>
</div>
<p className="text-sm text-muted-foreground">
{npcs.length} contact{npcs.length !== 1 ? "s" : ""} recorded in the theater of operations.
</p>
</div>
</header>
<NpcDirectory npcs={npcs} />
</div>

View file

@ -25,6 +25,15 @@ export const GameNpcs: CollectionConfig = {
description: "The NPC's name as shown in-game and on the frontend.",
},
},
{
name: "image",
type: "upload",
relationTo: "media",
admin: {
description:
"Portrait/photo for this contact. Shown on the contacts directory and profile when set.",
},
},
{
name: "occupation",
type: "text",
@ -50,7 +59,7 @@ export const GameNpcs: CollectionConfig = {
},
{
name: "bio",
type: "textarea",
type: "richText",
admin: {
description: "A short background/profile for this NPC.",
},

View file

@ -2,8 +2,10 @@
import Link from "next/link";
import type { GameNpc } from "@/payload-types";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
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;
@ -12,40 +14,110 @@ interface NpcCardProps {
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}`} className="block h-full">
<Card className="h-full transition-colors hover:bg-accent/50">
<CardHeader className="gap-2">
<CardTitle className="text-base">{npc.name}</CardTitle>
<p className="text-sm text-muted-foreground">
{npc.occupation ?? "Occupation not recorded"}
</p>
<div className="flex flex-wrap items-center gap-1.5">
{npc.isInGame === true && (
<Badge variant="secondary" className="border-emerald-500/30 text-emerald-500">
In Game
</Badge>
)}
{npc.isGenerated === true && (
<Badge variant="outline" className="border-amber-500/40 text-amber-500">
Generated
</Badge>
)}
{npc.vendor?.enabled === true && (
<Badge variant="outline" className="border-violet-500/40 text-violet-500">
Vendor
</Badge>
)}
<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.5">
<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="mt-0.5 justify-center" />
</div>
</div>
</CardHeader>
<CardContent className="flex flex-col gap-2 text-sm">
<div className="flex items-center justify-between gap-3">
<span className="text-muted-foreground">Faction</span>
<span className="truncate text-right">{factionName ?? "Unaffiliated"}</span>
</div>
</CardContent>
</Card>
</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>
);
}

View file

@ -3,13 +3,12 @@
import { useMemo, useState } from "react";
import { SearchIcon } from "lucide-react";
import type { GameNpc } from "@/payload-types";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { cn } from "@/lib/utils";
import { NpcCard } from "@/components/frontend/personnel/NpcCard";
import { DOSSIER, NoticeState } from "@/components/frontend/operations";
interface NpcDirectoryProps {
readonly npcs: GameNpc[];
@ -94,30 +93,29 @@ export function NpcDirectory({ npcs }: NpcDirectoryProps) {
</fieldset>
</div>
<Badge variant="outline" className="w-fit">
<span className={cn("w-fit", DOSSIER.chip)}>
{filteredNpcs.length} of {npcs.length}
</Badge>
</span>
</div>
{filteredNpcs.length === 0 ? (
<Card>
<CardContent className="flex flex-col gap-1 p-6">
<p className="font-semibold">
{npcs.length === 0
? "No contacts have been added."
: hasFilters
? "No contacts match those filters."
: "No contacts found."}
</p>
<p className="text-sm text-muted-foreground">
{npcs.length === 0
? "NPC records will appear here as the theater develops."
: "Try a different search or clear one of the filters."}
</p>
</CardContent>
</Card>
<NoticeState
variant="empty"
message={
npcs.length === 0
? "No contacts have been added."
: hasFilters
? "No contacts match those filters."
: "No contacts found."
}
hint={
npcs.length === 0
? "NPC records will appear here as the theater develops."
: "Try a different search or clear one of the filters."
}
/>
) : (
<div className="grid grid-cols-1 gap-3 md:grid-cols-2 lg:grid-cols-3">
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6">
{filteredNpcs.map((npc) => (
<NpcCard key={npc.id} npc={npc} />
))}

View file

@ -1,53 +1,71 @@
"use client";
import { Fragment } from "react";
import { Fragment, type ComponentType, type ReactNode } from "react";
import Link from "next/link";
import { ArrowLeftIcon, MapPinIcon, ShieldIcon, StoreIcon } from "lucide-react";
import { RichText } from "@payloadcms/richtext-lexical/react";
import type { Asset, GameNpc, MarketListing } from "@/payload-types";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import {
ClassificationStrip,
CornerBrackets,
DOSSIER,
LedgerRow,
StrategicSummary,
type ReadoutCell,
} from "@/components/frontend/operations";
import { CurrencyAmount } from "@/components/frontend/banking/CurrencyAmount";
import { NpcStatusChips } from "@/components/frontend/personnel/NpcStatusChips";
import { initialsOf } from "@/components/frontend/personnel/initials";
interface NpcProfileProps {
readonly npc: GameNpc;
readonly listings: MarketListing[];
/** Interactive employment controls, rendered in the dossier's right column. */
readonly employmentSlot?: ReactNode;
}
function assetName(asset: number | Asset): string {
return typeof asset === "object" && asset !== null ? asset.name : `Asset #${asset}`;
}
function StatusBadges({ npc }: { npc: GameNpc }) {
function Field({
icon: Icon,
label,
value,
}: {
icon: ComponentType<{ className?: string }>;
label: string;
value: string;
}) {
return (
<div className="flex flex-wrap items-center gap-1.5">
{npc.isInGame === true && (
<Badge variant="secondary" className="border-emerald-500/30 text-emerald-500">
In Game
</Badge>
)}
{npc.isGenerated === true && (
<Badge variant="outline" className="border-amber-500/40 text-amber-500">
Generated
</Badge>
)}
{npc.vendor?.enabled === true && (
<Badge variant="outline" className="border-violet-500/40 text-violet-500">
Vendor
</Badge>
)}
<div className="flex items-start gap-3">
<Icon className="mt-0.5 size-4 shrink-0 text-white/40" />
<div className="flex flex-col gap-1">
<span className={DOSSIER.readoutLabel}>{label}</span>
<span className="text-sm text-white/90">{value}</span>
</div>
</div>
);
}
export function NpcProfile({ npc, listings }: NpcProfileProps) {
type LexicalData = Parameters<typeof RichText>[0]["data"];
/** Renders the NPC's Lexical richText bio, falling back to a placeholder when empty. */
function NpcBio({ bio }: { bio: GameNpc["bio"] }) {
const children = (bio as { root?: { children?: unknown[] } } | null | undefined)?.root?.children;
if (!bio || !Array.isArray(children) || children.length === 0) {
return <p className="text-sm text-white/60">No bio on file.</p>;
}
return (
<div className="lexical-content">
<RichText data={bio as LexicalData} />
</div>
);
}
export function NpcProfile({ npc, listings, employmentSlot }: NpcProfileProps) {
const faction = typeof npc.faction === "object" && npc.faction !== null ? npc.faction : null;
const location =
typeof npc.location === "object" && npc.location !== null ? npc.location : null;
@ -55,134 +73,171 @@ export function NpcProfile({ npc, listings }: NpcProfileProps) {
(asset): asset is Asset => typeof asset === "object" && asset !== null,
);
const vendorEnabled = npc.vendor?.enabled === true;
const priceModifier = npc.vendor?.priceModifier ?? 1;
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 heroCells: ReadoutCell[] = [
{ label: "Faction", value: faction?.name ?? "Unaffiliated" },
{ label: "Station", value: location?.name ?? "Unknown" },
{ label: "Goods", value: vendorEnabled ? sellableAssets.length.toString() : "—", mono: true },
{ label: "Listings", value: listings.length.toString(), mono: true },
];
return (
<div className="flex flex-col gap-6 p-5">
<div className="flex flex-col gap-6">
<Link
href="/personnel/contacts"
className="inline-flex w-fit items-center gap-2 text-sm text-muted-foreground hover:text-foreground"
className="inline-flex w-fit items-center gap-2 font-mono text-xs uppercase tracking-widest text-white/50 transition-colors hover:text-white/90"
>
<ArrowLeftIcon className="size-4" />
<ArrowLeftIcon className="size-3.5" />
Back to Contacts
</Link>
<div className="flex flex-col gap-2">
<div className="flex flex-wrap items-center gap-3">
<h1 className="text-lg font-semibold">{npc.name}</h1>
<StatusBadges npc={npc} />
{/* Hero dossier */}
<section
data-slot="npc-dossier-hero"
className="group relative overflow-hidden rounded-none border border-border/70 bg-card"
>
<div aria-hidden="true" className="absolute inset-0">
{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/50" />
<div className="absolute inset-0 flex items-center justify-end">
<span className="select-none pr-6 font-mono text-[9rem] font-bold leading-none tracking-tighter text-white/[0.05] transition-opacity duration-500 group-hover:text-white/[0.08] motion-reduce:transition-none md:pr-12 md:text-[12rem]">
{monogram}
</span>
</div>
</>
)}
</div>
<p className="text-sm text-muted-foreground">
{npc.occupation ?? "Occupation not recorded"}
</p>
</div>
<div
aria-hidden="true"
className="absolute inset-0 bg-gradient-to-r from-black/75 via-black/40 to-transparent"
/>
<div
aria-hidden="true"
className="pointer-events-none absolute inset-0 z-[5] opacity-[0.04]"
style={DOSSIER.gridTexture}
/>
<ClassificationStrip left="Personnel File // Theater Contacts" right={`REF ${refCode}`} />
<CornerBrackets />
<div className="relative z-10 flex flex-col gap-3 px-6 py-10 md:py-14">
<h1
data-text={npc.name}
className="glitch-hover text-balance text-3xl font-bold tracking-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>
</h1>
<p className="glitch-soft max-w-prose text-pretty text-sm uppercase tracking-wider text-white/60 drop-shadow">
{npc.occupation ?? "Occupation not recorded"}
</p>
<NpcStatusChips npc={npc} className="mt-1" />
</div>
<div className="relative z-10">
<LedgerRow cells={heroCells} />
</div>
</section>
<div className="grid gap-6 lg:grid-cols-2">
<div className="flex flex-col gap-6">
<Card>
<CardHeader className="gap-2">
<CardTitle>Bio</CardTitle>
<CardDescription>Background information on this contact.</CardDescription>
</CardHeader>
<CardContent>
<p className="whitespace-pre-wrap text-sm text-muted-foreground">
{npc.bio?.trim() || "No bio on file."}
</p>
</CardContent>
</Card>
<StrategicSummary classificationLeft="Bio" classificationRight="Personnel File">
<NpcBio bio={npc.bio} />
</StrategicSummary>
<Card>
<CardHeader className="gap-2">
<CardTitle>Assignment</CardTitle>
<CardDescription>Known affiliations and current station.</CardDescription>
</CardHeader>
<CardContent className="grid gap-4 sm:grid-cols-2">
<div className="flex items-start gap-3">
<MapPinIcon className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
<div className="flex flex-col gap-1">
<span className="text-xs uppercase tracking-wider text-muted-foreground">
Stationed at
</span>
<span className="text-sm">{location?.name ?? "Location unknown"}</span>
</div>
</div>
<div className="flex items-start gap-3">
<ShieldIcon className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
<div className="flex flex-col gap-1">
<span className="text-xs uppercase tracking-wider text-muted-foreground">
Faction
</span>
<span className="text-sm">{faction?.name ?? "Unaffiliated"}</span>
</div>
</div>
</CardContent>
</Card>
<StrategicSummary classificationLeft="Assignment" classificationRight="Affiliations">
<div className="grid gap-4 sm:grid-cols-2">
<Field
icon={MapPinIcon}
label="Stationed at"
value={location?.name ?? "Location unknown"}
/>
<Field
icon={ShieldIcon}
label="Faction"
value={faction?.name ?? "Unaffiliated"}
/>
</div>
</StrategicSummary>
</div>
<div className="flex flex-col gap-6">
{vendorEnabled && (
<Card>
<CardHeader className="gap-2">
<div className="flex items-center gap-2">
<StoreIcon className="size-4 text-muted-foreground" />
<CardTitle>Vendor information</CardTitle>
</div>
<CardDescription>Market preferences for this contact.</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-4">
<div className="flex items-center justify-between gap-3 text-sm">
<span className="text-muted-foreground">Price modifier</span>
<span className="font-mono tabular-nums">
×{(npc.vendor?.priceModifier ?? 1).toFixed(2)}
<StrategicSummary classificationLeft="Vendor" classificationRight="Market Preferences">
<div className="flex flex-col gap-4">
<div className="flex items-center justify-between gap-3">
<span className={`flex items-center gap-2 ${DOSSIER.readoutLabel}`}>
<StoreIcon className="size-3.5 text-white/40" />
Price modifier
</span>
<span className="font-mono text-sm tabular-nums text-white/90">
×{priceModifier.toFixed(2)}
</span>
</div>
<div className="flex flex-col gap-2">
<span className="text-xs uppercase tracking-wider text-muted-foreground">
Goods they sell
</span>
<span className={DOSSIER.readoutLabel}>Goods they sell</span>
{sellableAssets.length > 0 ? (
<div className="flex flex-wrap gap-1.5">
{sellableAssets.map((asset) => (
<Badge key={asset.id} variant="secondary" className="font-normal">
<span key={asset.id} className={DOSSIER.chip}>
{asset.name}
</Badge>
</span>
))}
</div>
) : (
<p className="text-sm text-muted-foreground">No goods assigned.</p>
<p className="text-sm text-white/60">No goods assigned.</p>
)}
</div>
</CardContent>
</Card>
</div>
</StrategicSummary>
)}
<Card>
<CardHeader className="flex-row items-start justify-between gap-3">
<div className="flex flex-col gap-2">
<CardTitle>Active Market Stock</CardTitle>
<CardDescription>{listings.length} active listing(s).</CardDescription>
<StrategicSummary
classificationLeft="Active Market Stock"
classificationRight={`${listings.length} Listing(s)`}
>
<div className="flex flex-col gap-3">
<div className="flex justify-end">
<Button asChild variant="outline" size="sm">
<Link href="/logistics/market">View market</Link>
</Button>
</div>
<Button asChild variant="outline" size="sm">
<Link href="/logistics/market">View market</Link>
</Button>
</CardHeader>
<CardContent>
{listings.length === 0 ? (
<p className="text-sm italic text-muted-foreground">No active stock.</p>
<p className="text-sm italic text-white/50">No active stock.</p>
) : (
<div className="flex flex-col">
{listings.map((listing, index) => (
<Fragment key={listing.id}>
{index > 0 && <Separator />}
{index > 0 && <Separator className="bg-white/10" />}
<div className="flex items-center justify-between gap-4 py-3 first:pt-0 last:pb-0">
<div className="min-w-0">
<p className="truncate text-sm font-semibold">
<p className="truncate text-sm font-semibold text-white/90">
{assetName(listing.asset)}
</p>
<p className="text-xs text-muted-foreground">
<p className="text-xs text-white/50">
{listing.quantity.toLocaleString()} available
</p>
</div>
<span className="shrink-0 text-sm font-semibold tabular-nums">
<span className="shrink-0 text-sm font-semibold tabular-nums text-white/90">
<CurrencyAmount value={listing.price} currency={listing.currency} />
</span>
</div>
@ -190,8 +245,12 @@ export function NpcProfile({ npc, listings }: NpcProfileProps) {
))}
</div>
)}
</CardContent>
</Card>
</div>
</StrategicSummary>
{employmentSlot ? (
<Fragment key="employment">{employmentSlot}</Fragment>
) : null}
</div>
</div>
</div>

View file

@ -0,0 +1,52 @@
"use client";
import type { GameNpc } from "@/payload-types";
import { cn } from "@/lib/utils";
const STATUS_CHIP: Record<string, string> = {
inGame: "border-emerald-500/40 bg-emerald-500/20 text-emerald-400",
generated: "border-amber-500/40 bg-amber-500/20 text-amber-400",
vendor: "border-violet-500/40 bg-violet-500/20 text-violet-400",
};
function Chip({
label,
tone,
size,
}: {
label: string;
tone: keyof typeof STATUS_CHIP;
size: "default" | "compact";
}) {
return (
<span
className={cn(
"inline-flex items-center border font-mono uppercase leading-none tracking-widest",
size === "compact" ? "px-1 py-px text-[8px]" : "px-1.5 py-0.5 text-[9px]",
STATUS_CHIP[tone],
)}
>
{label}
</span>
);
}
/** Squared tactical status chips shared by the contact card and profile. */
export function NpcStatusChips({
npc,
className,
size = "default",
}: {
npc: GameNpc;
className?: string;
size?: "default" | "compact";
}) {
const vendorEnabled = npc.vendor?.enabled === true;
return (
<div className={cn("flex flex-wrap items-center gap-1.5", className)}>
{npc.isInGame === true && <Chip label="In Game" tone="inGame" size={size} />}
{npc.isGenerated === true && <Chip label="Generated" tone="generated" size={size} />}
{vendorEnabled && <Chip label="Vendor" tone="vendor" size={size} />}
</div>
);
}

View file

@ -0,0 +1,13 @@
/**
* Deterministic two-letter monogram used as the tactical "file photo" backdrop
* on personnel dossier surfaces. Pure, client-safe.
*/
export function initialsOf(name: string): string {
const words = name
.split(/[\s-]+/)
.map((word) => word.replace(/[^A-Za-z0-9]/g, ""))
.filter(Boolean);
if (words.length === 0) return "??";
if (words.length === 1) return words[0].slice(0, 2).toUpperCase();
return (words[0][0] + words[words.length - 1][0]).toUpperCase();
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,57 @@
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
/**
* Converts GameNpcs.bio from a plain-text column to a Lexical richText (jsonb)
* column. Existing plain-text bios are wrapped in a single Lexical paragraph
* so no data is lost; the `USING` clause is required because there is no
* implicit varchar -> jsonb cast.
*/
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "game_npcs"
ALTER COLUMN "bio" SET DATA TYPE jsonb
USING CASE
WHEN "bio" IS NULL THEN NULL
ELSE jsonb_build_object(
'root', jsonb_build_object(
'type', 'root',
'format', '',
'indent', 0,
'version', 1,
'direction', NULL,
'children', jsonb_build_array(
jsonb_build_object(
'type', 'paragraph',
'format', '',
'indent', 0,
'version', 1,
'direction', NULL,
'textStyle', '',
'textFormat', 0,
'children', jsonb_build_array(
jsonb_build_object(
'type', 'text',
'text', "bio",
'mode', 'normal',
'style', '',
'detail', 0,
'format', 0,
'version', 1
)
)
)
)
)
)
END;`)
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "game_npcs"
ALTER COLUMN "bio" SET DATA TYPE varchar
USING CASE
WHEN "bio" IS NULL THEN NULL
ELSE "bio" #>> '{root,children,0,children,0,text}'
END;`)
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,16 @@
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "game_npcs" ADD COLUMN "image_id" integer;
ALTER TABLE "game_npcs" ADD CONSTRAINT "game_npcs_image_id_media_id_fk" FOREIGN KEY ("image_id") REFERENCES "public"."media"("id") ON DELETE set null ON UPDATE no action;
CREATE INDEX "game_npcs_image_idx" ON "game_npcs" USING btree ("image_id");`)
}
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
await db.execute(sql`
ALTER TABLE "game_npcs" DROP CONSTRAINT "game_npcs_image_id_media_id_fk";
DROP INDEX "game_npcs_image_idx";
ALTER TABLE "game_npcs" DROP COLUMN "image_id";`)
}