feat(saves): add save archives and copy transfers

This commit is contained in:
N0VAN0M4LY committed 2026-11-29 15:55:23 +08:00
1 parent 073a907617
commit d0a767e692
19 files changed
+660 -25

No files matched your search

+10
View File
@@ -78,6 +78,16 @@ export class AccountStore {
return account;
}
remove(userId: string): boolean {
const accounts = this.#file.accounts.filter((account) => account.userId !== userId);
if (accounts.length === this.#file.accounts.length) return false;
const file = { ...this.#file, accounts };
writeFileAtomic(this.#path, JSON.stringify(file, null, 2));
this.#file = file;
if (this.#lastSignedInUserId === userId) this.#lastSignedInUserId = undefined;
return true;
}
/**
* The account that most recently signed in during this service run (for defaulting the initial
* read-only account dropdown in the built-in browser; never used as a fallback on mutations).
+1
View File
@@ -7,4 +7,5 @@ export { AccountStore, type RegistrationResult } from './accounts/account-store.
export { REGISTRATION_PATH } from './accounts/registration-service.ts';
export { HEALTH_PATH } from './transport/http-listener.ts';
export { editSaveCurrencies, listSaveSummaries, readSaveDetails } from './saves/save-editor.ts';
export { prepareTransferredProfile } from './saves/transferred-profile.ts';
export { multiVehiclePackIds } from './store/store-pack-ids.ts';
@@ -0,0 +1,64 @@
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 } from '../profile/profile-crews.ts';
import { ACTIVE_LISTS } from '../profile/profile-items.ts';
import { 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) {
const collection = findBlock(profile, key);
if (collection) collection.blocks = collection.blocks.filter((entry) => allowed.has(entry.name));
}
for (const crew of allCrews(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);
}