Add per-country crew slot controls and skill level previews to the launcher. Keep archived crews and their stable IDs in the save, update affected lineups, and back up the save before closing a slot. Verified with both type checks, the launcher build, 2.61.0.64 patch checks, and temporary save read and write checks. BREAKING CHANGE: The launcher automatically upgrades existing saves to format 4. Keep a pre-upgrade backup to use a save with an older launcher.
69 lines
3.7 KiB
TypeScript
69 lines
3.7 KiB
TypeScript
import { decodeBlk, encodeBlk, findBlock } from '@wto/blk';
|
|
import { DatasetCache } from '../game-data/datasets/dataset-cache.ts';
|
|
import { externalItemSources } from '../game-data/datasets/external-item-sources.ts';
|
|
import { itemCatalogue } from '../game-data/datasets/item-catalogue.ts';
|
|
import { unitNames } from '../game-data/datasets/unit-names.ts';
|
|
import { vehicleCatalogue } from '../game-data/datasets/vehicle-catalogue.ts';
|
|
import { vehicleEquipment } from '../game-data/datasets/vehicle-equipment.ts';
|
|
import { GameFiles } from '../game-data/game-files.ts';
|
|
import { InventoryCatalogue } from '../inventory/itemdef-catalogue.ts';
|
|
import { intField, stringField } from '../profile/blk-fields.ts';
|
|
import { allCrews, closedCrews } from '../profile/profile-crews.ts';
|
|
import { ACTIVE_LISTS } from '../profile/profile-items.ts';
|
|
import { normalizeModificationBlocks, recordName } from '../profile/profile-modifications.ts';
|
|
import { loadTuning } from '../tuning/tuning.ts';
|
|
import type { SaveLocation } from './save-editor.ts';
|
|
|
|
/** Validate a transferred profile and retain only the destination's vehicle and item identifiers. */
|
|
export function prepareTransferredProfile(location: SaveLocation, bytes: Uint8Array, filter: boolean): Uint8Array {
|
|
const profile = decodeBlk(bytes);
|
|
if (!filter) return bytes;
|
|
const packs = new GameFiles(location.gameFolder);
|
|
const datasets = new DatasetCache(location.dataFolder, packs, () => {});
|
|
const catalogue = datasets.load(vehicleCatalogue);
|
|
const vehicles = new Set(catalogue.map(({ name }) => name));
|
|
const classic = datasets.load(itemCatalogue);
|
|
const itemIds = new Set(classic.map(({ name }) => name));
|
|
const tuning = loadTuning(location.dataFolder, () => {});
|
|
const inventory = new InventoryCatalogue(catalogue, datasets.load(unitNames), datasets.load(externalItemSources), classic, tuning);
|
|
const modifications = new Set<string>();
|
|
const weapons = new Set<string>();
|
|
for (const equipment of datasets.load(vehicleEquipment)) {
|
|
for (const mod of equipment.modifications) modifications.add(recordName(equipment.vehicle, mod.name));
|
|
for (const weapon of equipment.weapons) weapons.add(recordName(equipment.vehicle, weapon.name));
|
|
weapons.add(recordName(equipment.vehicle, 'custom_presets'));
|
|
}
|
|
const blockKeys = [
|
|
['hangar', vehicles], ['unitResearch', vehicles], ['weaponPresets', vehicles],
|
|
['modifications', modifications], ['modsResearch', modifications], ['weapons', weapons],
|
|
] as const;
|
|
for (const [key, allowed] of blockKeys) {
|
|
for (const collection of profile.blocks) {
|
|
if (collection.name === key) {
|
|
collection.blocks = collection.blocks.filter((entry) => allowed.has(entry.name));
|
|
}
|
|
}
|
|
}
|
|
normalizeModificationBlocks(profile);
|
|
for (const crew of [...allCrews(profile), ...closedCrews(profile)]) {
|
|
const aircraft = findBlock(crew, 'aircrafts');
|
|
if (aircraft) {
|
|
aircraft.params = aircraft.params.filter(({ name, value }) =>
|
|
(name !== 'current' && name !== 'trained') || value.type !== 'string' ||
|
|
value.value === '' || vehicles.has(value.value));
|
|
}
|
|
}
|
|
const items = findBlock(profile, 'items');
|
|
if (items) {
|
|
items.blocks = items.blocks.filter((entry) => itemIds.has(stringField(entry, 'id')));
|
|
const uids = new Set(items.blocks.map(({ name }) => name));
|
|
for (const key of ACTIVE_LISTS) {
|
|
const list = findBlock(profile, key);
|
|
if (list) list.params = list.params.filter(({ value }) => value.type !== 'string' || uids.has(value.value));
|
|
}
|
|
}
|
|
const coupons = findBlock(profile, 'extInventory');
|
|
if (coupons) coupons.blocks = coupons.blocks.filter((entry) => inventory.hasItemDef(intField(entry, 'itemDefId')));
|
|
return encodeBlk(profile);
|
|
}
|