The faction dossier's Relationships block only ever showed one direction, and only the directions someone had bothered to type by hand. Read both directions from the ledger instead: each row now carries "they see us" and "we see them" meters, and a Recent Developments list under them spells out the events behind those numbers in plain language. Hidden entries move the meters without appearing in that list. Add /intelligence/factions/relations, a full cross-table of every faction against every other, player faction first, with the existing band labels as a legend. Rows and headers link back to dossiers, and the table scrolls sideways rather than truncating scores. A Relations entry in the Intelligence sidebar points at it.
160 lines
6 KiB
TypeScript
160 lines
6 KiB
TypeScript
import config from "@payload-config";
|
|
import { getPayload } from "payload";
|
|
import { headers as nextHeaders } from "next/headers";
|
|
import Link from "next/link";
|
|
import { ArrowLeftIcon, ScaleIcon } from "lucide-react";
|
|
import { getRelationContext } from "@/lib/intelligence/factionRelationLedger";
|
|
import {
|
|
formatScore,
|
|
pairKey,
|
|
relationBand,
|
|
RELATION_BANDS,
|
|
RELATION_BAND_CLASSES,
|
|
} from "@/lib/intelligence/factionRelations";
|
|
|
|
export const metadata = {
|
|
title: "Faction Relations | Polaris Task Force",
|
|
};
|
|
|
|
const TYPE_ORDER: Record<string, number> = {
|
|
playerFaction: 0,
|
|
majorFaction: 1,
|
|
minorFaction: 2,
|
|
corporation: 3,
|
|
special: 4,
|
|
};
|
|
|
|
export default async function FactionRelationsPage() {
|
|
const payload = await getPayload({ config });
|
|
const { user } = await payload.auth({
|
|
headers: await nextHeaders(),
|
|
canSetHeaders: false,
|
|
});
|
|
|
|
const context = await getRelationContext(payload, user);
|
|
|
|
// Player faction first, then majors down to specials, so the matrix reads in
|
|
// the same order the faction list uses.
|
|
const factions = [...context.factions].sort(
|
|
(a, b) => (TYPE_ORDER[a.type] ?? 99) - (TYPE_ORDER[b.type] ?? 99),
|
|
);
|
|
|
|
return (
|
|
<div className="p-5 flex flex-col gap-6 max-w-[96rem] mx-auto w-full">
|
|
<div className="flex flex-col gap-1">
|
|
<Link
|
|
href="/intelligence/factions"
|
|
className="flex w-fit items-center gap-1 py-1 text-sm text-muted-foreground transition-colors hover:text-primary"
|
|
>
|
|
<ArrowLeftIcon className="size-3" />
|
|
Back to Factions
|
|
</Link>
|
|
<div className="flex items-center gap-2">
|
|
<ScaleIcon className="size-5 text-muted-foreground" />
|
|
<h1 className="text-lg font-semibold">Faction Relations</h1>
|
|
</div>
|
|
<p className="text-sm text-muted-foreground">
|
|
Each row reads how that faction currently regards each column, accumulated from recorded
|
|
events. The two directions of a relationship are independent, so one faction can respect
|
|
another that despises it.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="flex flex-wrap items-center gap-3 text-xs text-muted-foreground">
|
|
<span className="uppercase tracking-wider">Scale</span>
|
|
{RELATION_BANDS.map((band) => (
|
|
<span key={band.key} className="flex items-center gap-1.5">
|
|
<span
|
|
className={`inline-block size-2 rounded-full ${RELATION_BAND_CLASSES[band.key].bar}`}
|
|
aria-hidden
|
|
/>
|
|
<span>{band.label}</span>
|
|
</span>
|
|
))}
|
|
</div>
|
|
|
|
{factions.length === 0 ? (
|
|
<div className="flex flex-col items-center justify-center py-12 text-muted-foreground">
|
|
<p className="text-sm">No factions found.</p>
|
|
</div>
|
|
) : (
|
|
<div className="overflow-x-auto rounded-lg border border-border">
|
|
<table className="w-full min-w-[720px] border-collapse text-sm">
|
|
<thead>
|
|
<tr className="border-b border-border">
|
|
<th className="sticky left-0 z-10 bg-card px-4 py-3 text-left text-xs font-medium uppercase tracking-wider text-muted-foreground">
|
|
Regards
|
|
</th>
|
|
{factions.map((faction) => (
|
|
<th
|
|
key={faction.id}
|
|
scope="col"
|
|
className="px-3 py-3 text-center text-xs font-medium uppercase tracking-wider text-muted-foreground"
|
|
>
|
|
<Link
|
|
href={`/intelligence/factions/${faction.id}`}
|
|
className="mx-auto block max-w-[9rem] truncate transition-colors hover:text-primary"
|
|
title={faction.name}
|
|
>
|
|
{faction.name}
|
|
</Link>
|
|
</th>
|
|
))}
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-border">
|
|
{factions.map((subject) => (
|
|
<tr key={subject.id}>
|
|
<th
|
|
scope="row"
|
|
className="sticky left-0 z-10 bg-card px-4 py-3 text-left font-medium"
|
|
>
|
|
<Link
|
|
href={`/intelligence/factions/${subject.id}`}
|
|
className="block max-w-[14rem] truncate transition-colors hover:text-primary"
|
|
title={subject.name}
|
|
>
|
|
{subject.name}
|
|
</Link>
|
|
</th>
|
|
{factions.map((target) => {
|
|
if (target.id === subject.id) {
|
|
return (
|
|
<td
|
|
key={target.id}
|
|
className="px-3 py-3 text-center text-muted-foreground/40"
|
|
>
|
|
<span aria-label="not applicable">-</span>
|
|
</td>
|
|
);
|
|
}
|
|
const score = context.scores.get(pairKey(subject.id, target.id)) ?? 0;
|
|
const band = relationBand(score);
|
|
return (
|
|
<td
|
|
key={target.id}
|
|
className="px-3 py-3 text-center"
|
|
title={`${subject.name} toward ${target.name}: ${band.label}`}
|
|
>
|
|
<span
|
|
className={`font-mono tabular-nums ${score === 0 ? "text-muted-foreground" : RELATION_BAND_CLASSES[band.key].text}`}
|
|
>
|
|
{formatScore(score)}
|
|
</span>
|
|
</td>
|
|
);
|
|
})}
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
|
|
<p className="text-xs text-muted-foreground">
|
|
Entries are recorded from the admin panel under Intelligence, Relation Entries. Scores are
|
|
clamped to -100..100, and a zero can mean a clean slate or events that cancelled out.
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|