Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
71 lines
3.3 KiB
TypeScript
71 lines
3.3 KiB
TypeScript
/**
|
|
* Build an optional asset pack by downloading the public images that the local
|
|
* pages use into <data folder>/asset-pack/, so the pages show official pictures without a network
|
|
* connection. Run it on a machine that can reach the official sites; nothing is shipped with
|
|
* the project, every player makes their own copy.
|
|
*
|
|
* node apps/server/src/asset-pack-cli.ts --data <data folder> [--concurrency 6]
|
|
*
|
|
* Sources: official marketplace art and vehicle renders, plus store covers and screenshots.
|
|
* The storefront links videos directly.
|
|
* Files keep their host/path layout (static-ggc.gaijin.net/units/x.png); index.json lists them.
|
|
* The pages read the pack first (web-ui/web/common.js `sourcesFor`).
|
|
*/
|
|
import { existsSync, readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { parseArgs } from 'node:util';
|
|
import { writeFileAtomic } from './storage/atomic-file.ts';
|
|
|
|
const MARKET_IMAGES = new URL('./web-ui/web/official-images.json', import.meta.url);
|
|
const STORE_MEDIA = new URL('./web-ui/web/official-store-media.json', import.meta.url);
|
|
|
|
async function main(): Promise<number> {
|
|
const { values } = parseArgs({ options: { data: { type: 'string' }, concurrency: { type: 'string', default: '6' } } });
|
|
if (!values.data) {
|
|
console.error('usage: asset-pack-cli.ts --data <data folder> [--concurrency 6]');
|
|
return 2;
|
|
}
|
|
const packDir = join(values.data, 'asset-pack');
|
|
const table = JSON.parse(readFileSync(MARKET_IMAGES, 'utf8')) as { base: string; byKey: Record<string, string> };
|
|
const store = JSON.parse(readFileSync(STORE_MEDIA, 'utf8')) as {
|
|
base: string;
|
|
byProduct: Record<string, { cover: string; screenshots?: string[] }>;
|
|
};
|
|
const urls = new Set<string>();
|
|
for (const [key, path] of Object.entries(table.byKey)) {
|
|
urls.add(table.base + path);
|
|
if (path.startsWith('units/')) urls.add(`https://static.encyclopedia.warthunder.com/images/${key.toLowerCase()}.png`);
|
|
}
|
|
for (const { cover, screenshots = [] } of Object.values(store.byProduct)) {
|
|
urls.add(store.base + cover);
|
|
for (const screenshot of screenshots) urls.add(store.base + screenshot);
|
|
}
|
|
const indexFile = join(packDir, 'index.json');
|
|
const done = new Set<string>(existsSync(indexFile) ? JSON.parse(readFileSync(indexFile, 'utf8')) as string[] : []);
|
|
const queue = [...urls].filter((url) => !done.has(url.replace(/^https?:\/\//, '')));
|
|
let failed = 0;
|
|
const worker = async (): Promise<void> => {
|
|
for (let url = queue.shift(); url; url = queue.shift()) {
|
|
const relative = url.replace(/^https?:\/\//, '');
|
|
try {
|
|
const response = await fetch(url, { signal: AbortSignal.timeout(15000) });
|
|
if (!response.ok || !response.headers.get('content-type')?.startsWith('image/')) {
|
|
await response.body?.cancel();
|
|
failed += 1;
|
|
continue;
|
|
}
|
|
writeFileAtomic(join(packDir, relative), Buffer.from(await response.arrayBuffer()));
|
|
done.add(relative);
|
|
} catch {
|
|
failed += 1;
|
|
}
|
|
}
|
|
};
|
|
await Promise.all(Array.from({ length: Math.max(1, Number(values.concurrency)) }, worker));
|
|
writeFileAtomic(indexFile, JSON.stringify([...done].sort()));
|
|
console.log(`asset pack: ${done.size} file(s) in ${packDir}; ${failed} not available`);
|
|
return 0;
|
|
}
|
|
|
|
process.exitCode = await main();
|