feat(tuning): configure tuning for each game copy

This commit is contained in:
N0VAN0M4LY committed 2026-11-29 16:24:21 +08:00
1 parent 61255f5473
commit 893d60854f
15 files changed
+440 -9

No files matched your search

@@ -0,0 +1,32 @@
import { readLauncherTuning, writeLauncherTuning, type LauncherTuningPatch } from '@wto/server';
import { AppError } from '@shared/errors.ts';
import type { TuningView } from '@shared/schemas/tuning.ts';
import { listCopies } from '../install/install-record.ts';
import { getLaunchState } from '../launch/launch-controller.ts';
async function dataFolder(copyId: string): Promise<string> {
const copy = (await listCopies()).copies.find(({ id }) => id === copyId);
if (!copy) throw new AppError('copy_not_found');
return copy.dataPath;
}
export async function getCopyTuning(copyId: string): Promise<TuningView> {
const folder = await dataFolder(copyId);
try {
return readLauncherTuning(folder);
} catch (error) {
console.error('[tuning] could not read the copy settings:', error);
throw new AppError('tuning_invalid');
}
}
export async function updateCopyTuning(copyId: string, patch: LauncherTuningPatch): Promise<TuningView> {
const folder = await dataFolder(copyId);
if (['checking', 'building', 'starting-server'].includes(getLaunchState().phase)) throw new AppError('launch_busy');
try {
return writeLauncherTuning(folder, patch);
} catch (error) {
console.error('[tuning] could not save the copy settings:', error);
throw new AppError('tuning_invalid');
}
}