feat(launcher): add Bot parameters tuning page for ground AI and lineup weights

Extend readLauncherTuning/writeLauncherTuning and launcher IPC schemas to read, validate, and atomically persist battle.botPoolLimitPerType and nested ground-ai.jsonc overrides (including mode, vehicle class lineupWeights, spawn loadout, and all advanced ground AI sections). Add a dedicated Bot parameters section under Tuning with collapsible groups, bilingual labels, cross-field validation, and per-section reset. Verified with root/launcher typecheck, electron-vite build, 904-key locale parity check, and temp-dir read/write/reset round-trip.
This commit is contained in:
N0VAN0M4LY committed 2026-12-04 03:22:50 +08:00
1 parent 37cbcd806f
commit 2d3287937f
13 files changed
+1432 -22

No files matched your search

+1 -1
View File
@@ -12,5 +12,5 @@ export { listSaveAvatars, readSaveAvatar } from './saves/save-avatars.ts';
export { importOfficialBackup, previewOfficialBackup } from './saves/import/official-backup.ts';
export { prepareTransferredProfile } from './saves/transferred-profile.ts';
export { loadGroundAiTuning, type GroundAiTuning } from './tuning/ground-ai-tuning.ts';
export { readLauncherTuning, writeLauncherTuning, type LauncherTuningPatch } from './tuning/launcher-tuning.ts';
export { readLauncherTuning, writeLauncherTuning, type GroundAiTuningPatch, type LauncherTuningPatch } from './tuning/launcher-tuning.ts';
export { multiVehiclePackIds } from './store/store-pack-ids.ts';
+11 -6
View File
@@ -2,7 +2,13 @@
* Typed, range-validated reader for `tuning/ground-ai.jsonc`.
*/
import type { DiscoveredMod } from '@wto/mods';
import { GROUND_AI_MODES, type GroundAiConfig, type GroundAiMode } from '@wto/patcher';
import {
GROUND_AI_DRIVE_MODES,
GROUND_AI_MODES,
type GroundAiConfig,
type GroundAiDriveMode,
type GroundAiMode,
} from '@wto/patcher';
import type { TankLineupWeights } from '../battle/battle-ranks.ts';
import { tuningFiles } from './tuning-loader.ts';
import { TuningError, type TuningReader } from './tuning-reader.ts';
@@ -12,8 +18,6 @@ export interface GroundAiTuning extends GroundAiConfig {
readonly lineupWeights: TankLineupWeights;
}
const DRIVE_MODES = new Set(['vehicle_phys', 'movesys']);
export function loadGroundAiTuning(
dataFolder: string | null,
report: (line: string) => void,
@@ -170,9 +174,10 @@ function readTerrainSection(terrain: TuningReader): GroundAiTuning['terrain'] {
}
function readNavigationSection(nav: TuningReader): GroundAiTuning['navigation'] {
const driveMode = nav.string('driveMode');
if (!DRIVE_MODES.has(driveMode)) {
throw new TuningError(`tuning file ground-ai.jsonc: navigation.driveMode must be "vehicle_phys" or "movesys" (found "${driveMode}")`);
const driveModeRaw = nav.string('driveMode');
const driveMode = GROUND_AI_DRIVE_MODES.find((candidate): candidate is GroundAiDriveMode => candidate === driveModeRaw);
if (driveMode === undefined) {
throw new TuningError(`tuning file ground-ai.jsonc: navigation.driveMode must be "vehicle_phys" or "movesys" (found "${driveModeRaw}")`);
}
const steerSign = nav.number('steerSign', { min: -1, max: 1 });
if (steerSign !== 1 && steerSign !== -1) {
+76 -2
View File
@@ -6,6 +6,7 @@ import { readBattleTuning } from '../battle/battle-tuning.ts';
import { readNewProfileTuning } from '../profile/new-profile-tuning.ts';
import { readResearchTuning } from '../research/research-tuning.ts';
import { writeFileAtomic } from '../storage/atomic-file.ts';
import { readGroundAiTuning, type GroundAiTuning } from './ground-ai-tuning.ts';
import { tuningFiles, type TuningFiles } from './tuning-loader.ts';
import { TuningError } from './tuning-reader.ts';
@@ -14,6 +15,7 @@ function values(files: TuningFiles) {
const economy = readBattleEconomyTuning(files.read('battle-economy'));
const newProfile = readNewProfileTuning(files.read('new-profile')).startingBalance;
const research = readResearchTuning(files.read('research'));
const groundAi = readGroundAiTuning(files.read('ground-ai'));
return {
rewardMultiplierSilverLions: battle.rewardMultiplierSilverLions,
rewardMultiplierResearchPoints: battle.rewardMultiplierResearchPoints,
@@ -22,6 +24,7 @@ function values(files: TuningFiles) {
smallTeamsMaxPlayers: battle.smallTeamsMaxPlayers,
brSpreadMrank: battle.brSpreadMrank,
subModeChance: battle.subModeChance,
botPoolLimitPerType: battle.botPoolLimitPerType,
tankBotRespawns: battle.tankBotRespawns,
airBotRespawns: battle.airBotRespawns,
strikeUcavSpawnScore: battle.strikeUcavSpawnScore,
@@ -30,11 +33,27 @@ function values(files: TuningFiles) {
goldenEagles: newProfile.goldenEagles,
preferLineSuccessor: research.preferLineSuccessor,
autoTargetPick: research.autoTargetPick,
groundAi,
};
}
type Editable = ReturnType<typeof values>;
export type LauncherTuningPatch = { [K in keyof Editable]?: Editable[K] | undefined };
type FlatKey = Exclude<keyof Editable, 'groundAi'>;
type GroundAiSectionKey = Exclude<keyof GroundAiTuning, 'mode'>;
export type GroundAiTuningPatch = {
readonly mode?: GroundAiTuning['mode'] | undefined;
} & {
readonly [S in GroundAiSectionKey]?: {
readonly [K in keyof GroundAiTuning[S]]?: GroundAiTuning[S][K] | undefined;
} | undefined;
};
export type LauncherTuningPatch = {
readonly [K in FlatKey]?: Editable[K] | undefined;
} & {
readonly groundAi?: GroundAiTuningPatch | undefined;
};
const fileOf = {
rewardMultiplierSilverLions: 'battle',
@@ -44,6 +63,7 @@ const fileOf = {
smallTeamsMaxPlayers: 'battle',
brSpreadMrank: 'battle',
subModeChance: 'battle',
botPoolLimitPerType: 'battle',
tankBotRespawns: 'battle',
airBotRespawns: 'battle',
strikeUcavSpawnScore: 'battle',
@@ -52,7 +72,7 @@ const fileOf = {
goldenEagles: 'new-profile',
preferLineSuccessor: 'research',
autoTargetPick: 'research',
} as const satisfies Record<keyof Editable, string>;
} as const satisfies Record<FlatKey, string>;
interface OverrideFile {
readonly path: string;
@@ -68,6 +88,11 @@ export function writeLauncherTuning(dataFolder: string, patch: LauncherTuningPat
const { defaults, effective } = readLauncherTuning(dataFolder);
const changes = new Map<string, OverrideFile>();
for (const key of Object.keys(patch) as Array<keyof Editable>) {
if (key === 'groundAi') {
const groundPatch = patch.groundAi;
if (groundPatch) applyGroundAiPatch(dataFolder, groundPatch, defaults.groundAi, effective.groundAi, changes);
continue;
}
if (!Object.hasOwn(fileOf, key)) throw new TuningError(`Unknown launcher tuning field ${key}`);
const value = patch[key];
if (value === undefined || value === effective[key]) continue;
@@ -102,6 +127,55 @@ export function writeLauncherTuning(dataFolder: string, patch: LauncherTuningPat
return { defaults, effective: updated };
}
function applyGroundAiPatch(
dataFolder: string,
patch: GroundAiTuningPatch,
defaults: GroundAiTuning,
effective: GroundAiTuning,
changes: Map<string, OverrideFile>,
): void {
let file = changes.get('ground-ai');
const ensureFile = (): OverrideFile => {
if (!file) {
file = readOverride(join(dataFolder, 'tuning', 'ground-ai.jsonc'));
changes.set('ground-ai', file);
}
return file;
};
for (const key of Object.keys(patch) as Array<keyof GroundAiTuning>) {
if (!Object.hasOwn(defaults, key)) throw new TuningError(`Unknown ground AI tuning field ${key}`);
if (key === 'mode') {
const nextMode = patch.mode;
if (nextMode === undefined || nextMode === effective.mode) continue;
const target = ensureFile();
if (nextMode === defaults.mode) delete target.fields['mode'];
else target.fields['mode'] = nextMode;
continue;
}
const sectionPatch = patch[key];
if (!sectionPatch) continue;
const sectionDefaults = defaults[key] as Record<string, unknown>;
const sectionEffective = effective[key] as Record<string, unknown>;
for (const field of Object.keys(sectionPatch)) {
if (!Object.hasOwn(sectionDefaults, field)) {
throw new TuningError(`Unknown ground AI tuning field ${key}.${field}`);
}
const value = (sectionPatch as Record<string, unknown>)[field];
if (value === undefined || value === sectionEffective[field]) continue;
const target = ensureFile();
const existing = target.fields[key];
const sectionObj: Record<string, unknown> = existing !== null && typeof existing === 'object' && !Array.isArray(existing)
? { ...(existing as Record<string, unknown>) }
: {};
if (value === sectionDefaults[field]) delete sectionObj[field];
else sectionObj[field] = value;
if (Object.keys(sectionObj).length > 0) target.fields[key] = sectionObj;
else delete target.fields[key];
}
}
}
function readOverride(path: string): OverrideFile {
let previous: string;
try {