Load unlock prices from unlocks.blk and expose them in Common/unlocks. Support purchasing unlocks and saving showcases, and count qualified crews for the ace showcase. Read charRequestBlk action parameters from HTTP headers and apply this to cln_get_users_terse_info.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
/**
|
|
* The player's profile showcase, kept in the profile in the form the
|
|
* client reads it back from cln_get_showcases and cln_get_users_terse_info:
|
|
*
|
|
* showcase{
|
|
* current:t="favorite_unit"
|
|
* favorite_unit{ unit:t="us_m22_locust" difficulty:t="arcade" }
|
|
* medalist{ medals:t="..." medals:t="..." }
|
|
* }
|
|
*
|
|
* This block is the local service's own record: the client's profile reader does not know it.
|
|
*/
|
|
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock, type BlkParam } from '@wto/blk';
|
|
|
|
const SHOWCASE = 'showcase';
|
|
const CURRENT = 'current';
|
|
|
|
export function currentShowcase(profile: BlkBlock): string {
|
|
const value = findParam(findBlock(profile, SHOWCASE) ?? { name: '', params: [], blocks: [] }, CURRENT)?.value;
|
|
return value?.type === 'string' ? value.value : '';
|
|
}
|
|
|
|
/** Every saved showcase, by type. */
|
|
export function savedShowcases(profile: BlkBlock): readonly BlkBlock[] {
|
|
return findBlock(profile, SHOWCASE)?.blocks ?? [];
|
|
}
|
|
|
|
/** Replace the fields of one showcase type and make it the current one. */
|
|
export function writeShowcase(profile: BlkBlock, type: string, fields: readonly BlkParam[]): void {
|
|
const showcase = ensureBlock(profile, SHOWCASE);
|
|
setParam(showcase, CURRENT, { type: 'string', value: type });
|
|
ensureBlock(showcase, type).params = [...fields];
|
|
}
|