Files
WT-Offline/packages/local-service/src/profile/profile-showcase.ts
T
N0VAN0M4LY feda31d12a fix(profile): prevent saved showcases from crashing the parser
Store local showcase selections separately from the client's top-level
showcase block.
2026-11-25 22:46:35 +08:00

37 lines
1.6 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:
*
* wtoShowcase{
* current:t="favorite_unit"
* favorite_unit{ unit:t="us_m22_locust" difficulty:t="arcade" }
* medalist{ medals:t="..." medals:t="..." }
* }
*
* Stored under `wtoShowcase` rather than `showcase`: the client's native profile serializer
* (aces.exe 2.61.0.37 0x917e30 -> 0x9492c0) reads a top-level `showcase` block with a different
* flat schema and fatal-aborts if `favoriteUnitDifficulty:t` is absent (0x949b49), while the UI
* scripts read showcase data exclusively through cln_get_showcases and cln_get_users_terse_info.
*/
import { ensureBlock, findBlock, findParam, setParam, type BlkBlock, type BlkParam } from '@wto/blk';
const SHOWCASE = 'wtoShowcase';
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];
}