feat(tuning): configure tuning for each game copy
This commit is contained in:
1 parent
61255f5473
commit
893d60854f
15 files changed
+440
-9
No files matched your search
@@ -2,6 +2,7 @@ import { app, BrowserWindow, dialog, shell } from 'electron';
|
||||
import { patchFeatures, recordedGameVersions } from '@wto/patcher';
|
||||
import { AppError } from '@shared/errors.ts';
|
||||
import { listBackgroundPictures } from '../services/background-art/art-catalog.ts';
|
||||
import { getCopyTuning, updateCopyTuning } from '../services/config/copy-tuning.ts';
|
||||
import { getSettings, updateSettings } from '../services/config/settings-store.ts';
|
||||
import { cancelMaintenance, maintainCopy, maintenanceInfo, maintenanceInProgress } from '../services/copies/copy-maintenance.ts';
|
||||
import { exportDiagnostics, openLogsFolder } from '../services/diagnostics/diagnostics.ts';
|
||||
@@ -127,6 +128,9 @@ export function registerIpcHandlers(): void {
|
||||
handle('saves:research', ({ copyId, userId, branch }) => getSaveResearch(copyId, userId, branch));
|
||||
handle('saves:editResearch', ({ copyId, userId, branch, action }) => changeSaveResearch(copyId, userId, branch, action));
|
||||
|
||||
handle('tuning:get', ({ copyId }) => getCopyTuning(copyId));
|
||||
handle('tuning:update', ({ copyId, patch }) => updateCopyTuning(copyId, patch));
|
||||
|
||||
handle('launch:getState', () => getLaunchState());
|
||||
handle('launch:getLabInfo', () => readInstalledLab().catch(() => null));
|
||||
handle('launch:start', () => {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user