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.
This commit is contained in:
1 parent
1e7dc2447f
commit
f463f3e325
14 files changed
+315
-13
No files matched your search
@@ -68,7 +68,8 @@ export function setSpecialization(crew: BlkBlock, vehicle: string, spec: number)
|
||||
}
|
||||
|
||||
/** trained/spec pairs in order; a trained vehicle without a following spec has spec 0. */
|
||||
function trainedPairs(crew: BlkBlock): { vehicle: string; spec: number }[] {
|
||||
/** The vehicles the crew is trained for, each with its specialization (0 none, 1 expert, 2 ace). */
|
||||
export function trainedPairs(crew: BlkBlock): { vehicle: string; spec: number }[] {
|
||||
const pairs: { vehicle: string; spec: number }[] = [];
|
||||
for (const param of findBlock(crew, VEHICLES)?.params ?? []) {
|
||||
if (param.name === TRAINED && param.value.type === 'string') pairs.push({ vehicle: param.value.value, spec: 0 });
|
||||
|
||||
@@ -24,6 +24,11 @@ export function crewOf(profile: BlkBlock, crewId: number): BlkBlock | undefined
|
||||
return profile.blocks.find((block) => block.name === CREWS)?.blocks.find((crew) => crew.name === `c${crewId}`);
|
||||
}
|
||||
|
||||
/** Every crew block, in profile order. */
|
||||
export function allCrews(profile: BlkBlock): readonly BlkBlock[] {
|
||||
return (profile.blocks.find((block) => block.name === CREWS)?.blocks ?? []).filter((crew) => CREW_NAME.test(crew.name));
|
||||
}
|
||||
|
||||
export function crewCountOf(profile: BlkBlock, country: string): number {
|
||||
return (profile.blocks.find((block) => block.name === CREWS)?.blocks ?? []).filter((crew) => crewCountry(crew) === country).length;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
Reference in new issue
Block a user