import { useCallback } from 'react'; import clsx from 'clsx'; import classes from './CharacterCard.module.scss'; import { SystemView } from '@/hooks/Mapper/components/ui-kit/SystemView'; import { CharacterTypeRaw, WithIsOwnCharacter } from '@/hooks/Mapper/types'; import { Commands } from '@/hooks/Mapper/types/mapHandlers'; import { emitMapEvent } from '@/hooks/Mapper/events'; type CharacterCardProps = { compact?: boolean; showSystem?: boolean; showShipName?: boolean; useSystemsCache?: boolean; } & CharacterTypeRaw & WithIsOwnCharacter; const SHIP_NAME_RX = /u'|'/g; export const getShipName = (name: string) => { return name .replace(SHIP_NAME_RX, '') .replace(/\\u([\dA-Fa-f]{4})/g, (_, grp) => String.fromCharCode(parseInt(grp, 16)) ) .replace(/\\x([\dA-Fa-f]{2})/g, (_, grp) => String.fromCharCode(parseInt(grp, 16)) ); }; export const CharacterCard = ({ compact = false, isOwn, showSystem, showShipName, useSystemsCache, ...char }: CharacterCardProps) => { const handleSelect = useCallback(() => { emitMapEvent({ name: Commands.centerSystem, data: char?.location?.solar_system_id?.toString(), }); }, [char]); const shipNameText = char.ship?.ship_name ? getShipName(char.ship.ship_name) : ''; const tickerText = char.alliance_id ? char.alliance_ticker : char.corporation_ticker; const shipType = char.ship?.ship_type_info?.name; const locationShown = showSystem && char.location?.solar_system_id; if (compact) { return (
{`${char.name}
{char.name} {" "} {(!locationShown && showShipName && shipNameText) ? `- ${shipNameText}` : `[${tickerText}]`}
{shipType && (
{shipType}
)}
); } else { return (
{char.name} {" "} [{tickerText}]
{locationShown ? (
) : ( shipNameText && (
{shipNameText}
) )}
{shipType && (
{shipType}
)}
); } };