Save decal and attachment layouts

Handle cln_save_decals and cln_save_attachables and return the complete
updated layout block for the affected resource type.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 21:51:53 +08:00
1 parent 8692a13577
commit c6c8f85ddd
3 files changed
+58

No files matched your search

@@ -6,6 +6,7 @@ import type { CharActionHandler } from '../char-action.ts';
import { acceptEula } from './agreement-actions.ts';
import { bulkTrainCrews, trainCrew } from './crew-actions.ts';
import { buyAllModificationsAction, buyModificationAction, buySparesAction, enableModificationsAction } from './modification-actions.ts';
import { saveDecorLayoutsAction } from './decor-layout-actions.ts';
import { entitlementsFull, initialMeta, legacyUserData } from './online-init-actions.ts';
import { priceEx } from './price-actions.ts';
import { buyAircraft, buySlot } from './purchase-actions.ts';
@@ -37,5 +38,7 @@ export function actionTable(deps: ActionDependencies): ReadonlyMap<string, CharA
['cln_buy_all_modification', buyAllModificationsAction(deps.profiles, deps.accounts, deps.research)],
['cln_buy_spare_aircrafts', buySparesAction(deps.profiles, deps.accounts, deps.research)],
['cln_enable_modifications', enableModificationsAction(deps.profiles, deps.accounts)],
['cln_save_decals', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'decals')],
['cln_save_attachables', saveDecorLayoutsAction(deps.profiles, deps.accounts, 'attachables')],
]);
}
@@ -0,0 +1,23 @@
/**
* Saving decal and attachable layouts. Both are sent by native functions
* whose job types are not profile updates: cln_save_decals is type 0x1f (aces.exe 0x2a1910),
* cln_save_attachables type 0x20 (0x2a1c30); the client takes the whole answer as its decals or
* attachables block (GameSaveData::onAsyncEconTransComplete 0xeb7a14 / 0xeb7a45). So each answers
* the full block of its kind after storing the request.
*
* Request (lab round 21): <vehicle>{ <skin>{ ... } }
*/
import type { AccountStore } from '../../accounts/account-store.ts';
import { decorLayouts, saveDecorLayouts, type DecorLayoutKind } from '../../profile/profile-decor-layouts.ts';
import type { PlayerProfiles } from '../../profile/player-profiles.ts';
import type { CharActionHandler } from '../char-action.ts';
import { withAccount } from './account-context.ts';
export function saveDecorLayoutsAction(profiles: PlayerProfiles, accounts: AccountStore, kind: DecorLayoutKind): CharActionHandler {
return (context) => withAccount(context, accounts, (account) => {
const changes = context.payload;
if (!changes) return { kind: 'error', code: 'BAD_PARAMS' };
const profile = profiles.update(account.userId, (saved) => saveDecorLayouts(saved, kind, changes));
return { kind: 'data', blk: decorLayouts(profile, kind) };
});
}
@@ -0,0 +1,32 @@
/**
* Decal and attachable layouts in the profile:
*
* decals{ <vehicle>{ <skin>{ <slot params ...> skin_condition:r camo_scale:r camo_rotation:r } } }
* attachables{ <vehicle>{ <skin>{ ... } } }
*
* The client keeps each block whole as its own copy (aces.exe: profile "decals" -> save data
* +0x140, "attachables" -> +0x160) and edits it in the customization window; the local service
* only stores what the client sends, per vehicle and skin.
*/
import { ensureBlock, findBlock, type BlkBlock } from '@wto/blk';
export type DecorLayoutKind = 'decals' | 'attachables';
/** The layouts of one kind, as the client keeps them (a root holding the vehicle blocks). */
export function decorLayouts(profile: BlkBlock, kind: DecorLayoutKind): BlkBlock {
return { name: '', params: [], blocks: structuredClone(findBlock(profile, kind)?.blocks ?? []) };
}
/** Replace the given skins' layouts: changes = { <vehicle>{ <skin>{ ... } } }. */
export function saveDecorLayouts(profile: BlkBlock, kind: DecorLayoutKind, changes: BlkBlock): void {
const layouts = ensureBlock(profile, kind);
for (const vehicle of changes.blocks) {
const saved = ensureBlock(layouts, vehicle.name);
for (const skin of vehicle.blocks) {
const copy = structuredClone(skin);
const index = saved.blocks.findIndex((existing) => existing.name === skin.name);
if (index >= 0) saved.blocks[index] = copy;
else saved.blocks.push(copy);
}
}
}