From 6d8a3af37a6dbcf54cc84b818a7f006d26207832 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Tue, 24 Nov 2026 21:51:53 +0800 Subject: [PATCH] feat(cosmetics): 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. --- .../src/char/actions/action-table.ts | 3 ++ .../src/char/actions/decor-layout-actions.ts | 23 +++++++++++++ .../src/profile/profile-decor-layouts.ts | 32 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 packages/local-service/src/char/actions/decor-layout-actions.ts create mode 100644 packages/local-service/src/profile/profile-decor-layouts.ts diff --git a/packages/local-service/src/char/actions/action-table.ts b/packages/local-service/src/char/actions/action-table.ts index 5f88bba..e9be31c 100644 --- a/packages/local-service/src/char/actions/action-table.ts +++ b/packages/local-service/src/char/actions/action-table.ts @@ -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{ { ... } } + */ +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) }; + }); +} diff --git a/packages/local-service/src/profile/profile-decor-layouts.ts b/packages/local-service/src/profile/profile-decor-layouts.ts new file mode 100644 index 0000000..8f8c98b --- /dev/null +++ b/packages/local-service/src/profile/profile-decor-layouts.ts @@ -0,0 +1,32 @@ +/** + * Decal and attachable layouts in the profile: + * + * decals{ { { skin_condition:r camo_scale:r camo_rotation:r } } } + * attachables{ { { ... } } } + * + * 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 = { { { ... } } }. */ +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); + } + } +}