import { GameSelectors, useAppSelector } from '@app/store'; import { cx } from '@app/utils'; import './PlayerList.css'; export interface PlayerListProps { gameId: number | undefined; } // HSV gradient from green (0s) to red (>=10s); black when disconnected // (ping < 0). Mirrors desktop's PingPixmapGenerator in // cockatrice/src/interface/pixel_map_generator.cpp. function pingCssColor(pingSeconds: number | undefined): string { if (pingSeconds == null || pingSeconds < 0) { return '#000'; } const max = 10; const ratio = Math.min(pingSeconds, max) / max; const hue = 120 * (1 - ratio); return `hsl(${hue}, 100%, 50%)`; } function PlayerList({ gameId }: PlayerListProps) { const players = useAppSelector((state) => gameId != null ? GameSelectors.getPlayers(state, gameId) : undefined, ); const activePlayerId = useAppSelector((state) => gameId != null ? GameSelectors.getActivePlayerId(state, gameId) : undefined, ); const hostId = useAppSelector((state) => gameId != null ? GameSelectors.getHostId(state, gameId) : undefined, ); const entries = players ? Object.values(players) : []; return (