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 (

World Map

PTF Unit Command // Tactical Grid {maps.length} Active Grid{maps.length === 1 ? "" : "s"}
{maps.length === 0 ? (

No maps published to the world map yet. Maps are configured in the admin panel (World: Maps) with the "World Map Entry" flag.

) : (
{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 ( {/* Cover imagery: basemap photo or zoom-1 tile mosaic, dimmed under the overlays */}
{url ? ( // eslint-disable-next-line @next/next/no-img-element ) : tileUrls ? ( ) : (
)}
{/* Legibility gradient */} ); }