Factions gain a discovered checkbox plus a read-time mask so players see the entry (UNDISCOVERED card, classified detail stub) without its name, description, standing, relationships, campaigns or cover image. The mask runs in the Factions afterRead hook, so every reader path is covered: pages, REST, and populated relationships. Readers holding the new factions:view-undiscovered permission or system:admin-access see the real record; admin panel reads are exempt so a masked edit form can never write the placeholder name back over a record.
273 lines
12 KiB
TypeScript
273 lines
12 KiB
TypeScript
import config from "@payload-config";
|
||
import { getPayload } from "payload";
|
||
import Link from "next/link";
|
||
import { headers as nextHeaders } from "next/headers";
|
||
import type { Metadata } from "next";
|
||
import { Map as MapIcon, MapPinIcon } from "lucide-react";
|
||
import type { Campaign, Faction, Map as MapDoc, Media } from "@/payload-types";
|
||
import { OverflowTooltip } from "@/components/frontend/map/OverflowTooltip";
|
||
import {
|
||
easeStatClass,
|
||
isWorldMapEntry,
|
||
weatherStatClass,
|
||
weatherStatLabel,
|
||
worldMapScreenQuery,
|
||
} from "@/lib/map/screen";
|
||
|
||
export const metadata: Metadata = {
|
||
title: "World Map: Polaris Task Force",
|
||
};
|
||
|
||
function basemapUrl(map: MapDoc): string | null {
|
||
const image = map.basemapImage as Media | number | null | undefined;
|
||
if (image && typeof image === "object" && image.url) return image.url;
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* Static preview for tile-mode maps: a 2x2 mosaic of the map's own zoom-1
|
||
* tiles covering the whole world square, center-cropped by the card frame.
|
||
*/
|
||
function tilePreviewUrls(template: string): string[] | null {
|
||
if (!template.includes("{z}") || !template.includes("{x}") || !template.includes("{y}")) {
|
||
return null;
|
||
}
|
||
return [0, 1].flatMap((y) =>
|
||
[0, 1].map((x) =>
|
||
template.replace("{z}", "1").replace("{x}", String(x)).replace("{y}", String(y)),
|
||
),
|
||
);
|
||
}
|
||
|
||
interface ReadoutCell {
|
||
key: string;
|
||
value: string;
|
||
label: string;
|
||
cls?: string;
|
||
}
|
||
|
||
export default async function MapPickerPage() {
|
||
const payload = await getPayload({ config: await config });
|
||
// Maps stay world-readable (overrideAccess), but the reader is still passed so
|
||
// populated factions run the discovery hook with the right clearance.
|
||
const { user } = await payload.auth({
|
||
headers: await nextHeaders(),
|
||
canSetHeaders: false,
|
||
});
|
||
|
||
const mapsRes = await payload.find({
|
||
collection: "maps",
|
||
where: worldMapScreenQuery(),
|
||
sort: "name",
|
||
limit: 100,
|
||
depth: 1,
|
||
overrideAccess: true,
|
||
user,
|
||
});
|
||
|
||
const maps = mapsRes.docs.filter((map) => isWorldMapEntry(map));
|
||
|
||
return (
|
||
<div className="flex min-h-[240px] flex-1 flex-col">
|
||
<div
|
||
className="flex items-center justify-between gap-3 border-b border-white/15 bg-black/50 px-5 py-2 backdrop-blur-sm"
|
||
data-tour="map-picker-header"
|
||
>
|
||
<div className="flex items-center gap-2">
|
||
<MapIcon className="size-4 text-muted-foreground" />
|
||
<h1 className="text-sm font-semibold uppercase tracking-[0.2em]">World Map</h1>
|
||
</div>
|
||
<div className="flex items-center gap-4 font-mono text-[9px] uppercase tracking-widest text-white/60">
|
||
<span>PTF Unit Command // Tactical Grid</span>
|
||
<span>
|
||
{maps.length} Active Grid{maps.length === 1 ? "" : "s"}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
|
||
{maps.length === 0 ? (
|
||
<div className="flex flex-1 flex-col items-center justify-center gap-2 py-24 text-muted-foreground">
|
||
<MapPinIcon className="size-6" />
|
||
<p className="text-sm">
|
||
No maps published to the world map yet. Maps are configured in the admin panel (World:
|
||
Maps) with the "World Map Entry" flag.
|
||
</p>
|
||
</div>
|
||
) : (
|
||
<div
|
||
className="grid grid-cols-1 gap-4 p-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
|
||
data-tour="map-picker-grid"
|
||
>
|
||
{maps.map((map) => {
|
||
const campaign =
|
||
map.campaign && typeof map.campaign === "object" ? (map.campaign as Campaign) : null;
|
||
const faction =
|
||
map.factionControl && typeof map.factionControl === "object"
|
||
? (map.factionControl as Faction)
|
||
: null;
|
||
const url = basemapUrl(map);
|
||
const tileUrls =
|
||
map.basemapMode === "tiles" && map.tileUrlTemplate
|
||
? tilePreviewUrls(map.tileUrlTemplate)
|
||
: null;
|
||
const refCode = String(map.id).padStart(3, "0");
|
||
|
||
// Readout footer cells: size is always known, intel fields join when set.
|
||
const cells: ReadoutCell[] = [
|
||
{
|
||
key: `s-${map.id}`,
|
||
value: `${map.worldSizeWidth}×${map.worldSizeHeight}`,
|
||
label: "M",
|
||
},
|
||
];
|
||
if (map.weather) {
|
||
cells.push({
|
||
key: `w-${map.id}`,
|
||
value: weatherStatLabel(map.weather),
|
||
label: "WX",
|
||
cls: weatherStatClass(map.weather),
|
||
});
|
||
}
|
||
if (map.easeOfAccess) {
|
||
cells.push({
|
||
key: `e-${map.id}`,
|
||
value: map.easeOfAccess,
|
||
label: "Access",
|
||
cls: easeStatClass(map.easeOfAccess),
|
||
});
|
||
}
|
||
if (faction) {
|
||
cells.push({
|
||
key: `f-${map.id}`,
|
||
value: faction.name,
|
||
label: "Ctrl",
|
||
cls: "text-violet-400",
|
||
});
|
||
}
|
||
|
||
return (
|
||
<Link
|
||
key={map.id}
|
||
href={`/map/${map.id}`}
|
||
aria-label={`Open map ${map.name}`}
|
||
className="group relative block aspect-[4/3] overflow-hidden rounded-none border border-border/70 bg-card transition-colors duration-300 hover:border-foreground/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
|
||
>
|
||
{/* Cover imagery: basemap photo or zoom-1 tile mosaic, dimmed under the overlays */}
|
||
<div className="absolute inset-0 scale-100 transition-transform duration-500 ease-out group-hover:scale-110 motion-reduce:transition-none motion-reduce:group-hover:scale-100">
|
||
{url ? (
|
||
// eslint-disable-next-line @next/next/no-img-element
|
||
<img
|
||
src={url}
|
||
alt=""
|
||
aria-hidden="true"
|
||
className="absolute inset-0 size-full object-cover opacity-60 transition-opacity duration-500 ease-out group-hover:opacity-80 motion-reduce:transition-none"
|
||
/>
|
||
) : tileUrls ? (
|
||
<div
|
||
aria-hidden="true"
|
||
className="absolute inset-0 flex items-center justify-center overflow-hidden"
|
||
>
|
||
{/* Square mosaic sized to the card width so it always covers the
|
||
4:3 frame (vertical overflow is cropped), like object-cover. */}
|
||
<div className="grid aspect-square w-full max-w-none grid-cols-2 opacity-60 transition-opacity duration-500 ease-out group-hover:opacity-80 motion-reduce:transition-none">
|
||
{tileUrls.map((tileUrl) => (
|
||
// eslint-disable-next-line @next/next/no-img-element
|
||
<img key={tileUrl} src={tileUrl} alt="" className="h-auto w-full" />
|
||
))}
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="flex size-full items-center justify-center text-muted-foreground">
|
||
<MapIcon className="size-8 opacity-30" />
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{/* Legibility gradient */}
|
||
<div
|
||
aria-hidden="true"
|
||
className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/60 to-black/25"
|
||
/>
|
||
|
||
{/* Faint tactical grid texture (constant, never brightens) */}
|
||
<div
|
||
aria-hidden="true"
|
||
className="pointer-events-none absolute inset-0 z-[5] opacity-[0.04]"
|
||
style={{
|
||
backgroundImage:
|
||
"linear-gradient(to right, white 1px, transparent 1px), linear-gradient(to bottom, white 1px, transparent 1px)",
|
||
backgroundSize: "28px 28px",
|
||
}}
|
||
/>
|
||
|
||
{/* Classification strip */}
|
||
<div
|
||
aria-hidden="true"
|
||
className="absolute inset-x-0 top-0 z-20 flex items-center justify-between gap-2 border-b border-white/15 bg-black/50 px-3 py-1.5 backdrop-blur-sm"
|
||
>
|
||
<OverflowTooltip
|
||
text={campaign ? `Campaign // ${campaign.name}` : "Grid // Unit Command"}
|
||
triggerClassName="truncate font-mono text-[9px] uppercase tracking-widest text-white/60"
|
||
textClassName="font-mono text-[9px] uppercase tracking-widest text-white/60"
|
||
/>
|
||
<span className="shrink-0 font-mono text-[9px] uppercase tracking-widest text-white/60">
|
||
REF {refCode}
|
||
</span>
|
||
</div>
|
||
|
||
{/* Corner brackets */}
|
||
<div aria-hidden="true" className="pointer-events-none absolute inset-2 z-30">
|
||
<span className="absolute left-0 top-0 size-3 border-l border-t border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||
<span className="absolute right-0 top-0 size-3 border-r border-t border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||
<span className="absolute bottom-0 left-0 size-3 border-b border-l border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||
<span className="absolute bottom-0 right-0 size-3 border-b border-r border-white/25 transition-colors duration-300 group-hover:border-white/60" />
|
||
</div>
|
||
|
||
{/* Title block */}
|
||
<div className="absolute inset-0 z-10 flex items-center justify-center px-8 pb-10 pt-8 text-center">
|
||
<div className="flex max-w-full flex-col items-center gap-1.5">
|
||
<h2 className="text-balance text-lg font-bold text-white drop-shadow-lg">
|
||
{map.name}
|
||
</h2>
|
||
{map.description && (
|
||
<OverflowTooltip
|
||
text={map.description}
|
||
triggerClassName="line-clamp-2 max-w-prose text-pretty text-xs text-white/70 drop-shadow"
|
||
textClassName="text-xs text-white/80"
|
||
/>
|
||
)}
|
||
</div>
|
||
</div>
|
||
|
||
{/* Readout footer */}
|
||
<footer className="absolute inset-x-0 bottom-0 z-20 flex items-stretch border-t border-white/15 bg-black/60 px-2 py-1.5 backdrop-blur-sm">
|
||
{cells.map((cell, index) => (
|
||
<div
|
||
key={cell.key}
|
||
className={`flex min-w-0 flex-1 items-center justify-center gap-1.5 px-1${
|
||
index < cells.length - 1 ? " border-r border-white/15" : ""
|
||
}`}
|
||
>
|
||
<OverflowTooltip
|
||
text={cell.value}
|
||
triggerClassName={`min-w-0 truncate font-mono text-xs tabular-nums uppercase tracking-wider ${
|
||
cell.cls ?? "text-white/80"
|
||
}`}
|
||
textClassName={`font-mono text-[10px] uppercase tracking-wider ${
|
||
cell.cls ?? "text-white/80"
|
||
}`}
|
||
/>
|
||
<span className="shrink-0 text-[9px] uppercase tracking-wider text-white/50">
|
||
{cell.label}
|
||
</span>
|
||
</div>
|
||
))}
|
||
</footer>
|
||
</Link>
|
||
);
|
||
})}
|
||
</div>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|