Files
WT-Offline/packages/local-service/src/game-data/game-files.ts
T
N0VAN0M4LY 1d9c92a9d0 feat(battle): serve game modes from extracted mission data
Publish stable mode IDs and matching responses in the stock format.
Build the mission pools from the multiplayer mission data and provide
required fields and localized names. Load datasets before listening and
reuse cached results when the source file digests match.

Preserve invalid UTF-8 bytes when round-tripping BLK strings and names.
The game mode list appeared in the offline client.
2026-11-24 11:02:30 +08:00

56 lines
1.5 KiB
TypeScript

/**
* The game files the local service reads, opened lazily from the player's game folder.
*/
import { statSync } from 'node:fs';
import { join } from 'node:path';
import type { BlkBlock } from '@wto/blk';
import { GamePack } from './game-pack.ts';
/** The data packs the local service reads (file names in the game folder). */
export type GamePackName = 'char.vromfs.bin' | 'mis.vromfs.bin';
/** What identifies one version of a pack file cheaply (implementation notes, first check). */
export interface PackStamp {
readonly size: number;
readonly mtimeMs: number;
}
/** Gaijin's template for a new account's profile. */
const NEW_ACCOUNT_TEMPLATE = 'config/default_user.blk';
export class GameFiles {
readonly #gameFolder: string;
readonly #packs = new Map<GamePackName, GamePack>();
constructor(gameFolder: string) {
this.#gameFolder = gameFolder;
}
newAccountTemplate(): BlkBlock {
return this.pack('char.vromfs.bin').readBlk(NEW_ACCOUNT_TEMPLATE);
}
pack(name: GamePackName): GamePack {
let pack = this.#packs.get(name);
if (!pack) {
pack = GamePack.open(this.#packPath(name));
this.#packs.set(name, pack);
}
return pack;
}
/** Drop the opened packs (they are reopened on demand); called after start-up extraction. */
releasePacks(): void {
this.#packs.clear();
}
packStamp(name: GamePackName): PackStamp {
const { size, mtimeMs } = statSync(this.#packPath(name));
return { size, mtimeMs };
}
#packPath(name: GamePackName): string {
return join(this.#gameFolder, name);
}
}