/** * Dataset: localized vehicle names from lang.vromfs.bin lang/units.csv. * * Used by the local web store and generated inventory coupon definitions so players see the * game's own English and Chinese vehicle names without shipping game text with the service. */ import type { Dataset } from './dataset.ts'; import { cleanLangText, parseSemicolonCsvRow, type LocalizedCsvText } from './lang-csv.ts'; const UNITS_CSV = 'lang/units.csv'; export type LocalizedText = LocalizedCsvText; export type UnitNamesMap = Readonly>; export const unitNames: Dataset = { id: 'unit-names', version: 2, extract: (source) => { const lines = source.readText('lang.vromfs.bin', UNITS_CSV).split(/\r?\n/); const header = parseSemicolonCsvRow(lines[0] ?? ''); const enCol = Math.max(1, header.indexOf('')); const zhCol = header.indexOf(''); const hzhCol = header.indexOf(''); const shopNames = new Map(); const fullNames = new Map(); const groupNames = new Map(); for (let i = 1; i < lines.length; i++) { const line = lines[i]!; if (!line.startsWith('"')) continue; const firstSemi = line.indexOf(';'); if (firstSemi <= 2) continue; const key = line.slice(1, firstSemi - 1); const isGroup = key.startsWith('shop/group/'); const isShop = !isGroup && key.endsWith('_shop'); const isFull = !isGroup && !isShop && key.endsWith('_0'); if (!isGroup && !isShop && !isFull) continue; const cols = parseSemicolonCsvRow(line); const en = cleanLangText(cols[enCol] ?? ''); if (!en) continue; const zh = cleanLangText((hzhCol >= 0 ? cols[hzhCol] : '') || (zhCol >= 0 ? cols[zhCol] : '') || en); if (isGroup) { groupNames.set(key, { en, zh }); } else { const unitId = key.slice(0, isShop ? -5 : -2); if (isShop) shopNames.set(unitId, { en, zh }); else fullNames.set(unitId, { en, zh }); } } const result: Record = {}; for (const [unitId, text] of fullNames) result[unitId] = text; for (const [unitId, text] of shopNames) result[unitId] = text; for (const [groupKey, text] of groupNames) result[groupKey] = text; return result; }, };