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
@@ -7,6 +7,7 @@ import { acceptEula } from './agreement-actions.ts';
|
||||
import { bulkTrainCrews, trainCrew } from './crew-actions.ts';
|
||||
import { buyAllModificationsAction, buyModificationAction, buySparesAction, enableModificationsAction } from './modification-actions.ts';
|
||||
import { purchaseSkillPointsAction, specializeCrewAction, upgradeCrewAction } from './crew-skill-actions.ts';
|
||||
import { savePilotAppearanceAction, selectTitleAction, usersTerseInfoAction } from './player-card-actions.ts';
|
||||
import { buyResourceAction } from './decor-actions.ts';
|
||||
import { saveDecorLayoutsAction } from './decor-layout-actions.ts';
|
||||
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
|
||||
@@ -43,6 +44,9 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
|
||||
['cln_upgrade_crew', upgradeCrewAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_purchase_skill_points', purchaseSkillPointsAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_specialize_crew', specializeCrewAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_select_title', selectTitleAction(deps.profiles, deps.accounts)],
|
||||
['cln_save_pilot_appearance', savePilotAppearanceAction(deps.profiles, deps.accounts)],
|
||||
['cln_get_users_terse_info', usersTerseInfoAction(deps.profiles, deps.accounts)],
|
||||
['cln_buy_resource', buyResourceAction(deps.profiles, deps.accounts, deps.research)],
|
||||
['cln_save_decals', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'decals')],
|
||||
['cln_save_attachables', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'attachables')],
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Player card actions. cln_select_title and cln_save_pilot_appearance
|
||||
* are sent with char_send_blk (job type 13) and answer the whole profile; cln_get_users_terse_info
|
||||
* (scripts user/usersInfoManager.nut, charRequestBlk) answers one block per requested user:
|
||||
* request usersList:t="<uid>;<uid>"
|
||||
* answer <uid>{ nick:t pilotIcon:t pilotId:t title:t clanTag:t clanName:t background:t frame:t }
|
||||
* or <uid>{ failed:b=yes } for unknown users
|
||||
*/
|
||||
import type { BlkBlock, BlkParam } from '@wto/blk';
|
||||
import type { AccountStore } from '../../accounts/account-store.ts';
|
||||
import { chooseTitle, saveAppearance } from '../../player-card/player-card-rules.ts';
|
||||
import { appearance, chosenTitle } from '../../profile/profile-appearance.ts';
|
||||
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
|
||||
import type { CharActionHandler } from '../char-action.ts';
|
||||
import { stringParam } from './payload-params.ts';
|
||||
import { ruleAction } from './rule-answer.ts';
|
||||
import { withAccount } from './account-context.ts';
|
||||
|
||||
export function selectTitleAction(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return ruleAction(profiles, accounts, (payload) => {
|
||||
const title = stringParam(payload, 'name');
|
||||
if (title === undefined) return undefined;
|
||||
return (profile) => chooseTitle(profile, title);
|
||||
});
|
||||
}
|
||||
|
||||
export function savePilotAppearanceAction(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return ruleAction(profiles, accounts, (payload) => {
|
||||
const choices = payload.params.flatMap((param) => param.value.type === 'string' ? [{ field: param.name, image: param.value.value }] : []);
|
||||
return (profile) => saveAppearance(profile, choices);
|
||||
});
|
||||
}
|
||||
|
||||
export function usersTerseInfoAction(profiles: PlayerProfiles, accounts: AccountStore): CharActionHandler {
|
||||
return (context) => withAccount(context, accounts, () => {
|
||||
const list = context.payload ? stringParam(context.payload, 'usersList') : undefined;
|
||||
if (list === undefined) return { kind: 'error', code: 'BAD_PARAMS' };
|
||||
const blocks = list.split(';').filter((uid) => uid !== '').map((uid): BlkBlock => {
|
||||
const account = accounts.byUserId(uid);
|
||||
if (!account) return { name: uid, params: [{ name: 'failed', value: { type: 'bool', value: true } }], blocks: [] };
|
||||
const profile = profiles.profileOf(account.userId);
|
||||
const looks = appearance(profile);
|
||||
const fields: [string, string][] = [
|
||||
['nick', account.nick], ['pilotIcon', looks.pilotIcon ?? ''], ['title', chosenTitle(profile)],
|
||||
['background', looks.background ?? ''], ['frame', looks.frame ?? ''],
|
||||
];
|
||||
return { name: uid, params: fields.map(([name, value]): BlkParam => ({ name, value: { type: 'string', value } })), blocks: [] };
|
||||
});
|
||||
return { kind: 'data', blk: { name: '', params: [], blocks } };
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Player card actions:
|
||||
* cln_select_title (select_current_title, aces.exe 0x1555b60): name:t; a title has to be an
|
||||
* earned unlock (titles are unlocks), "" clears it
|
||||
* cln_save_pilot_appearance (scripts user/profileAppearance.nut): <pilotIcon|background|frame>:t;
|
||||
* the choices are unlock images the client already filters to the available ones
|
||||
*/
|
||||
import type { BlkBlock } from '@wto/blk';
|
||||
import { APPEARANCE_FIELDS, setAppearance, setChosenTitle, type AppearanceField } from '../profile/profile-appearance.ts';
|
||||
import { earnedUnlocks } from '../profile/profile-unlocks.ts';
|
||||
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
||||
|
||||
export function chooseTitle(profile: BlkBlock, title: string): RuleOutcome {
|
||||
if (title !== '' && !earnedUnlocks(profile).has(title)) return refused('NOT_AVAILABLE');
|
||||
setChosenTitle(profile, title);
|
||||
return ACCEPTED;
|
||||
}
|
||||
|
||||
export function saveAppearance(profile: BlkBlock, choices: readonly { field: string; image: string }[]): RuleOutcome {
|
||||
const known = choices.filter((choice): choice is { field: AppearanceField; image: string } => (APPEARANCE_FIELDS as readonly string[]).includes(choice.field));
|
||||
if (known.length === 0) return refused('BAD_PARAMS');
|
||||
for (const { field, image } of known) setAppearance(profile, field, image);
|
||||
return ACCEPTED;
|
||||
}
|
||||
@@ -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