import type { MetaFunction } from "@remix-run/node"; import { json } from "@remix-run/node"; import { useLoaderData } from "@remix-run/react"; import { Footer } from "../components/footer"; import type { MetagameWorld } from "../utils/metagame"; import { fetchSingleMetagameWorld } from "../utils/metagame"; import type { WorldResponse, Zone } from "../utils/saerro"; import { allClasses, allVehicles, totalPopulation, worldQuery, } from "../utils/saerro"; import { pascalCaseToTitleCase, toTitleCase, worlds, zones, } from "../utils/strings"; import * as styles from "../components/world.css"; import { c } from "../utils/classes"; import { FactionBar } from "../components/faction-bar"; import { popImage } from "../components/index-world.css"; import vsLogo from "../images/vs-100.png"; import ncLogo from "../images/nc-100.png"; import trLogo from "../images/tr-100.png"; import { FactionPie } from "../components/faction-pie"; import { AlertTimer } from "../components/alert-timer"; import { contPrioritySort, zonePopulationSort } from "../utils/sorting"; import { WorldZoneContainer } from "../components/world-zone-container"; type LoaderData = { saerro: WorldResponse; metagame: MetagameWorld; id: string; }; export async function loader({ params }) { const [saerro, metagame] = await Promise.all([ worldQuery(params.id as string), fetchSingleMetagameWorld(params.id as string), ]); return json({ saerro, metagame, id: params.id } as LoaderData); } export const meta: MetaFunction = ({ data }) => { const { saerro, id } = data as LoaderData; const date = new Date(); const worldInfo = worlds[String(id || "default")]; const datetimeHumanFriendly = date.toLocaleString(worldInfo.locale, { timeZone: worldInfo.timeZone, dateStyle: "medium", timeStyle: "short", }); return [ { title: `${ worldInfo.name || "Unknown world" } | PlanetSide 2 Live Population Stats`, }, { name: "description", content: `${worldInfo.name} currently has ${totalPopulation( saerro.world.population )} players online as of ${datetimeHumanFriendly} ${ worldInfo.name } time. VS: ${saerro.world.population.vs}, NC: ${ saerro.world.population.nc }, TR: ${ saerro.world.population.tr } -- See more detailed stats on ps2.live.`, }, ]; }; export default function World() { const { saerro: { world }, id, metagame, } = useLoaderData(); const worldInfo = worlds[String(id || "default")]; const nextZoneID = metagame.zones.length !== 0 ? metagame.zones.sort( (a, b) => new Date(a.locked_since ?? Date.now()).getTime() - new Date(b.locked_since ?? Date.now()).getTime() )[0].id : 0; return ( <>
{worldInfo.name.toUpperCase()}
[{worldInfo.location}] [{worldInfo.platform}]
{totalPopulation(world.population).toLocaleString()}
PLAYERS
VS{" "} {world.population.vs}
NC{" "} {world.population.nc}
TR{" "} {world.population.tr}
CONTINENT CONTROL
{metagame.zones.sort(contPrioritySort).map((zone, idx) => { const zoneInfo = zones[String(zone.id)]; return (
{zoneInfo.name.toUpperCase()}
{zone.alert ? ( ) : zone.locked ? ( nextZoneID == zone.id ? ( <>NEXT UP ยป ) : ( <>LOCKED ) ) : ( <>UNLOCKED )}
); })}

WARZONES

{world.zones.all.sort(zonePopulationSort).map((zone) => ( // ))}