Save profile appearance and return player summaries
Persist titles, avatars, backgrounds, and frames. Return the corresponding appearance fields in the player summary response.
This commit is contained in:
1 parent
81d33f3048
commit
71c44a085d
4 files changed
+117
No files matched your search
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 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 service's own record
|
||||
*/
|
||||
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
|
||||
const TITLE = 'title';
|
||||
const APPEARANCE = 'pilotAppearance';
|
||||
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<Record<AppearanceField, string>> {
|
||||
const block = findBlock(profile, APPEARANCE);
|
||||
const result: Partial<Record<AppearanceField, string>> = {};
|
||||
for (const field of APPEARANCE_FIELDS) {
|
||||
const value = block && findParam(block, field)?.value;
|
||||
if (value?.type === 'string') result[field] = value.value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function setAppearance(profile: BlkBlock, field: AppearanceField, image: string): void {
|
||||
setParam(ensureBlock(profile, APPEARANCE), field, { type: 'string', value: image });
|
||||
}
|
||||
Reference in new issue
Block a user