Files
WT-Offline/packages/local-service/src/profile/profile-showcase.ts
T
N0VAN0M4LY f463f3e325 feat(profile): add unlock purchases and showcases
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.
2026-11-25 02:49:13 +08:00

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];
}