Files
WT-Offline/packages/local-service/src/game-data/datasets/unit-names.ts
T
N0VAN0M4LY 259cd0f32c feat(store): sell multi-vehicle packs and localize country names
Offer the five three-vehicle packs and nine starter packs as bundles.
Grant their unowned vehicles and bonuses on purchase. Encode each
vehicle in an aircraftGift field and validate duplicate IDs and
vehicle assignments.

Read group labels from units.csv and country names from
_common_languages.csv. Use those names in packs and browser filters.

Type checking and local catalogue and price response checks passed.
In-game acceptance is pending.
2026-11-25 13:41:32 +08:00

59 lines
2.3 KiB
TypeScript

/**
* 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<Record<string, LocalizedText>>;
export const unitNames: Dataset<UnitNamesMap> = {
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('<English>'));
const zhCol = header.indexOf('<Chinese>');
const hzhCol = header.indexOf('<HChinese>');
const shopNames = new Map<string, LocalizedText>();
const fullNames = new Map<string, LocalizedText>();
const groupNames = new Map<string, LocalizedText>();
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<string, LocalizedText> = {};
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;
},
};