/** * The crew slot list in a char request body, written by the stock scripts * (gui.vromfs.bin scripts/crew/crewTrain.nut createBatchTrainCrewRequestBlk): * * batchTrainCrew{ * trainCrew{ crewId:i=10 unitName:t="cr_32" } * trainCrew{ crewId:i=11 unitName:t="" } empty: leave the slot empty * } */ import { findBlock, findParam, type BlkBlock } from '@wto/blk'; import type { CrewSlotAssignment } from '../../profile/crew-slots.ts'; /** The list, empty when the body has none, or undefined when an entry is malformed. */ export function readCrewSlots(payload: BlkBlock): CrewSlotAssignment[] | undefined { const batch = findBlock(payload, 'batchTrainCrew'); if (!batch) return []; const result: CrewSlotAssignment[] = []; for (const entry of batch.blocks) { if (entry.name !== 'trainCrew') continue; const crewId = findParam(entry, 'crewId')?.value; const vehicle = findParam(entry, 'unitName')?.value; if (crewId?.type !== 'int' || vehicle?.type !== 'string') return undefined; result.push({ crewId: crewId.value, vehicle: vehicle.value }); } return result; }