/** * The player's card in the profile: * title:t the chosen title (profile top level, read by the client's * profile serializer) * pilotAppearance{ pilotIcon:t background:t frame:t } * what cln_save_pilot_appearance sets; the client itself reads * it back through cln_get_users_terse_info, so the block is the * local server's own record */ import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk'; const TITLE = 'title'; const APPEARANCE = 'pilotAppearance'; export const DEFAULT_PILOT_ICON = 'cardicon_default'; export const APPEARANCE_FIELDS = ['pilotIcon', 'background', 'frame'] as const; export type AppearanceField = (typeof APPEARANCE_FIELDS)[number]; export function chosenTitle(profile: BlkBlock): string { const value = findParam(profile, TITLE)?.value; return value?.type === 'string' ? value.value : ''; } export function setChosenTitle(profile: BlkBlock, title: string): void { setParam(profile, TITLE, { type: 'string', value: title }); } export function appearance(profile: BlkBlock): Partial> { const block = findBlock(profile, APPEARANCE); const result: Partial> = {}; for (const field of APPEARANCE_FIELDS) { const value = block && findParam(block, field)?.value; if (value?.type === 'string') result[field] = value.value; } if (result.pilotIcon === undefined) { const legacy = findParam(profile, 'pilotIcon')?.value; if (legacy?.type === 'string') result.pilotIcon = legacy.value; } return result; } export function setAppearance(profile: BlkBlock, field: AppearanceField, image: string): void { setParam(ensureBlock(profile, APPEARANCE), field, { type: 'string', value: image }); }