feat(mods): compose shared tech tree insertions

Accept manifest declarations for inserting vehicles into an existing research link. Compose shared links in mod load order after ordinary overlays and write matching shop and economy prerequisites. Validate anchors, rank order, and cycles, and document the manifest field.

Verified type checks, a 2.61.0.64 build with shared, folded, and cross-column insertions, load-order and disable readback, and the local server health endpoint. In-game acceptance remains pending.
This commit is contained in:
N0VAN0M4LY committed 2026-12-05 18:36:50 +08:00
1 parent 0843fde6ff
commit f86ab99c17
11 files changed
+313 -10

No files matched your search

@@ -226,6 +226,9 @@ export function computeModsBuildFingerprint(
hash.update(`port=${port};salt=${extraSalt}\n`);
for (const mod of mods) {
hash.update(`mod=${mod.manifest.id}@${mod.manifest.version}\n`);
if (mod.manifest.techTreeInsertions?.length) {
hash.update(`tech_tree_insertions=${JSON.stringify(mod.manifest.techTreeInsertions)}\n`);
}
const filesToStamp = [
...mod.content.packOperations.map((op) => op.sourceRelativePath),
...mod.content.guiPatchDirs,
+21 -6
View File
@@ -4,7 +4,7 @@
*/
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { decodeBlk, encodeBlk, isBinaryBlk, parseBlkText, parseSharedNameMap } from '@wto/blk';
import { decodeBlk, encodeBlk, isBinaryBlk, parseBlkText, parseSharedNameMap, type SharedNameContext } from '@wto/blk';
import {
applyBlkPatch,
applyBlkTextPatch,
@@ -18,6 +18,8 @@ import {
type ModdableClientPack,
} from '@wto/mods';
import { getFile, NAME_MAP_PATH, putFile, readArchive, writeArchive, type Archive } from '@wto/vromfs';
import { composeTechTreeInsertions, VEHICLE_ECONOMY_PATH } from '../tech-tree/compose-insertions.ts';
import { SHOP_PATH } from '../tech-tree/reveal-hidden-vehicles.ts';
export interface PackOverlayReport {
readonly pack: ModdableClientPack;
@@ -35,7 +37,10 @@ export function applyModPackOverlays(
ops: mod.content.packOperations.filter((op) => op.pack === packName),
}))
.filter((entry) => entry.ops.length > 0);
const totalOps = relevantMods.reduce((sum, entry) => sum + entry.ops.length, 0);
const insertions = packName === 'char.vromfs.bin'
? mods.flatMap(({ manifest }) => (manifest.techTreeInsertions ?? []).map((entry) => ({ ...entry, modId: manifest.id })))
: [];
const totalOps = relevantMods.reduce((sum, entry) => sum + entry.ops.length, insertions.length);
if (totalOps === 0) {
return { pack: basePack, report: { pack: packName, operationsApplied: 0 } };
}
@@ -74,10 +79,7 @@ export function applyModPackOverlays(
if (!resolvedPath) {
throw new Error(`${where}: target BLK "${op.targetPath}" not found in ${packName}`);
}
const raw = getFile(archive, resolvedPath);
const root = isBinaryBlk(raw)
? decodeBlk(raw, { names, dictionary })
: parseBlkText(Buffer.from(raw).toString('utf8'));
const root = readOverlayBlk(archive, resolvedPath, { names, dictionary });
const patchText = readFileSync(sourcePath, 'utf8');
if (op.sourceRelativePath.toLowerCase().endsWith('.patch.blk')) {
applyBlkTextPatch(root, patchText, {
@@ -123,12 +125,25 @@ export function applyModPackOverlays(
}
}
if (insertions.length > 0) {
const shop = readOverlayBlk(archive, SHOP_PATH, { names, dictionary });
const economy = readOverlayBlk(archive, VEHICLE_ECONOMY_PATH, { names, dictionary });
composeTechTreeInsertions(shop, economy, insertions);
putFile(archive, SHOP_PATH, encodeBlk(shop));
putFile(archive, VEHICLE_ECONOMY_PATH, encodeBlk(economy));
}
return {
pack: writeArchive(archive),
report: { pack: packName, operationsApplied: totalOps },
};
}
function readOverlayBlk(archive: Archive, path: string, shared: SharedNameContext) {
const raw = getFile(archive, path);
return isBinaryBlk(raw) ? decodeBlk(raw, shared) : parseBlkText(Buffer.from(raw).toString('utf8'));
}
function createArchiveIncludeResolver(params: {
readonly archive: Archive;
readonly names: readonly string[];