feat(launcher): add Mods page, per-client presets, custom repo folder, and launch integration
This commit is contained in:
1 parent
aa7a6e7d02
commit
dbc21182a2
21 files changed
+1961
-21
No files matched your search
@@ -14,6 +14,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource/roboto-condensed": "^5.3.0",
|
||||
"@wto/mods": "*",
|
||||
"@wto/patcher": "*",
|
||||
"@wto/server": "*",
|
||||
"fflate": "^0.8.2",
|
||||
|
||||
@@ -17,6 +17,19 @@ import { canonicalCopyPath, copyFolderMissing, createCopyDraft, hydrateCopiesSta
|
||||
import { readInstalledLab } from '../services/launch/lab-handoff.ts';
|
||||
import { getLaunchState, launchInProgress, openServerStatus, startLaunch, stopLaunch } from '../services/launch/launch-controller.ts';
|
||||
import { activePatchSet, applyPackUpdate, checkPackUpdate, revertToBundledPatchSet } from '../services/patch-pack/pack-update.ts';
|
||||
import {
|
||||
applyModPreset,
|
||||
autoSortMods,
|
||||
deleteModPreset,
|
||||
exportModPreset,
|
||||
getModsState,
|
||||
importModPreset,
|
||||
openModsFolder,
|
||||
saveModPreset,
|
||||
setModEnabled,
|
||||
setModsFolder,
|
||||
setModsOrder,
|
||||
} from '../services/mods/mods-service.ts';
|
||||
import { resourcePaths } from '../services/resources/resource-paths.ts';
|
||||
import { changeSaveAccount, changeSaveResearch, copyOnlineData, createSave, discoverOnlineData, exportSave, getSaveAvatarChoices, getSaveAvatarPreview, getSaveDetails, getSaveList, getSaveResearch, importSelectedBackups, listSaveBackups, pickOfficialBackups, pickSaveArchive, previewSelectedBackups, removeSave, restoreSaveBackup, saveWriteInProgress, selectSave, setSaveCurrencies, takeSaveBackup, transferSave } from '../services/saves/manage-saves.ts';
|
||||
import { broadcast, handle } from './register.ts';
|
||||
@@ -175,6 +188,48 @@ export function registerIpcHandlers(): void {
|
||||
handle('tuning:get', ({ copyId }) => getCopyTuning(copyId));
|
||||
handle('tuning:update', ({ copyId, patch }) => updateCopyTuning(copyId, patch));
|
||||
|
||||
const requireModsWritable = (): void => {
|
||||
if (launchInProgress() || maintenanceInProgress()) throw new AppError('mods_read_only');
|
||||
};
|
||||
handle('mods:getState', ({ copyId }) => getModsState(copyId));
|
||||
handle('mods:setEnabled', ({ copyId, modId, enabled }) => {
|
||||
requireModsWritable();
|
||||
return setModEnabled(copyId, modId, enabled);
|
||||
});
|
||||
handle('mods:setOrder', ({ copyId, order }) => {
|
||||
requireModsWritable();
|
||||
return setModsOrder(copyId, order);
|
||||
});
|
||||
handle('mods:autoSort', ({ copyId }) => {
|
||||
requireModsWritable();
|
||||
return autoSortMods(copyId);
|
||||
});
|
||||
handle('mods:savePreset', ({ copyId, name, overwriteId }) => {
|
||||
requireModsWritable();
|
||||
return saveModPreset(copyId, name, overwriteId);
|
||||
});
|
||||
handle('mods:applyPreset', ({ copyId, presetId }) => {
|
||||
requireModsWritable();
|
||||
return applyModPreset(copyId, presetId);
|
||||
});
|
||||
handle('mods:deletePreset', ({ copyId, presetId }) => {
|
||||
requireModsWritable();
|
||||
return deleteModPreset(copyId, presetId);
|
||||
});
|
||||
handle('mods:exportPreset', ({ copyId, presetId }, sender) =>
|
||||
exportModPreset(copyId, presetId, BrowserWindow.fromWebContents(sender)));
|
||||
handle('mods:importPreset', ({ copyId }, sender) => {
|
||||
requireModsWritable();
|
||||
return importModPreset(copyId, BrowserWindow.fromWebContents(sender));
|
||||
});
|
||||
handle('mods:openFolder', () => openModsFolder());
|
||||
handle('mods:setFolder', async ({ copyId, path }) => {
|
||||
requireModsWritable();
|
||||
const state = await setModsFolder(copyId, path);
|
||||
broadcast('event:settings-changed', await getSettings());
|
||||
return state;
|
||||
});
|
||||
|
||||
handle('launch:getState', () => getLaunchState());
|
||||
handle('launch:getLabInfo', () => readInstalledLab().catch(() => null));
|
||||
handle('launch:start', () => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { Settings } from '@shared/schemas/settings.ts';
|
||||
import { getSettings } from '../config/settings-store.ts';
|
||||
import { decalCachePath } from '../install/decals.ts';
|
||||
import { canonicalCopyPath, copyPathContains, readInstallRecord } from '../install/install-record.ts';
|
||||
import { resolveEnabledModsForLaunch } from '../mods/mods-service.ts';
|
||||
import { resourcePaths } from '../resources/resource-paths.ts';
|
||||
import { saveBackup } from '../saves/save-archive.ts';
|
||||
import { buildCopy } from './build-copy.ts';
|
||||
@@ -108,7 +109,7 @@ async function launch(job: LaunchJob): Promise<void> {
|
||||
job.copyId = record.id;
|
||||
const plan = await planLaunch(job, record, settings);
|
||||
if (plan === null) return;
|
||||
const { lab, copyPath, stockPath, dataPath, port } = plan;
|
||||
const { lab, copyPath, stockPath, dataPath, port, modsDir, enabledModIds } = plan;
|
||||
await buildForLaunch(job, record, plan, settings);
|
||||
|
||||
const publish = (phase: LaunchState['phase'], gameExit?: GameExit): void => {
|
||||
@@ -123,7 +124,15 @@ async function launch(job: LaunchJob): Promise<void> {
|
||||
update(job, { phase: 'ready' });
|
||||
return;
|
||||
}
|
||||
const gameExit = await runOrdinaryLaunch(copyPath, dataPath, port, settings, signal, publish);
|
||||
const gameExit = await runOrdinaryLaunch(
|
||||
copyPath,
|
||||
dataPath,
|
||||
port,
|
||||
settings,
|
||||
signal,
|
||||
publish,
|
||||
{ modsDir, enabledModIds },
|
||||
);
|
||||
update(job, { phase: 'game-exited', gameExit });
|
||||
}
|
||||
|
||||
@@ -134,6 +143,8 @@ interface LaunchPlan {
|
||||
readonly dataPath: string;
|
||||
readonly steamLibraryConfirmed: boolean;
|
||||
readonly port: number;
|
||||
readonly modsDir: string;
|
||||
readonly enabledModIds: readonly string[];
|
||||
}
|
||||
|
||||
async function planLaunch(job: LaunchJob, record: InstallRecord, settings: Settings): Promise<LaunchPlan | null> {
|
||||
@@ -183,13 +194,15 @@ async function planLaunch(job: LaunchJob, record: InstallRecord, settings: Setti
|
||||
throw new AppError(lab ? 'launch_lab_version' : 'launch_stock_version');
|
||||
}
|
||||
if (games) throw new AppError('launch_game_running');
|
||||
const { modsDir, enabledMods } = await resolveEnabledModsForLaunch(dataPath, copyVersion);
|
||||
const enabledModIds = enabledMods.map((mod) => mod.manifest.id);
|
||||
const port = await selectPort(requestedPort);
|
||||
return { lab, copyPath, stockPath, dataPath, steamLibraryConfirmed, port };
|
||||
return { lab, copyPath, stockPath, dataPath, steamLibraryConfirmed, port, modsDir, enabledModIds };
|
||||
}
|
||||
|
||||
async function buildForLaunch(job: LaunchJob, record: InstallRecord, plan: LaunchPlan, settings: Settings): Promise<void> {
|
||||
const signal = job.stop.signal;
|
||||
const { lab, copyPath, stockPath, dataPath, port, steamLibraryConfirmed } = plan;
|
||||
const { lab, copyPath, stockPath, dataPath, port, steamLibraryConfirmed, modsDir, enabledModIds } = plan;
|
||||
if (settings.autoSaveBackups) {
|
||||
for (const { userId } of new AccountStore(dataPath).all()) {
|
||||
signal.throwIfAborted();
|
||||
@@ -211,6 +224,8 @@ async function buildForLaunch(job: LaunchJob, record: InstallRecord, plan: Launc
|
||||
...(record.decalCacheId ? { decalCache: decalCachePath(lab ? record.dataPath : dataPath, record.decalCacheId) } : {}),
|
||||
hookLogging: settings.loggingEnabled,
|
||||
acceptedUnavailable: record.unavailablePatches.map(({ patchId }) => patchId),
|
||||
modsDir,
|
||||
enabledModIds,
|
||||
}, signal, (filesWritten, filesTotal, file) => {
|
||||
writtenFiles = filesWritten;
|
||||
if (!signal.aborted) update(job, {
|
||||
|
||||
@@ -33,13 +33,22 @@ export async function localServerReady(port: number, pid?: number, signal?: Abor
|
||||
}
|
||||
}
|
||||
|
||||
export interface StartLocalServerOptions extends Omit<ServerOptions, 'report' | 'mods'> {
|
||||
readonly modsDir?: string;
|
||||
readonly enabledModIds?: readonly string[];
|
||||
}
|
||||
|
||||
export async function startLocalServer(
|
||||
{ gameFolder, dataFolder, port, loggingEnabled = true }: Omit<ServerOptions, 'report'>, signal: AbortSignal,
|
||||
{ gameFolder, dataFolder, port, loggingEnabled = true, modsDir, enabledModIds }: StartLocalServerOptions, signal: AbortSignal,
|
||||
): Promise<LocalServer> {
|
||||
signal.throwIfAborted();
|
||||
const workerArgs = [gameFolder, dataFolder, String(port), loggingEnabled ? '1' : '0'];
|
||||
if (modsDir && enabledModIds && enabledModIds.length > 0) {
|
||||
workerArgs.push(modsDir, JSON.stringify(enabledModIds));
|
||||
}
|
||||
const worker = utilityProcess.fork(
|
||||
join(import.meta.dirname, 'server-worker.js'),
|
||||
[gameFolder, dataFolder, String(port), loggingEnabled ? '1' : '0'],
|
||||
workerArgs,
|
||||
{
|
||||
serviceName: 'WTOffline local server',
|
||||
stdio: 'pipe',
|
||||
|
||||
@@ -45,12 +45,19 @@ type OrdinaryPhase = 'starting-server' | 'starting-game' | 'running' | 'server-r
|
||||
export async function runOrdinaryLaunch(
|
||||
copyPath: string, dataPath: string, port: number, settings: Settings, signal: AbortSignal,
|
||||
publish: (phase: OrdinaryPhase, gameExit?: GameExit) => void,
|
||||
mods?: { readonly modsDir: string; readonly enabledModIds: readonly string[] },
|
||||
): Promise<GameExit> {
|
||||
const args = parseLaunchArguments(settings.launchArguments);
|
||||
if (!args) throw new AppError('launch_game_failed');
|
||||
publish('starting-server');
|
||||
const server = await startLocalServer(
|
||||
{ gameFolder: copyPath, dataFolder: dataPath, port, loggingEnabled: settings.loggingEnabled },
|
||||
{
|
||||
gameFolder: copyPath,
|
||||
dataFolder: dataPath,
|
||||
port,
|
||||
loggingEnabled: settings.loggingEnabled,
|
||||
...(mods && mods.enabledModIds.length > 0 ? { modsDir: mods.modsDir, enabledModIds: mods.enabledModIds } : {}),
|
||||
},
|
||||
signal,
|
||||
);
|
||||
const stop = new AbortController();
|
||||
|
||||
@@ -0,0 +1,351 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
||||
import { isAbsolute, join } from 'node:path';
|
||||
import { app, BrowserWindow, dialog, shell } from 'electron';
|
||||
import {
|
||||
computeAutoSortOrder,
|
||||
discoverMods,
|
||||
emptyClientModsConfig,
|
||||
MOD_API_VERSION,
|
||||
normalizeClientModsConfig,
|
||||
resolveModLoadOrder,
|
||||
type ClientModsConfig,
|
||||
type DiscoveredMod,
|
||||
type ModPreset,
|
||||
} from '@wto/mods';
|
||||
import { AppError } from '@shared/errors.ts';
|
||||
import type { InstallRecord } from '@shared/schemas/install.ts';
|
||||
import { ModPresetTransferSchema, type ModListItem, type ModsStateView } from '@shared/schemas/mods.ts';
|
||||
import { readJsonOr, writeJsonAtomic } from '../../util/atomic-json.ts';
|
||||
import { getSettings, updateSettings } from '../config/settings-store.ts';
|
||||
import { listCopies } from '../install/install-record.ts';
|
||||
|
||||
const CLIENT_MODS_CONFIG_FILE = 'mods-config.json';
|
||||
|
||||
export function defaultModsFolder(): string {
|
||||
return join(app.getPath('userData'), 'mods');
|
||||
}
|
||||
|
||||
export async function resolveModsFolder(): Promise<{ readonly modsDir: string; readonly defaultModsDir: string; readonly isCustomModsDir: boolean }> {
|
||||
const settings = await getSettings();
|
||||
const defaultModsDir = defaultModsFolder();
|
||||
const isCustomModsDir = settings.modsFolder !== null;
|
||||
const modsDir = settings.modsFolder ?? defaultModsDir;
|
||||
await mkdir(modsDir, { recursive: true });
|
||||
return { modsDir, defaultModsDir, isCustomModsDir };
|
||||
}
|
||||
|
||||
export async function openModsFolder(): Promise<void> {
|
||||
const { modsDir } = await resolveModsFolder();
|
||||
const failure = await shell.openPath(modsDir);
|
||||
if (failure) console.warn('[mods] opening the mods folder failed:', modsDir, failure);
|
||||
}
|
||||
|
||||
export async function getModsState(copyId: string): Promise<ModsStateView> {
|
||||
const copy = await requireCopy(copyId);
|
||||
return buildModsStateView(copy);
|
||||
}
|
||||
|
||||
export async function setModEnabled(copyId: string, modId: string, enabled: boolean): Promise<ModsStateView> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const { modsDir } = await resolveModsFolder();
|
||||
const discovered = discoverMods(modsDir);
|
||||
const current = normalizeClientModsConfig(await readClientModsConfig(copy.dataPath), discovered.mods);
|
||||
const next: ClientModsConfig = {
|
||||
...current,
|
||||
activePresetId: null,
|
||||
enabled: { ...current.enabled, [modId]: enabled },
|
||||
};
|
||||
await writeClientModsConfig(copy.dataPath, next);
|
||||
return buildModsStateView(copy, next);
|
||||
}
|
||||
|
||||
export async function setModsOrder(copyId: string, order: readonly string[]): Promise<ModsStateView> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const { modsDir } = await resolveModsFolder();
|
||||
const discovered = discoverMods(modsDir);
|
||||
const current = normalizeClientModsConfig(await readClientModsConfig(copy.dataPath), discovered.mods);
|
||||
const next = normalizeClientModsConfig({ ...current, activePresetId: null, order }, discovered.mods);
|
||||
await writeClientModsConfig(copy.dataPath, next);
|
||||
return buildModsStateView(copy, next);
|
||||
}
|
||||
|
||||
export async function autoSortMods(copyId: string): Promise<ModsStateView> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const { modsDir } = await resolveModsFolder();
|
||||
const discovered = discoverMods(modsDir);
|
||||
const current = normalizeClientModsConfig(await readClientModsConfig(copy.dataPath), discovered.mods);
|
||||
const sortedOrder = computeAutoSortOrder(discovered.mods, current.order);
|
||||
const next: ClientModsConfig = {
|
||||
...current,
|
||||
activePresetId: null,
|
||||
order: sortedOrder,
|
||||
};
|
||||
await writeClientModsConfig(copy.dataPath, next);
|
||||
return buildModsStateView(copy, next);
|
||||
}
|
||||
|
||||
export async function saveModPreset(copyId: string, name: string, overwriteId?: string): Promise<ModsStateView> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const { modsDir } = await resolveModsFolder();
|
||||
const discovered = discoverMods(modsDir);
|
||||
const current = normalizeClientModsConfig(await readClientModsConfig(copy.dataPath), discovered.mods);
|
||||
const now = new Date().toISOString();
|
||||
|
||||
let presets: ModPreset[];
|
||||
let presetId: string;
|
||||
if (overwriteId && current.presets.some((preset) => preset.id === overwriteId)) {
|
||||
presetId = overwriteId;
|
||||
presets = current.presets.map((preset) => (
|
||||
preset.id === overwriteId
|
||||
? { id: preset.id, name, order: [...current.order], enabled: { ...current.enabled }, updatedAt: now }
|
||||
: preset
|
||||
));
|
||||
} else {
|
||||
presetId = randomUUID();
|
||||
presets = [
|
||||
...current.presets,
|
||||
{ id: presetId, name, order: [...current.order], enabled: { ...current.enabled }, updatedAt: now },
|
||||
];
|
||||
}
|
||||
|
||||
const next: ClientModsConfig = {
|
||||
...current,
|
||||
activePresetId: presetId,
|
||||
presets,
|
||||
};
|
||||
await writeClientModsConfig(copy.dataPath, next);
|
||||
return buildModsStateView(copy, next);
|
||||
}
|
||||
|
||||
export async function applyModPreset(copyId: string, presetId: string): Promise<ModsStateView> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const { modsDir } = await resolveModsFolder();
|
||||
const discovered = discoverMods(modsDir);
|
||||
const current = normalizeClientModsConfig(await readClientModsConfig(copy.dataPath), discovered.mods);
|
||||
const preset = current.presets.find((item) => item.id === presetId);
|
||||
if (!preset) throw new AppError('mods_preset_invalid');
|
||||
|
||||
const next = normalizeClientModsConfig({
|
||||
...current,
|
||||
order: preset.order,
|
||||
enabled: preset.enabled,
|
||||
activePresetId: preset.id,
|
||||
}, discovered.mods);
|
||||
await writeClientModsConfig(copy.dataPath, next);
|
||||
return buildModsStateView(copy, next);
|
||||
}
|
||||
|
||||
export async function deleteModPreset(copyId: string, presetId: string): Promise<ModsStateView> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const current = await readClientModsConfig(copy.dataPath);
|
||||
const next: ClientModsConfig = {
|
||||
...current,
|
||||
activePresetId: current.activePresetId === presetId ? null : current.activePresetId,
|
||||
presets: current.presets.filter((preset) => preset.id !== presetId),
|
||||
};
|
||||
await writeClientModsConfig(copy.dataPath, next);
|
||||
return buildModsStateView(copy, next);
|
||||
}
|
||||
|
||||
export async function exportModPreset(
|
||||
copyId: string,
|
||||
presetId: string,
|
||||
window: BrowserWindow | null,
|
||||
): Promise<{ readonly path: string | null }> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const current = await readClientModsConfig(copy.dataPath);
|
||||
const preset = current.presets.find((item) => item.id === presetId);
|
||||
if (!preset) throw new AppError('mods_preset_invalid');
|
||||
|
||||
const safeName = preset.name.replace(/[^A-Za-z0-9\u4e00-\u9fa5._-]+/g, '-').replace(/^-+|-+$/g, '') || 'preset';
|
||||
const dialogOptions = {
|
||||
defaultPath: `${safeName}.wto-mods-preset.json`,
|
||||
filters: [{ name: 'WTOffline Mod Preset', extensions: ['json'] }],
|
||||
};
|
||||
const choice = window
|
||||
? await dialog.showSaveDialog(window, dialogOptions)
|
||||
: await dialog.showSaveDialog(dialogOptions);
|
||||
if (choice.canceled || !choice.filePath) return { path: null };
|
||||
|
||||
const payload = {
|
||||
format: 1 as const,
|
||||
name: preset.name,
|
||||
order: [...preset.order],
|
||||
enabled: { ...preset.enabled },
|
||||
};
|
||||
await writeFile(choice.filePath, JSON.stringify(payload, null, 2) + '\n', 'utf8');
|
||||
return { path: choice.filePath };
|
||||
}
|
||||
|
||||
export async function importModPreset(
|
||||
copyId: string,
|
||||
window: BrowserWindow | null,
|
||||
): Promise<{ readonly imported: boolean; readonly state: ModsStateView }> {
|
||||
const copy = await requireCopy(copyId);
|
||||
const dialogOptions = {
|
||||
properties: ['openFile'] as Array<'openFile'>,
|
||||
filters: [{ name: 'WTOffline Mod Preset', extensions: ['json'] }],
|
||||
};
|
||||
const choice = window
|
||||
? await dialog.showOpenDialog(window, dialogOptions)
|
||||
: await dialog.showOpenDialog(dialogOptions);
|
||||
if (choice.canceled || !choice.filePaths[0]) {
|
||||
return { imported: false, state: await buildModsStateView(copy) };
|
||||
}
|
||||
|
||||
let parsedRaw: unknown;
|
||||
try {
|
||||
parsedRaw = JSON.parse(await readFile(choice.filePaths[0], 'utf8')) as unknown;
|
||||
} catch {
|
||||
throw new AppError('mods_preset_invalid');
|
||||
}
|
||||
const validated = ModPresetTransferSchema.safeParse(parsedRaw);
|
||||
if (!validated.success) throw new AppError('mods_preset_invalid');
|
||||
|
||||
const current = await readClientModsConfig(copy.dataPath);
|
||||
const newPreset: ModPreset = {
|
||||
id: randomUUID(),
|
||||
name: validated.data.name,
|
||||
order: validated.data.order,
|
||||
enabled: validated.data.enabled,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
const next: ClientModsConfig = {
|
||||
...current,
|
||||
presets: [...current.presets, newPreset],
|
||||
};
|
||||
await writeClientModsConfig(copy.dataPath, next);
|
||||
return { imported: true, state: await buildModsStateView(copy, next) };
|
||||
}
|
||||
|
||||
export async function setModsFolder(copyId: string, folderPath: string | null): Promise<ModsStateView> {
|
||||
if (folderPath !== null) {
|
||||
if (!isAbsolute(folderPath)) throw new AppError('mods_folder_invalid');
|
||||
try {
|
||||
await mkdir(folderPath, { recursive: true });
|
||||
const info = await stat(folderPath);
|
||||
if (!info.isDirectory()) throw new AppError('mods_folder_invalid');
|
||||
} catch (error) {
|
||||
if (error instanceof AppError) throw error;
|
||||
throw new AppError('mods_folder_invalid');
|
||||
}
|
||||
}
|
||||
await updateSettings({ modsFolder: folderPath });
|
||||
const copy = await requireCopy(copyId);
|
||||
return buildModsStateView(copy);
|
||||
}
|
||||
|
||||
/** Resolve ordered enabled mods for a launch; rejects when blocking dependency/conflict errors exist. */
|
||||
export async function resolveEnabledModsForLaunch(
|
||||
dataPath: string,
|
||||
gameVersion: string | null,
|
||||
): Promise<{ readonly modsDir: string; readonly enabledMods: readonly DiscoveredMod[] }> {
|
||||
const { modsDir } = await resolveModsFolder();
|
||||
const discovered = discoverMods(modsDir);
|
||||
const config = normalizeClientModsConfig(await readClientModsConfig(dataPath), discovered.mods);
|
||||
const resolved = resolveModLoadOrder(discovered.mods, config, gameVersion);
|
||||
if (resolved.hasBlockingErrors) {
|
||||
console.error('[mods] blocking mod issues prevented launch:', resolved.issues.filter((i) => i.severity === 'error'));
|
||||
throw new AppError('mods_blocking_issues');
|
||||
}
|
||||
return { modsDir, enabledMods: resolved.enabledMods };
|
||||
}
|
||||
|
||||
async function buildModsStateView(copy: InstallRecord, preloadedConfig?: ClientModsConfig): Promise<ModsStateView> {
|
||||
const { modsDir, defaultModsDir, isCustomModsDir } = await resolveModsFolder();
|
||||
const discovered = discoverMods(modsDir);
|
||||
const rawConfig = preloadedConfig ?? await readClientModsConfig(copy.dataPath);
|
||||
const config = normalizeClientModsConfig(rawConfig, discovered.mods);
|
||||
const resolved = resolveModLoadOrder(discovered.mods, config, copy.gameVersion);
|
||||
|
||||
const byId = new Map(discovered.mods.map((mod) => [mod.manifest.id, mod]));
|
||||
const orderedMods: ModListItem[] = config.order
|
||||
.map((id) => byId.get(id))
|
||||
.filter((mod): mod is DiscoveredMod => mod !== undefined)
|
||||
.map(toModListItem);
|
||||
|
||||
return {
|
||||
modsDir,
|
||||
defaultModsDir,
|
||||
isCustomModsDir,
|
||||
apiVersion: MOD_API_VERSION,
|
||||
mods: orderedMods,
|
||||
discoveryErrors: [...discovered.errors],
|
||||
order: [...config.order],
|
||||
enabled: { ...config.enabled },
|
||||
activePresetId: config.activePresetId,
|
||||
presets: config.presets.map((preset) => ({
|
||||
id: preset.id,
|
||||
name: preset.name,
|
||||
order: [...preset.order],
|
||||
enabled: { ...preset.enabled },
|
||||
updatedAt: preset.updatedAt,
|
||||
})),
|
||||
issues: [...resolved.issues],
|
||||
hasBlockingErrors: resolved.hasBlockingErrors,
|
||||
};
|
||||
}
|
||||
|
||||
function toModListItem(mod: DiscoveredMod): ModListItem {
|
||||
return {
|
||||
id: mod.manifest.id,
|
||||
folderName: mod.folderName,
|
||||
rootDir: mod.rootDir,
|
||||
name: mod.manifest.name,
|
||||
...(mod.manifest.description !== undefined ? { description: mod.manifest.description } : {}),
|
||||
version: mod.manifest.version,
|
||||
author: mod.manifest.author,
|
||||
apiVersion: mod.manifest.apiVersion,
|
||||
gameVersions: [...mod.manifest.gameVersions],
|
||||
requires: [...mod.manifest.requires],
|
||||
conflicts: [...mod.manifest.conflicts],
|
||||
loadAfter: [...mod.manifest.loadAfter],
|
||||
loadBefore: [...mod.manifest.loadBefore],
|
||||
badges: [...mod.content.badges],
|
||||
hasServerScript: mod.content.serverEntry !== undefined,
|
||||
serverTuningFiles: [...mod.content.serverTuningFiles],
|
||||
packOperations: [...mod.content.packOperations],
|
||||
guiPatchCount: mod.content.guiPatchDirs.length,
|
||||
exePatchCount: mod.content.exePatchDirs.length,
|
||||
hasClientAddon: mod.content.hasClientAddon,
|
||||
addonFileCount: mod.content.addonRelativeFiles.length,
|
||||
clientFileCount: mod.content.clientFiles.length,
|
||||
hasConfigBlkPatch: mod.content.configBlkPatch !== undefined,
|
||||
};
|
||||
}
|
||||
|
||||
async function requireCopy(copyId: string): Promise<InstallRecord> {
|
||||
const copies = await listCopies();
|
||||
const copy = copies.copies.find((entry) => entry.id === copyId);
|
||||
if (!copy) throw new AppError('copy_not_found');
|
||||
return copy;
|
||||
}
|
||||
|
||||
async function readClientModsConfig(dataPath: string): Promise<ClientModsConfig> {
|
||||
const path = join(dataPath, CLIENT_MODS_CONFIG_FILE);
|
||||
try {
|
||||
const raw = await readJsonOr(path, null);
|
||||
if (!raw || typeof raw !== 'object') return emptyClientModsConfig();
|
||||
const obj = raw as Partial<ClientModsConfig>;
|
||||
return {
|
||||
format: 1,
|
||||
order: Array.isArray(obj.order) ? obj.order.filter((item): item is string => typeof item === 'string') : [],
|
||||
enabled: obj.enabled && typeof obj.enabled === 'object' ? { ...obj.enabled } : {},
|
||||
activePresetId: typeof obj.activePresetId === 'string' ? obj.activePresetId : null,
|
||||
presets: Array.isArray(obj.presets) ? obj.presets : [],
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn('[mods] unreadable client mods config, using defaults:', path, error);
|
||||
return emptyClientModsConfig();
|
||||
}
|
||||
}
|
||||
|
||||
async function writeClientModsConfig(dataPath: string, config: ClientModsConfig): Promise<void> {
|
||||
try {
|
||||
await writeJsonAtomic(join(dataPath, CLIENT_MODS_CONFIG_FILE), config);
|
||||
} catch (error) {
|
||||
console.error('[mods] writing client mods config failed:', error);
|
||||
throw new AppError('mods_write_failed');
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,8 @@ export interface BuildRequest {
|
||||
readonly decalCache?: string;
|
||||
readonly hookLogging: boolean;
|
||||
readonly acceptedUnavailable: readonly string[];
|
||||
readonly modsDir?: string;
|
||||
readonly enabledModIds?: readonly string[];
|
||||
}
|
||||
|
||||
export type BuildCommand = BuildRequest | { readonly kind: 'write' };
|
||||
|
||||
@@ -1,7 +1,20 @@
|
||||
import { readFileSync, realpathSync } from 'node:fs';
|
||||
import { relative } from 'node:path';
|
||||
import type { MessageEvent } from 'electron';
|
||||
import { assertWritableCopy, buildGameCopy, copyPlayerDecalCache, playerDecalCacheProblem, readStockGameFiles, writeGameCopy, type GameCopyFile } from '@wto/patcher';
|
||||
import { discoverMods, touchedClientPacks, type DiscoveredMod, type ModdableClientPack } from '@wto/mods';
|
||||
import {
|
||||
assertWritableCopy,
|
||||
buildGameCopy,
|
||||
computeModsBuildFingerprint,
|
||||
copyPlayerDecalCache,
|
||||
CORE_BUILD_PACKS,
|
||||
playerDecalCacheProblem,
|
||||
prepareOptionalStockPacks,
|
||||
readStockGameFiles,
|
||||
syncExternalModFiles,
|
||||
writeGameCopy,
|
||||
type GameCopyFile,
|
||||
} from '@wto/patcher';
|
||||
import { multiVehiclePackIds } from '@wto/server';
|
||||
import type { BuildCommand, BuildReply, BuildRequest } from './build-protocol.ts';
|
||||
|
||||
@@ -9,6 +22,9 @@ let prepared: {
|
||||
readonly request: BuildRequest;
|
||||
readonly files: readonly GameCopyFile[];
|
||||
readonly decalCache: string | undefined;
|
||||
readonly enabledMods: readonly DiscoveredMod[];
|
||||
readonly optionalPacksInBuild: readonly ModdableClientPack[];
|
||||
readonly fingerprint: string;
|
||||
} | null = null;
|
||||
|
||||
function checkBuildLocation({ stockPath, copyPath, steamLibraryConfirmed }: BuildRequest): void {
|
||||
@@ -31,17 +47,39 @@ function importedDecals(path: string | undefined): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function resolveOrderedMods(modsDir: string | undefined, enabledModIds: readonly string[] | undefined): DiscoveredMod[] {
|
||||
if (!modsDir || !enabledModIds || enabledModIds.length === 0) return [];
|
||||
const discovered = discoverMods(modsDir);
|
||||
const byId = new Map(discovered.mods.map((mod) => [mod.manifest.id, mod]));
|
||||
const ordered: DiscoveredMod[] = [];
|
||||
for (const id of enabledModIds) {
|
||||
const mod = byId.get(id);
|
||||
if (!mod) throw new Error(`enabled mod "${id}" was not found in ${modsDir}`);
|
||||
ordered.push(mod);
|
||||
}
|
||||
return ordered;
|
||||
}
|
||||
|
||||
function build(request: BuildRequest): void {
|
||||
checkBuildLocation(request);
|
||||
const decalCache = importedDecals(request.decalCache);
|
||||
const enabledMods = resolveOrderedMods(request.modsDir, request.enabledModIds);
|
||||
const touchedPacks = touchedClientPacks(enabledMods);
|
||||
const optionalPacksInBuild = touchedPacks.filter((pack) => !CORE_BUILD_PACKS.has(pack));
|
||||
const extraStockPacks = optionalPacksInBuild.length > 0
|
||||
? prepareOptionalStockPacks(request.copyPath, request.stockPath, optionalPacksInBuild)
|
||||
: undefined;
|
||||
|
||||
const result = buildGameCopy({
|
||||
stock: readStockGameFiles(request.stockPath),
|
||||
patches: request.patches,
|
||||
networkHookLibrary: readFileSync(request.networkHookLibrary),
|
||||
port: request.port,
|
||||
multiVehiclePackIds: multiVehiclePackIds(request.dataPath, console.info),
|
||||
multiVehiclePackIds: multiVehiclePackIds(request.dataPath, console.info, enabledMods),
|
||||
placeholderDecals: decalCache === undefined,
|
||||
hookLogging: request.hookLogging,
|
||||
...(enabledMods.length > 0 ? { mods: enabledMods } : {}),
|
||||
...(extraStockPacks ? { extraStockPacks } : {}),
|
||||
});
|
||||
const unavailable = [...result.exePatches.failures, ...result.guiPatches.failures, ...result.nativeModules.failures];
|
||||
const accepted = new Set(request.acceptedUnavailable);
|
||||
@@ -50,7 +88,19 @@ function build(request: BuildRequest): void {
|
||||
send({ kind: 'failed', error: 'launch_build_unavailable' });
|
||||
return;
|
||||
}
|
||||
prepared = { request, files: result.files, decalCache };
|
||||
if (result.mods.enabledModIds.length > 0) {
|
||||
console.info(
|
||||
`[build] applied ${result.mods.enabledModIds.length} mod(s): ${result.mods.enabledModIds.join(', ')} ` +
|
||||
`(pack overlays=${result.mods.packOverlays.length}, addons=${result.mods.addonMounts.length}, ` +
|
||||
`gui=${result.mods.guiPatches.applied.length} ok/${result.mods.guiPatches.failures.length} failed, ` +
|
||||
`exe=${result.mods.exePatches.applied.length} ok/${result.mods.exePatches.failures.length} failed)`,
|
||||
);
|
||||
for (const failure of [...result.mods.guiPatches.failures, ...result.mods.exePatches.failures]) {
|
||||
console.warn(`[build] mod "${failure.modId}" patch "${failure.patchId}" skipped: ${failure.reason}`);
|
||||
}
|
||||
}
|
||||
const fingerprint = computeModsBuildFingerprint(enabledMods, request.port, request.patches);
|
||||
prepared = { request, files: result.files, decalCache, enabledMods, optionalPacksInBuild, fingerprint };
|
||||
send({ kind: 'prepared', total: prepared.files.length });
|
||||
}
|
||||
|
||||
@@ -62,15 +112,22 @@ process.parentPort.on('message', (event: MessageEvent) => {
|
||||
return;
|
||||
}
|
||||
if (!prepared) throw new Error('No build is ready to write.');
|
||||
const { request, files, decalCache } = prepared;
|
||||
const { request, files, decalCache, enabledMods, optionalPacksInBuild, fingerprint } = prepared;
|
||||
prepared = null;
|
||||
checkBuildLocation(request);
|
||||
const { copyPath } = request;
|
||||
const { copyPath, stockPath } = request;
|
||||
if (decalCache) copyPlayerDecalCache(decalCache, copyPath);
|
||||
for (const [index, file] of files.entries()) {
|
||||
writeGameCopy(copyPath, [file]);
|
||||
send({ kind: 'progress', written: index + 1, total: files.length, file: file.path });
|
||||
}
|
||||
const deployResult = syncExternalModFiles(copyPath, stockPath, enabledMods, optionalPacksInBuild, fingerprint);
|
||||
for (const warning of deployResult.warnings) {
|
||||
console.warn(`[mods] skipped "${warning.targetRelPath}" from "${warning.modId}": ${warning.reason}`);
|
||||
}
|
||||
if (deployResult.restoredOptionalPacks.length > 0) {
|
||||
console.info(`[mods] restored stock pack(s): ${deployResult.restoredOptionalPacks.join(', ')}`);
|
||||
}
|
||||
send({ kind: 'written' });
|
||||
} catch (error) {
|
||||
console.error('[build] preparing the game copy failed:', error);
|
||||
|
||||
@@ -1,16 +1,42 @@
|
||||
import { discoverMods, type DiscoveredMod } from '@wto/mods';
|
||||
import { startServer } from '@wto/server';
|
||||
|
||||
export type ServerWorkerStatus = 'listening' | 'port-busy' | 'failed';
|
||||
|
||||
function loadOrderedMods(modsDir: string | undefined, enabledJson: string | undefined): DiscoveredMod[] {
|
||||
if (!modsDir || !enabledJson) return [];
|
||||
const ids = JSON.parse(enabledJson) as unknown;
|
||||
if (!Array.isArray(ids) || ids.length === 0) return [];
|
||||
const discovered = discoverMods(modsDir);
|
||||
const byId = new Map(discovered.mods.map((mod) => [mod.manifest.id, mod]));
|
||||
const mods: DiscoveredMod[] = [];
|
||||
for (const id of ids) {
|
||||
if (typeof id !== 'string') continue;
|
||||
const mod = byId.get(id);
|
||||
if (!mod) throw new Error(`Enabled mod "${id}" not found in ${modsDir}`);
|
||||
mods.push(mod);
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
|
||||
async function serve(): Promise<void> {
|
||||
const [gameFolder, dataFolder, portText, loggingFlag] = process.argv.slice(2);
|
||||
const [gameFolder, dataFolder, portText, loggingFlag, modsDir, enabledModIdsJson] = process.argv.slice(2);
|
||||
const port = Number(portText);
|
||||
if (!gameFolder || !dataFolder || !Number.isInteger(port) || port < 1 || port > 65535) {
|
||||
throw new Error('Invalid local server arguments.');
|
||||
}
|
||||
const loggingEnabled = loggingFlag !== '0';
|
||||
const server = await startServer({ gameFolder, dataFolder, port, loggingEnabled, report: console.info });
|
||||
const mods = loadOrderedMods(modsDir, enabledModIdsJson);
|
||||
const server = await startServer({
|
||||
gameFolder,
|
||||
dataFolder,
|
||||
port,
|
||||
loggingEnabled,
|
||||
...(mods.length > 0 ? { mods } : {}),
|
||||
report: console.info,
|
||||
});
|
||||
if (server.logFolder) console.info('Traffic log:', server.logFolder);
|
||||
if (server.loadedModIds.length > 0) console.info('Loaded server script mods:', server.loadedModIds.join(', '));
|
||||
process.parentPort.once('message', () => {
|
||||
void server.close().then(() => process.exit(0)).catch((error: unknown) => {
|
||||
console.error('Could not close the local server:', error);
|
||||
|
||||
@@ -22,6 +22,7 @@ import { useInstallWizard } from './pages/install/useInstallWizard.ts';
|
||||
import { WizardMain } from './pages/install/WizardMain.tsx';
|
||||
import { WizardSide } from './pages/install/WizardSide.tsx';
|
||||
import { wizardBar } from './pages/install/wizard-bar.ts';
|
||||
import { ModsPage } from './pages/mods/ModsPage.tsx';
|
||||
import { TuningPage } from './pages/tuning/TuningPage.tsx';
|
||||
import { SavesPage } from './pages/saves/SavesPage.tsx';
|
||||
import { DeveloperSettings } from './pages/settings/DeveloperSettings.tsx';
|
||||
@@ -32,7 +33,7 @@ import { Background } from './shell/Background.tsx';
|
||||
import { BottomBar } from './shell/BottomBar.tsx';
|
||||
import type { BarModel } from './shell/bar-model.ts';
|
||||
import { Footer } from './shell/Footer.tsx';
|
||||
import { COPY_SECTIONS, navigate, SAVE_SECTIONS, SETTINGS_SECTIONS, START_ROUTE, TUNING_SECTIONS, type Destination, type Route } from './shell/navigation.ts';
|
||||
import { COPY_SECTIONS, MODS_SECTIONS, navigate, SAVE_SECTIONS, SETTINGS_SECTIONS, START_ROUTE, TUNING_SECTIONS, type Destination, type Route } from './shell/navigation.ts';
|
||||
import { SubNav } from './shell/SubNav.tsx';
|
||||
import { TitleBar } from './shell/TitleBar.tsx';
|
||||
import { useBackgrounds } from './shell/useBackgrounds.ts';
|
||||
@@ -195,6 +196,14 @@ export function App({ info, initialSettings, initialCopies }: AppProps) {
|
||||
: <Sheet title={t(`tuning.sections.${route.tuning}`)}><p className="lead">{t('tuning.noCopy')}</p></Sheet>,
|
||||
bar: home,
|
||||
};
|
||||
case 'mods':
|
||||
return {
|
||||
side: <SubNav sections={MODS_SECTIONS} active={route.mods} label={(section) => t(`mods.sections.${section}`)} onSelect={(section) => go({ page: 'mods', section })} />,
|
||||
main: record
|
||||
? <ModsPage key={record.id} copy={record} section={route.mods} readOnly={['checking', 'building', 'starting-server', 'starting-game', 'running', 'server-running', 'stopping'].includes(launch.phase)} onError={report} />
|
||||
: <Sheet title={t(`mods.sections.${route.mods}`)}><p className="lead">{t('mods.noCopy')}</p></Sheet>,
|
||||
bar: home,
|
||||
};
|
||||
case 'copies': {
|
||||
const side = <SubNav sections={COPY_SECTIONS} active={route.copies} label={(section) => t(`copies.sections.${section}`)} onSelect={(section) => go({ page: 'copies', section })} />;
|
||||
if (route.copies === 'list') {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"home": "Home",
|
||||
"saves": "Saves",
|
||||
"tuning": "Tuning",
|
||||
"mods": "Mods",
|
||||
"copies": "Clients",
|
||||
"settings": "Settings",
|
||||
"about": "About"
|
||||
@@ -629,7 +630,95 @@
|
||||
"download": "Download update",
|
||||
"install": "Quit and install",
|
||||
"installing": "Opening the installer…",
|
||||
"errors": {
|
||||
"mods": {
|
||||
"sections": {
|
||||
"list": "Mod list",
|
||||
"presets": "Presets & repository"
|
||||
},
|
||||
"loading": "Loading mods…",
|
||||
"noCopy": "Install or select an offline client first to configure its mods.",
|
||||
"enabledSummary": "{{enabled}} / {{total}} enabled",
|
||||
"experimentalTitle": "Experimental mod API notice:",
|
||||
"experimentalBody": "WTOffline is in early development (API {{api}}). Server script hooks, internal data structures, and declarative exe patch contracts may change at any time without backwards compatibility; only enable mods from trusted sources.",
|
||||
"readOnlyNotice": "Mod toggles, load order, and presets are read-only while the game, local server, or maintenance is running.",
|
||||
"searchPlaceholder": "Filter by mod name, ID, or author…",
|
||||
"autoSort": "Auto-sort by dependencies",
|
||||
"autoSorted": "Reordered mods based on dependencies and load-order hints.",
|
||||
"refresh": "Refresh",
|
||||
"openFolder": "Open mods folder",
|
||||
"discoveryErrorsTitle": "{{count}} mod folder(s) could not be loaded:",
|
||||
"blockingIssuesTitle": "{{count}} blocking mod error(s) prevent launching:",
|
||||
"issuesTitle": "{{count}} mod notice(s) or overlap(s):",
|
||||
"severity": {
|
||||
"error": "Error",
|
||||
"warning": "Warning",
|
||||
"info": "Info"
|
||||
},
|
||||
"emptyTitle": "No mods found in the global mods folder yet.",
|
||||
"emptyHint": "Place mod folders containing mod.jsonc into {{path}}, then click Refresh. Standalone skins, sights, and user missions continue to work directly via the game's native UserSkins / UserSights / UserMissions folders.",
|
||||
"noSearchMatch": "No mods match the current search filter.",
|
||||
"loadOrderHint": "Load order: lower items load later and take higher priority (drag or use arrows)",
|
||||
"moveUp": "Move up",
|
||||
"moveDown": "Move down",
|
||||
"showDetails": "Details",
|
||||
"hideDetails": "Hide",
|
||||
"errorCount": "{{count}} error",
|
||||
"warnCount": "{{count}} warn",
|
||||
"badges": {
|
||||
"data": "Data / Assets",
|
||||
"gui": "GUI Patch",
|
||||
"script": "Server Script",
|
||||
"exe": "Exe Patch"
|
||||
},
|
||||
"details": {
|
||||
"folder": "Folder",
|
||||
"gameVersions": "Declared game versions",
|
||||
"requires": "Requires",
|
||||
"conflicts": "Conflicts",
|
||||
"tuning": "Server tuning overlays: {{count}}",
|
||||
"serverScript": "Executable server JS/TS script",
|
||||
"packOps": "Client pack operations: {{count}}",
|
||||
"addon": "3D model / texture addon: {{count}} file(s)",
|
||||
"guiPatches": "GUI script patches: {{count}}",
|
||||
"exePatches": "Declarative exe patches: {{count}}",
|
||||
"companionFiles": "Companion files: {{count}}",
|
||||
"configBlk": "Includes config.blk patch"
|
||||
},
|
||||
"presets": {
|
||||
"heading": "Mod presets (saved per client)",
|
||||
"description": "Save the current mod toggles and load order as named presets for quick switching or JSON export/import.",
|
||||
"quickSwitch": "Switch mod preset",
|
||||
"customOption": "Custom active selection",
|
||||
"namePlaceholder": "New preset name, e.g. Modern Vehicles",
|
||||
"saveCurrent": "Save preset",
|
||||
"import": "Import preset…",
|
||||
"empty": "No presets saved for this client yet.",
|
||||
"activeTag": "Active",
|
||||
"summary": "{{count}} enabled / {{total}} tracked",
|
||||
"apply": "Apply",
|
||||
"overwrite": "Update",
|
||||
"export": "Export",
|
||||
"delete": "Delete",
|
||||
"saved": "Saved preset \"{{name}}\".",
|
||||
"applied": "Applied preset \"{{name}}\".",
|
||||
"updated": "Updated preset \"{{name}}\" with current setup.",
|
||||
"exported": "Exported preset to: {{path}}",
|
||||
"imported": "Imported mod preset."
|
||||
},
|
||||
"repo": {
|
||||
"heading": "Global mods repository",
|
||||
"description": "All clients share one mod folder (large 3D model and texture addons mount across drives via NTFS Junctions with zero copying), while each client keeps its own toggles, load order, and presets.",
|
||||
"pathLabel": "Repository folder",
|
||||
"defaultNote": "Using launcher default mods folder",
|
||||
"customNote": "Using custom mods folder (can live on a larger drive or the same drive as your client)",
|
||||
"changeFolder": "Change folder…",
|
||||
"resetDefault": "Reset to default",
|
||||
"pickTitle": "Select global mods repository folder",
|
||||
"updated": "Updated global mods repository folder.",
|
||||
"resetDone": "Reset to default mods repository folder."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"network": "The update source could not be reached.",
|
||||
"page_limit": "Could not confirm whether a newer version is available.",
|
||||
"contents": "The launcher release information is invalid.",
|
||||
@@ -680,6 +769,94 @@
|
||||
"L-Debriefing": "Battle results",
|
||||
"L-Battle awards": "Battle awards"
|
||||
},
|
||||
"mods": {
|
||||
"sections": {
|
||||
"list": "Mod list",
|
||||
"presets": "Presets & repository"
|
||||
},
|
||||
"loading": "Loading mods…",
|
||||
"noCopy": "Install or select an offline client first to configure its mods.",
|
||||
"enabledSummary": "{{enabled}} / {{total}} enabled",
|
||||
"experimentalTitle": "Experimental mod API notice:",
|
||||
"experimentalBody": "WTOffline is in early development (API {{api}}). Server script hooks, internal data structures, and declarative exe patch contracts may change at any time without backwards compatibility; only enable mods from trusted sources.",
|
||||
"readOnlyNotice": "Mod toggles, load order, and presets are read-only while the game, local server, or maintenance is running.",
|
||||
"searchPlaceholder": "Filter by mod name, ID, or author…",
|
||||
"autoSort": "Auto-sort by dependencies",
|
||||
"autoSorted": "Reordered mods based on dependencies and load-order hints.",
|
||||
"refresh": "Refresh",
|
||||
"openFolder": "Open mods folder",
|
||||
"discoveryErrorsTitle": "{{count}} mod folder(s) could not be loaded:",
|
||||
"blockingIssuesTitle": "{{count}} blocking mod error(s) prevent launching:",
|
||||
"issuesTitle": "{{count}} mod notice(s) or overlap(s):",
|
||||
"severity": {
|
||||
"error": "Error",
|
||||
"warning": "Warning",
|
||||
"info": "Info"
|
||||
},
|
||||
"emptyTitle": "No mods found in the global mods folder yet.",
|
||||
"emptyHint": "Place mod folders containing mod.jsonc into {{path}}, then click Refresh. Standalone skins, sights, and user missions continue to work directly via the game's native UserSkins / UserSights / UserMissions folders.",
|
||||
"noSearchMatch": "No mods match the current search filter.",
|
||||
"loadOrderHint": "Load order: lower items load later and take higher priority (drag or use arrows)",
|
||||
"moveUp": "Move up",
|
||||
"moveDown": "Move down",
|
||||
"showDetails": "Details",
|
||||
"hideDetails": "Hide",
|
||||
"errorCount": "{{count}} error",
|
||||
"warnCount": "{{count}} warn",
|
||||
"badges": {
|
||||
"data": "Data / Assets",
|
||||
"gui": "GUI Patch",
|
||||
"script": "Server Script",
|
||||
"exe": "Exe Patch"
|
||||
},
|
||||
"details": {
|
||||
"folder": "Folder",
|
||||
"gameVersions": "Declared game versions",
|
||||
"requires": "Requires",
|
||||
"conflicts": "Conflicts",
|
||||
"tuning": "Server tuning overlays: {{count}}",
|
||||
"serverScript": "Executable server JS/TS script",
|
||||
"packOps": "Client pack operations: {{count}}",
|
||||
"addon": "3D model / texture addon: {{count}} file(s)",
|
||||
"guiPatches": "GUI script patches: {{count}}",
|
||||
"exePatches": "Declarative exe patches: {{count}}",
|
||||
"companionFiles": "Companion files: {{count}}",
|
||||
"configBlk": "Includes config.blk patch"
|
||||
},
|
||||
"presets": {
|
||||
"heading": "Mod presets (saved per client)",
|
||||
"description": "Save the current mod toggles and load order as named presets for quick switching or JSON export/import.",
|
||||
"quickSwitch": "Switch mod preset",
|
||||
"customOption": "Custom active selection",
|
||||
"namePlaceholder": "New preset name, e.g. Modern Vehicles",
|
||||
"saveCurrent": "Save preset",
|
||||
"import": "Import preset…",
|
||||
"empty": "No presets saved for this client yet.",
|
||||
"activeTag": "Active",
|
||||
"summary": "{{count}} enabled / {{total}} tracked",
|
||||
"apply": "Apply",
|
||||
"overwrite": "Update",
|
||||
"export": "Export",
|
||||
"delete": "Delete",
|
||||
"saved": "Saved preset \"{{name}}\".",
|
||||
"applied": "Applied preset \"{{name}}\".",
|
||||
"updated": "Updated preset \"{{name}}\" with current setup.",
|
||||
"exported": "Exported preset to: {{path}}",
|
||||
"imported": "Imported mod preset."
|
||||
},
|
||||
"repo": {
|
||||
"heading": "Global mods repository",
|
||||
"description": "All clients share one mod folder (large 3D model and texture addons mount across drives via NTFS Junctions with zero copying), while each client keeps its own toggles, load order, and presets.",
|
||||
"pathLabel": "Repository folder",
|
||||
"defaultNote": "Using launcher default mods folder",
|
||||
"customNote": "Using custom mods folder (can live on a larger drive or the same drive as your client)",
|
||||
"changeFolder": "Change folder…",
|
||||
"resetDefault": "Reset to default",
|
||||
"pickTitle": "Select global mods repository folder",
|
||||
"updated": "Updated global mods repository folder.",
|
||||
"resetDone": "Reset to default mods repository folder."
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"app_update_unavailable": "There is no launcher update available to install.",
|
||||
"app_update_busy": "A launcher update operation is already in progress.",
|
||||
@@ -703,6 +880,11 @@
|
||||
"save_avatar_invalid": "Select an avatar available in this client.",
|
||||
"save_level_invalid": "Enter a level supported by this client.",
|
||||
"tuning_invalid": "The tuning values could not be read or saved. Check the session limits and the launcher log.",
|
||||
"mods_read_only": "Mods cannot be changed while the game, local server, or maintenance is running.",
|
||||
"mods_write_failed": "The mod configuration could not be saved. See the launcher log.",
|
||||
"mods_preset_invalid": "The selected file is not a valid WTOffline mod preset.",
|
||||
"mods_blocking_issues": "Enabled mods have missing dependencies or conflicts. Resolve them on the Mods page before launching.",
|
||||
"mods_folder_invalid": "The selected global mods folder is invalid or not writable.",
|
||||
"copy_not_found": "The selected client is no longer available.",
|
||||
"copies_write_failed": "The client registry could not be saved.",
|
||||
"copy_location_in_use": "The client or data location overlaps an existing client.",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"home": "首页",
|
||||
"saves": "存档",
|
||||
"tuning": "数值",
|
||||
"mods": "模组",
|
||||
"copies": "客户端",
|
||||
"settings": "设置",
|
||||
"about": "关于"
|
||||
@@ -629,7 +630,95 @@
|
||||
"download": "下载更新",
|
||||
"install": "退出并安装",
|
||||
"installing": "正在打开安装包…",
|
||||
"errors": {
|
||||
"mods": {
|
||||
"sections": {
|
||||
"list": "模组列表",
|
||||
"presets": "预设与仓库"
|
||||
},
|
||||
"loading": "正在读取模组信息…",
|
||||
"noCopy": "请先安装或选择一个离线客户端,再为它配置模组。",
|
||||
"enabledSummary": "已启用 {{enabled}} / {{total}}",
|
||||
"experimentalTitle": "实验期模组接口提示:",
|
||||
"experimentalBody": "离线版当前处于极初期开发阶段(API {{api}})。服务端脚本钩子、内部数据结构及声明式 exe 补丁契约随时可能随本体更新变动且不保证向下兼容;请仅启用来源可信的模组。",
|
||||
"readOnlyNotice": "游戏、本地服务器或维护任务运行期间,模组开关、排序与预设为只读。",
|
||||
"searchPlaceholder": "搜索模组名称、ID 或作者…",
|
||||
"autoSort": "按依赖自动排序",
|
||||
"autoSorted": "已按前置与排序建议重新排列模组顺序。",
|
||||
"refresh": "刷新",
|
||||
"openFolder": "打开模组目录",
|
||||
"discoveryErrorsTitle": "有 {{count}} 个模组目录读取失败:",
|
||||
"blockingIssuesTitle": "存在 {{count}} 项阻塞性模组错误(处理前无法启动):",
|
||||
"issuesTitle": "检测到 {{count}} 项模组提示或冲突:",
|
||||
"severity": {
|
||||
"error": "错误",
|
||||
"warning": "警告",
|
||||
"info": "提示"
|
||||
},
|
||||
"emptyTitle": "当前模组目录里还没有模组。",
|
||||
"emptyHint": "将包含 mod.jsonc 的模组文件夹放入 {{path}},点击「刷新」即可识别。独立涂装、瞄具与单人任务继续沿用游戏原生的 UserSkins / UserSights / UserMissions 目录即可。",
|
||||
"noSearchMatch": "没有匹配当前搜索条件的模组。",
|
||||
"loadOrderHint": "加载顺序:越靠后优先级越高(可拖动或使用上下按钮调整)",
|
||||
"moveUp": "上移",
|
||||
"moveDown": "下移",
|
||||
"showDetails": "详情",
|
||||
"hideDetails": "收起",
|
||||
"errorCount": "{{count}} 错误",
|
||||
"warnCount": "{{count}} 警告",
|
||||
"badges": {
|
||||
"data": "数据/资源",
|
||||
"gui": "界面补丁",
|
||||
"script": "服务端脚本",
|
||||
"exe": "二进制补丁"
|
||||
},
|
||||
"details": {
|
||||
"folder": "目录",
|
||||
"gameVersions": "声明适配版本",
|
||||
"requires": "前置依赖",
|
||||
"conflicts": "已知互斥",
|
||||
"tuning": "服务端数值叠加:{{count}} 份",
|
||||
"serverScript": "含可执行服务端 JS/TS 脚本",
|
||||
"packOps": "客户端数据包操作:{{count}} 项",
|
||||
"addon": "独立 3D 模型/贴图扩展包:{{count}} 个文件",
|
||||
"guiPatches": "界面脚本补丁:{{count}} 项",
|
||||
"exePatches": "声明式 exe 补丁:{{count}} 项",
|
||||
"companionFiles": "附带外置文件:{{count}} 个",
|
||||
"configBlk": "含 config.blk 增量补丁"
|
||||
},
|
||||
"presets": {
|
||||
"heading": "模组序列预设(当前客户端独立保存)",
|
||||
"description": "将当前的启用开关与加载顺序保存为预设,方便在不同玩法配置间一键切换,或导出 JSON 分享给其他玩家。",
|
||||
"quickSwitch": "快速切换模组预设",
|
||||
"customOption": "当前自定义配置",
|
||||
"namePlaceholder": "输入新预设名称,例如:现代载具包",
|
||||
"saveCurrent": "保存为预设",
|
||||
"import": "导入预设…",
|
||||
"empty": "当前客户端尚未保存任何模组预设。",
|
||||
"activeTag": "当前使用",
|
||||
"summary": "启用 {{count}} / 共 {{total}} 个模组",
|
||||
"apply": "应用",
|
||||
"overwrite": "覆盖更新",
|
||||
"export": "导出",
|
||||
"delete": "删除",
|
||||
"saved": "已保存预设「{{name}}」。",
|
||||
"applied": "已切换至预设「{{name}}」。",
|
||||
"updated": "已用当前配置覆盖预设「{{name}}」。",
|
||||
"exported": "预设已导出到:{{path}}",
|
||||
"imported": "已导入模组预设。"
|
||||
},
|
||||
"repo": {
|
||||
"heading": "全局模组仓库位置",
|
||||
"description": "所有客户端共享同一份模组文件仓库(大体积 3D 模型与贴图包通过跨盘目录联接点零拷贝挂载,不重复占用磁盘);每个客户端独立保存自己的开关、排序和预设。",
|
||||
"pathLabel": "当前仓库目录",
|
||||
"defaultNote": "使用启动器默认模组目录",
|
||||
"customNote": "使用自定义模组目录(可放在大容量硬盘或游戏同盘)",
|
||||
"changeFolder": "更改目录…",
|
||||
"resetDefault": "恢复默认目录",
|
||||
"pickTitle": "选择全局模组仓库目录",
|
||||
"updated": "已更新全局模组仓库目录。",
|
||||
"resetDone": "已恢复为默认模组仓库目录。"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"network": "暂时无法访问更新源。",
|
||||
"page_limit": "无法确认是否有新版本。",
|
||||
"contents": "本体更新的发布信息无效。",
|
||||
@@ -680,6 +769,94 @@
|
||||
"L-Debriefing": "战后结算",
|
||||
"L-Battle awards": "战斗嘉奖"
|
||||
},
|
||||
"mods": {
|
||||
"sections": {
|
||||
"list": "模组列表",
|
||||
"presets": "预设与仓库"
|
||||
},
|
||||
"loading": "正在读取模组信息…",
|
||||
"noCopy": "请先安装或选择一个离线客户端,再为它配置模组。",
|
||||
"enabledSummary": "已启用 {{enabled}} / {{total}}",
|
||||
"experimentalTitle": "实验期模组接口提示:",
|
||||
"experimentalBody": "离线版当前处于极初期开发阶段(API {{api}})。服务端脚本钩子、内部数据结构及声明式 exe 补丁契约随时可能随本体更新变动且不保证向下兼容;请仅启用来源可信的模组。",
|
||||
"readOnlyNotice": "游戏、本地服务器或维护任务运行期间,模组开关、排序与预设为只读。",
|
||||
"searchPlaceholder": "搜索模组名称、ID 或作者…",
|
||||
"autoSort": "按依赖自动排序",
|
||||
"autoSorted": "已按前置与排序建议重新排列模组顺序。",
|
||||
"refresh": "刷新",
|
||||
"openFolder": "打开模组目录",
|
||||
"discoveryErrorsTitle": "有 {{count}} 个模组目录读取失败:",
|
||||
"blockingIssuesTitle": "存在 {{count}} 项阻塞性模组错误(处理前无法启动):",
|
||||
"issuesTitle": "检测到 {{count}} 项模组提示或冲突:",
|
||||
"severity": {
|
||||
"error": "错误",
|
||||
"warning": "警告",
|
||||
"info": "提示"
|
||||
},
|
||||
"emptyTitle": "当前模组目录里还没有模组。",
|
||||
"emptyHint": "将包含 mod.jsonc 的模组文件夹放入 {{path}},点击「刷新」即可识别。独立涂装、瞄具与单人任务继续沿用游戏原生的 UserSkins / UserSights / UserMissions 目录即可。",
|
||||
"noSearchMatch": "没有匹配当前搜索条件的模组。",
|
||||
"loadOrderHint": "加载顺序:越靠后优先级越高(可拖动或使用上下按钮调整)",
|
||||
"moveUp": "上移",
|
||||
"moveDown": "下移",
|
||||
"showDetails": "详情",
|
||||
"hideDetails": "收起",
|
||||
"errorCount": "{{count}} 错误",
|
||||
"warnCount": "{{count}} 警告",
|
||||
"badges": {
|
||||
"data": "数据/资源",
|
||||
"gui": "界面补丁",
|
||||
"script": "服务端脚本",
|
||||
"exe": "二进制补丁"
|
||||
},
|
||||
"details": {
|
||||
"folder": "目录",
|
||||
"gameVersions": "声明适配版本",
|
||||
"requires": "前置依赖",
|
||||
"conflicts": "已知互斥",
|
||||
"tuning": "服务端数值叠加:{{count}} 份",
|
||||
"serverScript": "含可执行服务端 JS/TS 脚本",
|
||||
"packOps": "客户端数据包操作:{{count}} 项",
|
||||
"addon": "独立 3D 模型/贴图扩展包:{{count}} 个文件",
|
||||
"guiPatches": "界面脚本补丁:{{count}} 项",
|
||||
"exePatches": "声明式 exe 补丁:{{count}} 项",
|
||||
"companionFiles": "附带外置文件:{{count}} 个",
|
||||
"configBlk": "含 config.blk 增量补丁"
|
||||
},
|
||||
"presets": {
|
||||
"heading": "模组序列预设(当前客户端独立保存)",
|
||||
"description": "将当前的启用开关与加载顺序保存为预设,方便在不同玩法配置间一键切换,或导出 JSON 分享给其他玩家。",
|
||||
"quickSwitch": "快速切换模组预设",
|
||||
"customOption": "当前自定义配置",
|
||||
"namePlaceholder": "输入新预设名称,例如:现代载具包",
|
||||
"saveCurrent": "保存为预设",
|
||||
"import": "导入预设…",
|
||||
"empty": "当前客户端尚未保存任何模组预设。",
|
||||
"activeTag": "当前使用",
|
||||
"summary": "启用 {{count}} / 共 {{total}} 个模组",
|
||||
"apply": "应用",
|
||||
"overwrite": "覆盖更新",
|
||||
"export": "导出",
|
||||
"delete": "删除",
|
||||
"saved": "已保存预设「{{name}}」。",
|
||||
"applied": "已切换至预设「{{name}}」。",
|
||||
"updated": "已用当前配置覆盖预设「{{name}}」。",
|
||||
"exported": "预设已导出到:{{path}}",
|
||||
"imported": "已导入模组预设。"
|
||||
},
|
||||
"repo": {
|
||||
"heading": "全局模组仓库位置",
|
||||
"description": "所有客户端共享同一份模组文件仓库(大体积 3D 模型与贴图包通过跨盘目录联接点零拷贝挂载,不重复占用磁盘);每个客户端独立保存自己的开关、排序和预设。",
|
||||
"pathLabel": "当前仓库目录",
|
||||
"defaultNote": "使用启动器默认模组目录",
|
||||
"customNote": "使用自定义模组目录(可放在大容量硬盘或游戏同盘)",
|
||||
"changeFolder": "更改目录…",
|
||||
"resetDefault": "恢复默认目录",
|
||||
"pickTitle": "选择全局模组仓库目录",
|
||||
"updated": "已更新全局模组仓库目录。",
|
||||
"resetDone": "已恢复为默认模组仓库目录。"
|
||||
}
|
||||
},
|
||||
"errors": {
|
||||
"app_update_unavailable": "当前没有可安装的本体更新。",
|
||||
"app_update_busy": "本体更新操作正在进行。",
|
||||
@@ -703,6 +880,11 @@
|
||||
"save_avatar_invalid": "请选择此客户端中可用的头像。",
|
||||
"save_level_invalid": "请输入此客户端支持的账号等级。",
|
||||
"tuning_invalid": "无法读取或保存数值。请核对对局人数限制和启动器日志。",
|
||||
"mods_read_only": "游戏、本地服务器或维护任务运行期间无法修改模组配置。",
|
||||
"mods_write_failed": "无法保存模组配置,请查看启动器日志。",
|
||||
"mods_preset_invalid": "所选文件不是有效的 WTOffline 模组预设。",
|
||||
"mods_blocking_issues": "当前启用的模组存在缺失前置或互斥冲突,请先在「模组」页面处理后再启动。",
|
||||
"mods_folder_invalid": "所选全局模组目录无效或无法写入。",
|
||||
"copy_not_found": "所选客户端已不可用。",
|
||||
"copies_write_failed": "无法保存客户端记录。",
|
||||
"copy_location_in_use": "客户端位置或数据目录与已有客户端重叠。",
|
||||
|
||||
@@ -0,0 +1,565 @@
|
||||
import { useCallback, useEffect, useMemo, useState, type DragEvent, type FormEvent } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import type { InstallRecord } from '@shared/schemas/install.ts';
|
||||
import type { ModIssueView, ModListItem, ModsStateView } from '@shared/schemas/mods.ts';
|
||||
import { Row } from '../../components/Row.tsx';
|
||||
import { Sheet } from '../../components/Sheet.tsx';
|
||||
import { ipcInvoke } from '../../ipc.ts';
|
||||
import type { ModsSection } from '../../shell/navigation.ts';
|
||||
|
||||
interface Props {
|
||||
readonly copy: InstallRecord;
|
||||
readonly section: ModsSection;
|
||||
readonly readOnly: boolean;
|
||||
readonly onError: (error: unknown) => void;
|
||||
}
|
||||
|
||||
function localized(value: string | Readonly<Record<string, string>> | undefined, language: string): string {
|
||||
if (!value) return '';
|
||||
if (typeof value === 'string') return value;
|
||||
const exact = value[language];
|
||||
if (exact) return exact;
|
||||
const prefix = language.split('-')[0];
|
||||
if (prefix) {
|
||||
const match = Object.entries(value).find(([key]) => key === prefix || key.startsWith(`${prefix}-`));
|
||||
if (match?.[1]) return match[1];
|
||||
}
|
||||
return value.en ?? value['en-US'] ?? Object.values(value)[0] ?? '';
|
||||
}
|
||||
|
||||
export function ModsPage({ copy, section, readOnly, onError }: Props) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const [state, setState] = useState<ModsStateView | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [query, setQuery] = useState('');
|
||||
const [expandedId, setExpandedId] = useState<string | null>(null);
|
||||
const [draggedId, setDraggedId] = useState<string | null>(null);
|
||||
const [presetName, setPresetName] = useState('');
|
||||
const [notice, setNotice] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(() => {
|
||||
setBusy(true);
|
||||
ipcInvoke('mods:getState', { copyId: copy.id })
|
||||
.then(setState)
|
||||
.catch(onError)
|
||||
.finally(() => setBusy(false));
|
||||
}, [copy.id, onError]);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
ipcInvoke('mods:getState', { copyId: copy.id })
|
||||
.then((result) => { if (mounted) setState(result); })
|
||||
.catch(onError);
|
||||
return () => { mounted = false; };
|
||||
}, [copy.id, onError]);
|
||||
|
||||
const runAction = (action: Promise<ModsStateView>, successNotice?: string): void => {
|
||||
setBusy(true);
|
||||
setNotice(null);
|
||||
action
|
||||
.then((next) => {
|
||||
setState(next);
|
||||
if (successNotice) setNotice(successNotice);
|
||||
})
|
||||
.catch(onError)
|
||||
.finally(() => setBusy(false));
|
||||
};
|
||||
|
||||
const issuesByMod = useMemo(() => {
|
||||
const map = new Map<string, ModIssueView[]>();
|
||||
for (const issue of state?.issues ?? []) {
|
||||
const list = map.get(issue.modId) ?? [];
|
||||
list.push(issue);
|
||||
map.set(issue.modId, list);
|
||||
}
|
||||
return map;
|
||||
}, [state]);
|
||||
|
||||
const title = t(`mods.sections.${section}`);
|
||||
if (!state) {
|
||||
return <Sheet title={title} aside={copy.name}><p className="lead">{t('mods.loading')}</p></Sheet>;
|
||||
}
|
||||
|
||||
const disabled = readOnly || busy;
|
||||
const enabledCount = state.mods.filter((mod) => state.enabled[mod.id] === true).length;
|
||||
|
||||
const toggleMod = (modId: string, nextEnabled: boolean): void => {
|
||||
runAction(ipcInvoke('mods:setEnabled', { copyId: copy.id, modId, enabled: nextEnabled }));
|
||||
};
|
||||
|
||||
const reorder = (nextOrder: string[]): void => {
|
||||
runAction(ipcInvoke('mods:setOrder', { copyId: copy.id, order: nextOrder }));
|
||||
};
|
||||
|
||||
const moveMod = (modId: string, delta: -1 | 1): void => {
|
||||
const idx = state.order.indexOf(modId);
|
||||
const target = idx + delta;
|
||||
if (idx < 0 || target < 0 || target >= state.order.length) return;
|
||||
const next = [...state.order];
|
||||
const [item] = next.splice(idx, 1);
|
||||
next.splice(target, 0, item!);
|
||||
reorder(next);
|
||||
};
|
||||
|
||||
const handleDrop = (targetId: string, event: DragEvent<HTMLDivElement>): void => {
|
||||
event.preventDefault();
|
||||
const sourceId = draggedId;
|
||||
setDraggedId(null);
|
||||
if (!sourceId || sourceId === targetId || disabled) return;
|
||||
const from = state.order.indexOf(sourceId);
|
||||
const to = state.order.indexOf(targetId);
|
||||
if (from < 0 || to < 0) return;
|
||||
const next = [...state.order];
|
||||
const [moved] = next.splice(from, 1);
|
||||
next.splice(to, 0, moved!);
|
||||
reorder(next);
|
||||
};
|
||||
|
||||
const savePreset = (event: FormEvent<HTMLFormElement>): void => {
|
||||
event.preventDefault();
|
||||
const trimmed = presetName.trim();
|
||||
if (!trimmed) return;
|
||||
runAction(
|
||||
ipcInvoke('mods:savePreset', { copyId: copy.id, name: trimmed }),
|
||||
t('mods.presets.saved', { name: trimmed }),
|
||||
);
|
||||
setPresetName('');
|
||||
};
|
||||
|
||||
const pickCustomFolder = (): void => {
|
||||
ipcInvoke('dialog:pickFolder', { title: t('mods.repo.pickTitle') })
|
||||
.then(({ path }) => {
|
||||
if (!path) return;
|
||||
runAction(ipcInvoke('mods:setFolder', { copyId: copy.id, path }), t('mods.repo.updated'));
|
||||
})
|
||||
.catch(onError);
|
||||
};
|
||||
|
||||
const resetFolder = (): void => {
|
||||
runAction(ipcInvoke('mods:setFolder', { copyId: copy.id, path: null }), t('mods.repo.resetDone'));
|
||||
};
|
||||
|
||||
const exportPreset = (presetId: string): void => {
|
||||
setBusy(true);
|
||||
setNotice(null);
|
||||
ipcInvoke('mods:exportPreset', { copyId: copy.id, presetId })
|
||||
.then(({ path }) => {
|
||||
if (path) setNotice(t('mods.presets.exported', { path }));
|
||||
})
|
||||
.catch(onError)
|
||||
.finally(() => setBusy(false));
|
||||
};
|
||||
|
||||
const importPreset = (): void => {
|
||||
setBusy(true);
|
||||
setNotice(null);
|
||||
ipcInvoke('mods:importPreset', { copyId: copy.id })
|
||||
.then(({ imported, state: next }) => {
|
||||
setState(next);
|
||||
if (imported) setNotice(t('mods.presets.imported'));
|
||||
})
|
||||
.catch(onError)
|
||||
.finally(() => setBusy(false));
|
||||
};
|
||||
|
||||
const normalizedQuery = query.trim().toLowerCase();
|
||||
const visibleMods = normalizedQuery
|
||||
? state.mods.filter((mod) => {
|
||||
const displayName = localized(mod.name, i18n.language).toLowerCase();
|
||||
return displayName.includes(normalizedQuery)
|
||||
|| mod.id.toLowerCase().includes(normalizedQuery)
|
||||
|| mod.author.toLowerCase().includes(normalizedQuery);
|
||||
})
|
||||
: state.mods;
|
||||
|
||||
const canDrag = !disabled && normalizedQuery.length === 0;
|
||||
|
||||
return (
|
||||
<Sheet title={title} aside={`${copy.name} · ${t('mods.enabledSummary', { enabled: enabledCount, total: state.mods.length })}`}>
|
||||
<div className="mods-banner mods-banner-experimental" role="note">
|
||||
<strong>{t('mods.experimentalTitle')}</strong>
|
||||
<span>{t('mods.experimentalBody', { api: state.apiVersion })}</span>
|
||||
</div>
|
||||
|
||||
{readOnly && (
|
||||
<div className="mods-banner mods-banner-warn" role="status">
|
||||
{t('mods.readOnlyNotice')}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{notice && (
|
||||
<div className="mods-banner mods-banner-ok" role="status">
|
||||
{notice}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{section === 'list' ? (
|
||||
<>
|
||||
<div className="mods-toolbar">
|
||||
<input
|
||||
type="search"
|
||||
className="input mods-search"
|
||||
placeholder={t('mods.searchPlaceholder')}
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
{state.presets.length > 0 && (
|
||||
<select
|
||||
className="select mods-preset-select"
|
||||
aria-label={t('mods.presets.quickSwitch')}
|
||||
disabled={disabled}
|
||||
value={state.activePresetId ?? ''}
|
||||
onChange={(event) => {
|
||||
const id = event.target.value;
|
||||
if (id) runAction(ipcInvoke('mods:applyPreset', { copyId: copy.id, presetId: id }));
|
||||
}}
|
||||
>
|
||||
<option value="">{t('mods.presets.customOption')}</option>
|
||||
{state.presets.map((preset) => (
|
||||
<option key={preset.id} value={preset.id}>{preset.name}</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="button"
|
||||
disabled={disabled || state.mods.length < 2}
|
||||
onClick={() => runAction(ipcInvoke('mods:autoSort', { copyId: copy.id }), t('mods.autoSorted'))}
|
||||
>
|
||||
{t('mods.autoSort')}
|
||||
</button>
|
||||
<button type="button" className="button" disabled={busy} onClick={load}>
|
||||
{t('mods.refresh')}
|
||||
</button>
|
||||
<button type="button" className="button" onClick={() => ipcInvoke('mods:openFolder').catch(onError)}>
|
||||
{t('mods.openFolder')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{state.discoveryErrors.length > 0 && (
|
||||
<div className="mods-issues-box mods-issues-error">
|
||||
<div className="mods-issues-title">{t('mods.discoveryErrorsTitle', { count: state.discoveryErrors.length })}</div>
|
||||
<ul>
|
||||
{state.discoveryErrors.map((err) => (
|
||||
<li key={err.folderName}>
|
||||
<code>{err.folderName}</code>: {err.reason}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{state.issues.length > 0 && (
|
||||
<div className={state.hasBlockingErrors ? 'mods-issues-box mods-issues-error' : 'mods-issues-box mods-issues-warn'}>
|
||||
<div className="mods-issues-title">
|
||||
{state.hasBlockingErrors
|
||||
? t('mods.blockingIssuesTitle', { count: state.issues.filter((i) => i.severity === 'error').length })
|
||||
: t('mods.issuesTitle', { count: state.issues.length })}
|
||||
</div>
|
||||
<ul>
|
||||
{state.issues.map((issue, idx) => (
|
||||
<li key={`${issue.modId}-${issue.kind}-${idx}`} className={`mods-issue-${issue.severity}`}>
|
||||
<span className="mods-issue-tag">{t(`mods.severity.${issue.severity}`)}</span>
|
||||
<strong>{issue.modId}</strong>: {issue.detail}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{visibleMods.length === 0 ? (
|
||||
<div className="mods-empty">
|
||||
<p className="lead">{state.mods.length === 0 ? t('mods.emptyTitle') : t('mods.noSearchMatch')}</p>
|
||||
{state.mods.length === 0 && (
|
||||
<>
|
||||
<p className="mods-hint">{t('mods.emptyHint', { path: state.modsDir })}</p>
|
||||
<button type="button" className="button button-primary" onClick={() => ipcInvoke('mods:openFolder').catch(onError)}>
|
||||
{t('mods.openFolder')}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="mods-list">
|
||||
{visibleMods.map((mod) => {
|
||||
const index = state.order.indexOf(mod.id);
|
||||
const isEnabled = state.enabled[mod.id] === true;
|
||||
const isExpanded = expandedId === mod.id;
|
||||
const modIssues = issuesByMod.get(mod.id) ?? [];
|
||||
return (
|
||||
<ModCard
|
||||
key={mod.id}
|
||||
mod={mod}
|
||||
index={index}
|
||||
total={state.order.length}
|
||||
enabled={isEnabled}
|
||||
expanded={isExpanded}
|
||||
disabled={disabled}
|
||||
canDrag={canDrag}
|
||||
language={i18n.language}
|
||||
issues={modIssues}
|
||||
onToggle={(next) => toggleMod(mod.id, next)}
|
||||
onMove={(delta) => moveMod(mod.id, delta)}
|
||||
onToggleExpand={() => setExpandedId(isExpanded ? null : mod.id)}
|
||||
onDragStart={() => setDraggedId(mod.id)}
|
||||
onDrop={(event) => handleDrop(mod.id, event)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<section className="mods-section">
|
||||
<h3 className="mods-subheading">{t('mods.presets.heading')}</h3>
|
||||
<p className="mods-hint">{t('mods.presets.description')}</p>
|
||||
<form className="mods-preset-form" onSubmit={savePreset}>
|
||||
<input
|
||||
type="text"
|
||||
className="input"
|
||||
maxLength={80}
|
||||
disabled={disabled}
|
||||
placeholder={t('mods.presets.namePlaceholder')}
|
||||
value={presetName}
|
||||
onChange={(event) => setPresetName(event.target.value)}
|
||||
/>
|
||||
<button type="submit" className="button button-primary" disabled={disabled || !presetName.trim()}>
|
||||
{t('mods.presets.saveCurrent')}
|
||||
</button>
|
||||
<button type="button" className="button" disabled={disabled} onClick={importPreset}>
|
||||
{t('mods.presets.import')}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{state.presets.length === 0 ? (
|
||||
<p className="mods-hint">{t('mods.presets.empty')}</p>
|
||||
) : (
|
||||
<div className="mods-preset-list">
|
||||
{state.presets.map((preset) => {
|
||||
const active = state.activePresetId === preset.id;
|
||||
const count = Object.values(preset.enabled).filter(Boolean).length;
|
||||
return (
|
||||
<div key={preset.id} className={active ? 'mods-preset-item mods-preset-active' : 'mods-preset-item'}>
|
||||
<div className="mods-preset-meta">
|
||||
<div className="mods-preset-name">
|
||||
{preset.name}
|
||||
{active && <span className="mods-badge mods-badge-data">{t('mods.presets.activeTag')}</span>}
|
||||
</div>
|
||||
<div className="mods-preset-sub">
|
||||
{t('mods.presets.summary', { count, total: preset.order.length })}
|
||||
</div>
|
||||
</div>
|
||||
<div className="copy-list-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="button button-primary"
|
||||
disabled={disabled}
|
||||
onClick={() => runAction(
|
||||
ipcInvoke('mods:applyPreset', { copyId: copy.id, presetId: preset.id }),
|
||||
t('mods.presets.applied', { name: preset.name }),
|
||||
)}
|
||||
>
|
||||
{t('mods.presets.apply')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="button"
|
||||
disabled={disabled}
|
||||
onClick={() => runAction(
|
||||
ipcInvoke('mods:savePreset', { copyId: copy.id, name: preset.name, overwriteId: preset.id }),
|
||||
t('mods.presets.updated', { name: preset.name }),
|
||||
)}
|
||||
>
|
||||
{t('mods.presets.overwrite')}
|
||||
</button>
|
||||
<button type="button" className="button" disabled={busy} onClick={() => exportPreset(preset.id)}>
|
||||
{t('mods.presets.export')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="button"
|
||||
disabled={disabled}
|
||||
onClick={() => runAction(ipcInvoke('mods:deletePreset', { copyId: copy.id, presetId: preset.id }))}
|
||||
>
|
||||
{t('mods.presets.delete')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="mods-section">
|
||||
<h3 className="mods-subheading">{t('mods.repo.heading')}</h3>
|
||||
<p className="mods-hint">{t('mods.repo.description')}</p>
|
||||
<Row
|
||||
label={t('mods.repo.pathLabel')}
|
||||
hint={state.isCustomModsDir ? t('mods.repo.customNote') : t('mods.repo.defaultNote')}
|
||||
>
|
||||
<code className="mods-path">{state.modsDir}</code>
|
||||
</Row>
|
||||
<div className="copy-list-actions" style={{ marginTop: 12 }}>
|
||||
<button type="button" className="button" onClick={() => ipcInvoke('mods:openFolder').catch(onError)}>
|
||||
{t('mods.openFolder')}
|
||||
</button>
|
||||
<button type="button" className="button" disabled={disabled} onClick={pickCustomFolder}>
|
||||
{t('mods.repo.changeFolder')}
|
||||
</button>
|
||||
{state.isCustomModsDir && (
|
||||
<button type="button" className="button" disabled={disabled} onClick={resetFolder}>
|
||||
{t('mods.repo.resetDefault')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
</>
|
||||
)}
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
|
||||
interface ModCardProps {
|
||||
readonly mod: ModListItem;
|
||||
readonly index: number;
|
||||
readonly total: number;
|
||||
readonly enabled: boolean;
|
||||
readonly expanded: boolean;
|
||||
readonly disabled: boolean;
|
||||
readonly canDrag: boolean;
|
||||
readonly language: string;
|
||||
readonly issues: readonly ModIssueView[];
|
||||
readonly onToggle: (next: boolean) => void;
|
||||
readonly onMove: (delta: -1 | 1) => void;
|
||||
readonly onToggleExpand: () => void;
|
||||
readonly onDragStart: () => void;
|
||||
readonly onDrop: (event: DragEvent<HTMLDivElement>) => void;
|
||||
}
|
||||
|
||||
function ModCard({
|
||||
mod,
|
||||
index,
|
||||
total,
|
||||
enabled,
|
||||
expanded,
|
||||
disabled,
|
||||
canDrag,
|
||||
language,
|
||||
issues,
|
||||
onToggle,
|
||||
onMove,
|
||||
onToggleExpand,
|
||||
onDragStart,
|
||||
onDrop,
|
||||
}: ModCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const displayName = localized(mod.name, language) || mod.id;
|
||||
const description = localized(mod.description, language);
|
||||
const errorCount = issues.filter((i) => i.severity === 'error').length;
|
||||
const warnCount = issues.filter((i) => i.severity === 'warning').length;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`mods-card${enabled ? ' mods-card-enabled' : ''}`}
|
||||
draggable={canDrag}
|
||||
onDragStart={onDragStart}
|
||||
onDragOver={(event) => { if (canDrag) event.preventDefault(); }}
|
||||
onDrop={onDrop}
|
||||
>
|
||||
<div className="mods-card-row">
|
||||
<span className="mods-order-num" title={t('mods.loadOrderHint')}>#{index + 1}</span>
|
||||
<input
|
||||
type="checkbox"
|
||||
className="mods-checkbox"
|
||||
checked={enabled}
|
||||
disabled={disabled}
|
||||
aria-label={displayName}
|
||||
onChange={(event) => onToggle(event.target.checked)}
|
||||
/>
|
||||
<div className="mods-card-main" onClick={onToggleExpand}>
|
||||
<div className="mods-card-title">
|
||||
<span className="mods-name">{displayName}</span>
|
||||
<span className="mods-version">v{mod.version}</span>
|
||||
<span className="mods-author">· {mod.author}</span>
|
||||
<div className="mods-badges">
|
||||
{mod.badges.map((badge) => (
|
||||
<span key={badge} className={`mods-badge mods-badge-${badge}`}>
|
||||
{t(`mods.badges.${badge}`)}
|
||||
</span>
|
||||
))}
|
||||
{errorCount > 0 && <span className="mods-badge mods-badge-error">{t('mods.errorCount', { count: errorCount })}</span>}
|
||||
{warnCount > 0 && <span className="mods-badge mods-badge-warn">{t('mods.warnCount', { count: warnCount })}</span>}
|
||||
</div>
|
||||
</div>
|
||||
{description && <div className="mods-card-desc">{description}</div>}
|
||||
</div>
|
||||
<div className="mods-card-actions">
|
||||
<button
|
||||
type="button"
|
||||
className="button mods-move-btn"
|
||||
disabled={disabled || index <= 0}
|
||||
title={t('mods.moveUp')}
|
||||
onClick={() => onMove(-1)}
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="button mods-move-btn"
|
||||
disabled={disabled || index < 0 || index >= total - 1}
|
||||
title={t('mods.moveDown')}
|
||||
onClick={() => onMove(1)}
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
<button type="button" className="button" onClick={onToggleExpand}>
|
||||
{expanded ? t('mods.hideDetails') : t('mods.showDetails')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{expanded && (
|
||||
<div className="mods-card-details">
|
||||
<div className="mods-detail-grid">
|
||||
<div><span>ID:</span> <code>{mod.id}</code></div>
|
||||
<div><span>API:</span> <code>{mod.apiVersion}</code></div>
|
||||
<div><span>{t('mods.details.folder')}:</span> <code>{mod.folderName}</code></div>
|
||||
{mod.gameVersions.length > 0 && (
|
||||
<div><span>{t('mods.details.gameVersions')}:</span> <code>{mod.gameVersions.join(', ')}</code></div>
|
||||
)}
|
||||
{mod.requires.length > 0 && (
|
||||
<div><span>{t('mods.details.requires')}:</span> <code>{mod.requires.join(', ')}</code></div>
|
||||
)}
|
||||
{mod.conflicts.length > 0 && (
|
||||
<div><span>{t('mods.details.conflicts')}:</span> <code>{mod.conflicts.join(', ')}</code></div>
|
||||
)}
|
||||
</div>
|
||||
<div className="mods-detail-summary">
|
||||
{mod.serverTuningFiles.length > 0 && (
|
||||
<span>{t('mods.details.tuning', { count: mod.serverTuningFiles.length })}</span>
|
||||
)}
|
||||
{mod.hasServerScript && <span>{t('mods.details.serverScript')}</span>}
|
||||
{mod.packOperations.length > 0 && (
|
||||
<span>{t('mods.details.packOps', { count: mod.packOperations.length })}</span>
|
||||
)}
|
||||
{mod.hasClientAddon && (
|
||||
<span>{t('mods.details.addon', { count: mod.addonFileCount })}</span>
|
||||
)}
|
||||
{mod.guiPatchCount > 0 && (
|
||||
<span>{t('mods.details.guiPatches', { count: mod.guiPatchCount })}</span>
|
||||
)}
|
||||
{mod.exePatchCount > 0 && (
|
||||
<span>{t('mods.details.exePatches', { count: mod.exePatchCount })}</span>
|
||||
)}
|
||||
{mod.clientFileCount > 0 && (
|
||||
<span>{t('mods.details.companionFiles', { count: mod.clientFileCount })}</span>
|
||||
)}
|
||||
{mod.hasConfigBlkPatch && <span>{t('mods.details.configBlk')}</span>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
/**
|
||||
* The window's pages and the sections of those that have a section list in the side panel.
|
||||
* Pages for later features (saves, tuning) join this list when they are built.
|
||||
*/
|
||||
|
||||
export const PAGES = ['home', 'saves', 'tuning', 'copies', 'settings', 'about'] as const;
|
||||
export const PAGES = ['home', 'saves', 'tuning', 'mods', 'copies', 'settings', 'about'] as const;
|
||||
export type PageId = (typeof PAGES)[number];
|
||||
|
||||
export const SAVE_SECTIONS = ['list', 'overview', 'battles', 'vehicles', 'official', 'backup'] as const;
|
||||
@@ -12,6 +11,9 @@ export type SaveSection = (typeof SAVE_SECTIONS)[number];
|
||||
export const TUNING_SECTIONS = ['rewards', 'battle', 'newProfile', 'research'] as const;
|
||||
export type TuningSection = (typeof TUNING_SECTIONS)[number];
|
||||
|
||||
export const MODS_SECTIONS = ['list', 'presets'] as const;
|
||||
export type ModsSection = (typeof MODS_SECTIONS)[number];
|
||||
|
||||
export const COPY_SECTIONS = ['list', 'summary', 'features', 'maintain'] as const;
|
||||
export type CopySection = (typeof COPY_SECTIONS)[number];
|
||||
|
||||
@@ -23,16 +25,25 @@ export interface Route {
|
||||
readonly copies: CopySection;
|
||||
readonly saves: SaveSection;
|
||||
readonly tuning: TuningSection;
|
||||
readonly mods: ModsSection;
|
||||
readonly settings: SettingsSection;
|
||||
}
|
||||
|
||||
export const START_ROUTE: Route = { page: 'home', saves: 'list', tuning: 'rewards', copies: 'list', settings: 'general' };
|
||||
export const START_ROUTE: Route = {
|
||||
page: 'home',
|
||||
saves: 'list',
|
||||
tuning: 'rewards',
|
||||
mods: 'list',
|
||||
copies: 'list',
|
||||
settings: 'general',
|
||||
};
|
||||
|
||||
/** Where a link points: a page, and for pages with sections, which one. */
|
||||
export type Destination =
|
||||
| { readonly page: 'home' | 'about' }
|
||||
| { readonly page: 'saves'; readonly section?: SaveSection }
|
||||
| { readonly page: 'tuning'; readonly section?: TuningSection }
|
||||
| { readonly page: 'mods'; readonly section?: ModsSection }
|
||||
| { readonly page: 'copies'; readonly section?: CopySection }
|
||||
| { readonly page: 'settings'; readonly section?: SettingsSection };
|
||||
|
||||
@@ -42,6 +53,8 @@ export function navigate(route: Route, to: Destination): Route {
|
||||
return { ...route, page: 'saves', saves: to.section ?? route.saves };
|
||||
case 'tuning':
|
||||
return { ...route, page: 'tuning', tuning: to.section ?? route.tuning };
|
||||
case 'mods':
|
||||
return { ...route, page: 'mods', mods: to.section ?? route.mods };
|
||||
case 'copies':
|
||||
return { ...route, page: 'copies', copies: to.section ?? route.copies };
|
||||
case 'settings':
|
||||
|
||||
@@ -435,3 +435,327 @@
|
||||
.about-card .notice .button {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/* ===== Mods ===== */
|
||||
.mods-banner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 12px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.mods-banner-experimental {
|
||||
background: rgba(214, 158, 46, 0.14);
|
||||
border-color: rgba(214, 158, 46, 0.45);
|
||||
color: rgba(255, 241, 204, 0.94);
|
||||
}
|
||||
|
||||
.mods-banner-warn {
|
||||
background: rgba(206, 65, 55, 0.16);
|
||||
border-color: rgba(206, 65, 55, 0.5);
|
||||
color: #ffd7d4;
|
||||
}
|
||||
|
||||
.mods-banner-ok {
|
||||
background: rgba(68, 170, 102, 0.16);
|
||||
border-color: rgba(68, 170, 102, 0.5);
|
||||
color: #d7ffe4;
|
||||
}
|
||||
|
||||
.mods-toolbar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.mods-search {
|
||||
flex: 1 1 180px;
|
||||
min-width: 140px;
|
||||
}
|
||||
|
||||
.mods-preset-select {
|
||||
max-width: 210px;
|
||||
}
|
||||
|
||||
.mods-issues-box {
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 12px;
|
||||
font-size: 12.5px;
|
||||
border-radius: var(--radius);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.mods-issues-error {
|
||||
background: rgba(206, 65, 55, 0.15);
|
||||
border-color: rgba(206, 65, 55, 0.55);
|
||||
}
|
||||
|
||||
.mods-issues-warn {
|
||||
background: rgba(214, 158, 46, 0.13);
|
||||
border-color: rgba(214, 158, 46, 0.45);
|
||||
}
|
||||
|
||||
.mods-issues-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.mods-issues-box ul {
|
||||
margin: 0;
|
||||
padding-left: 18px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.mods-issue-tag {
|
||||
display: inline-block;
|
||||
margin-right: 6px;
|
||||
padding: 1px 5px;
|
||||
font-size: 11px;
|
||||
border-radius: 2px;
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
}
|
||||
|
||||
.mods-empty {
|
||||
padding: 20px 14px;
|
||||
text-align: center;
|
||||
border: 1px dashed var(--line);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.mods-hint {
|
||||
font-size: 12.5px;
|
||||
color: var(--text-dim);
|
||||
line-height: 1.5;
|
||||
margin: 6px 0 12px;
|
||||
}
|
||||
|
||||
.mods-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.mods-card {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
background: rgba(12, 16, 19, 0.62);
|
||||
transition: border-color 120ms ease;
|
||||
}
|
||||
|
||||
.mods-card-enabled {
|
||||
border-left: 3px solid var(--red);
|
||||
background: rgba(18, 24, 29, 0.78);
|
||||
}
|
||||
|
||||
.mods-card-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.mods-order-num {
|
||||
min-width: 26px;
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
text-align: right;
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.mods-checkbox {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mods-card-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mods-card-title {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.mods-name {
|
||||
font-weight: 600;
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.mods-version,
|
||||
.mods-author {
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
.mods-card-desc {
|
||||
margin-top: 3px;
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.mods-badges {
|
||||
display: inline-flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.mods-badge {
|
||||
padding: 1px 6px;
|
||||
font-size: 11px;
|
||||
border-radius: 2px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.16);
|
||||
}
|
||||
|
||||
.mods-badge-data {
|
||||
background: rgba(88, 166, 255, 0.16);
|
||||
color: #b7d7ff;
|
||||
}
|
||||
|
||||
.mods-badge-gui {
|
||||
background: rgba(163, 113, 247, 0.18);
|
||||
color: #dec8ff;
|
||||
}
|
||||
|
||||
.mods-badge-script {
|
||||
background: rgba(214, 158, 46, 0.22);
|
||||
color: #ffe3a3;
|
||||
}
|
||||
|
||||
.mods-badge-exe {
|
||||
background: rgba(206, 65, 55, 0.28);
|
||||
color: #ffc2be;
|
||||
border-color: rgba(206, 65, 55, 0.55);
|
||||
}
|
||||
|
||||
.mods-badge-error {
|
||||
background: rgba(206, 65, 55, 0.35);
|
||||
color: #ffd5d2;
|
||||
}
|
||||
|
||||
.mods-badge-warn {
|
||||
background: rgba(214, 158, 46, 0.25);
|
||||
color: #ffe8b3;
|
||||
}
|
||||
|
||||
.mods-card-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.mods-move-btn {
|
||||
min-width: 28px;
|
||||
padding: 4px 6px;
|
||||
}
|
||||
|
||||
.mods-card-details {
|
||||
padding: 10px 12px 12px 48px;
|
||||
border-top: 1px solid var(--line);
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
.mods-detail-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 4px 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.mods-detail-summary {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.mods-detail-summary span {
|
||||
padding: 2px 7px;
|
||||
border-radius: 2px;
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
color: rgba(255, 255, 255, 0.85);
|
||||
}
|
||||
|
||||
.mods-section {
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.mods-subheading {
|
||||
margin: 0 0 4px;
|
||||
font: 600 15px var(--font-display);
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.mods-preset-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin: 10px 0 14px;
|
||||
}
|
||||
|
||||
.mods-preset-form .input {
|
||||
flex: 1 1 200px;
|
||||
}
|
||||
|
||||
.mods-preset-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.mods-preset-item {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
background: rgba(12, 16, 19, 0.62);
|
||||
}
|
||||
|
||||
.mods-preset-active {
|
||||
border-left: 3px solid var(--red);
|
||||
}
|
||||
|
||||
.mods-preset-meta {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.mods-preset-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 600;
|
||||
color: var(--white);
|
||||
}
|
||||
|
||||
.mods-preset-sub {
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.mods-path {
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
@@ -24,6 +24,11 @@ export const APP_ERROR_CODES = [
|
||||
'diagnostics_export_failed',
|
||||
'copy_not_found',
|
||||
'tuning_invalid',
|
||||
'mods_read_only',
|
||||
'mods_write_failed',
|
||||
'mods_preset_invalid',
|
||||
'mods_blocking_issues',
|
||||
'mods_folder_invalid',
|
||||
'save_not_found',
|
||||
'save_archive_invalid',
|
||||
'save_official_invalid',
|
||||
|
||||
@@ -16,6 +16,8 @@ export const IPC_CHANNEL_PREFIXES = [
|
||||
'copies:',
|
||||
/** Settings shared by the saves of a game copy. */
|
||||
'tuning:',
|
||||
/** Additive mods repository, per-copy ordering/toggles, and presets. */
|
||||
'mods:',
|
||||
/** Local account and save management. */
|
||||
'saves:',
|
||||
/** Starting and stopping the active copy. */
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
} from '../schemas/install.ts';
|
||||
import { LabInfoSchema, LaunchStateSchema } from '../schemas/launch.ts';
|
||||
import { MaintenanceInfoSchema, MaintenanceProgressSchema, MaintenanceRequestSchema } from '../schemas/maintenance.ts';
|
||||
import { ModsStateViewSchema } from '../schemas/mods.ts';
|
||||
import { ActivePatchSetSchema, PackApplyResultSchema, PackCheckSchema, PackReleaseSchema } from '../schemas/patch-pack.ts';
|
||||
import { AccountEditsSchema, SaveAvatarChoicesSchema, SaveAvatarIdSchema, ResearchBranchSchema, ResearchOperationSchema, SaveResearchSchema, OfficialImportOptionsSchema, OfficialPreviewSchema, OnlineDataSourceSchema, SaveOfficialRequestSchema, CurrencyEditsSchema, SaveBackupNameSchema, SaveBackupSchema, SaveDetailsSchema, SaveKeysSchema, SaveListSchema, SaveRegistrationSchema, SaveTransferSchema } from '../schemas/saves.ts';
|
||||
import { TuningPatchSchema, TuningViewSchema } from '../schemas/tuning.ts';
|
||||
@@ -262,6 +263,50 @@ export const ipcContract = {
|
||||
input: z.object({ copyId: CopyIdSchema, patch: TuningPatchSchema }),
|
||||
output: TuningViewSchema,
|
||||
},
|
||||
'mods:getState': {
|
||||
input: z.object({ copyId: CopyIdSchema }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'mods:setEnabled': {
|
||||
input: z.object({ copyId: CopyIdSchema, modId: z.string().min(1), enabled: z.boolean() }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'mods:setOrder': {
|
||||
input: z.object({ copyId: CopyIdSchema, order: z.array(z.string()) }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'mods:autoSort': {
|
||||
input: z.object({ copyId: CopyIdSchema }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'mods:savePreset': {
|
||||
input: z.object({ copyId: CopyIdSchema, name: z.string().trim().min(1).max(80), overwriteId: z.string().min(1).optional() }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'mods:applyPreset': {
|
||||
input: z.object({ copyId: CopyIdSchema, presetId: z.string().min(1) }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'mods:deletePreset': {
|
||||
input: z.object({ copyId: CopyIdSchema, presetId: z.string().min(1) }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'mods:exportPreset': {
|
||||
input: z.object({ copyId: CopyIdSchema, presetId: z.string().min(1) }),
|
||||
output: z.object({ path: z.string().nullable() }),
|
||||
},
|
||||
'mods:importPreset': {
|
||||
input: z.object({ copyId: CopyIdSchema }),
|
||||
output: z.object({ imported: z.boolean(), state: ModsStateViewSchema }),
|
||||
},
|
||||
'mods:openFolder': {
|
||||
input: z.void(),
|
||||
output: z.void(),
|
||||
},
|
||||
'mods:setFolder': {
|
||||
input: z.object({ copyId: CopyIdSchema, path: z.string().min(1).nullable() }),
|
||||
output: ModsStateViewSchema,
|
||||
},
|
||||
'launch:getState': {
|
||||
input: z.void(),
|
||||
output: LaunchStateSchema,
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ModRiskBadgeSchema = z.enum(['data', 'gui', 'script', 'exe']);
|
||||
export const ModIssueSeveritySchema = z.enum(['error', 'warning', 'info']);
|
||||
export const LocalizedTextSchema = z.union([z.string(), z.record(z.string(), z.string())]);
|
||||
|
||||
export const ModPackOperationSchema = z.object({
|
||||
pack: z.string(),
|
||||
targetPath: z.string(),
|
||||
action: z.enum(['blk-patch', 'csv-patch', 'file']),
|
||||
sourceRelativePath: z.string(),
|
||||
});
|
||||
|
||||
export const ModListItemSchema = z.object({
|
||||
id: z.string(),
|
||||
folderName: z.string(),
|
||||
rootDir: z.string(),
|
||||
name: LocalizedTextSchema,
|
||||
description: LocalizedTextSchema.optional(),
|
||||
version: z.string(),
|
||||
author: z.string(),
|
||||
apiVersion: z.string(),
|
||||
gameVersions: z.array(z.string()),
|
||||
requires: z.array(z.string()),
|
||||
conflicts: z.array(z.string()),
|
||||
loadAfter: z.array(z.string()),
|
||||
loadBefore: z.array(z.string()),
|
||||
badges: z.array(ModRiskBadgeSchema),
|
||||
hasServerScript: z.boolean(),
|
||||
serverTuningFiles: z.array(z.string()),
|
||||
packOperations: z.array(ModPackOperationSchema),
|
||||
guiPatchCount: z.number().int().nonnegative(),
|
||||
exePatchCount: z.number().int().nonnegative(),
|
||||
hasClientAddon: z.boolean(),
|
||||
addonFileCount: z.number().int().nonnegative(),
|
||||
clientFileCount: z.number().int().nonnegative(),
|
||||
hasConfigBlkPatch: z.boolean(),
|
||||
});
|
||||
|
||||
export const ModDiscoveryErrorSchema = z.object({
|
||||
folderName: z.string(),
|
||||
rootDir: z.string(),
|
||||
reason: z.string(),
|
||||
});
|
||||
|
||||
export const ModIssueSchema = z.object({
|
||||
severity: ModIssueSeveritySchema,
|
||||
kind: z.string(),
|
||||
modId: z.string(),
|
||||
otherModId: z.string().optional(),
|
||||
detail: z.string(),
|
||||
});
|
||||
|
||||
export const ModPresetSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1).max(80),
|
||||
order: z.array(z.string()),
|
||||
enabled: z.record(z.string(), z.boolean()),
|
||||
updatedAt: z.string(),
|
||||
});
|
||||
|
||||
export const ModsStateViewSchema = z.object({
|
||||
modsDir: z.string(),
|
||||
defaultModsDir: z.string(),
|
||||
isCustomModsDir: z.boolean(),
|
||||
apiVersion: z.string(),
|
||||
mods: z.array(ModListItemSchema),
|
||||
discoveryErrors: z.array(ModDiscoveryErrorSchema),
|
||||
order: z.array(z.string()),
|
||||
enabled: z.record(z.string(), z.boolean()),
|
||||
activePresetId: z.string().nullable(),
|
||||
presets: z.array(ModPresetSchema),
|
||||
issues: z.array(ModIssueSchema),
|
||||
hasBlockingErrors: z.boolean(),
|
||||
});
|
||||
|
||||
export const ModPresetTransferSchema = z.object({
|
||||
format: z.literal(1),
|
||||
name: z.string().min(1).max(80),
|
||||
order: z.array(z.string()),
|
||||
enabled: z.record(z.string(), z.boolean()),
|
||||
});
|
||||
|
||||
export type ModListItem = z.output<typeof ModListItemSchema>;
|
||||
export type ModPresetView = z.output<typeof ModPresetSchema>;
|
||||
export type ModIssueView = z.output<typeof ModIssueSchema>;
|
||||
export type ModsStateView = z.output<typeof ModsStateViewSchema>;
|
||||
@@ -37,6 +37,8 @@ export const SettingsSchema = z.object({
|
||||
developerMode: z.boolean().default(true),
|
||||
labStockPath: LabPathSchema.default(null),
|
||||
labDataPath: LabPathSchema.default(null),
|
||||
/** Custom global mods repository directory; null uses `<userData>/mods`. */
|
||||
modsFolder: LabPathSchema.default(null),
|
||||
});
|
||||
|
||||
export type Settings = z.output<typeof SettingsSchema>;
|
||||
@@ -60,6 +62,7 @@ export const SettingsPatchSchema = z.object({
|
||||
developerMode: z.boolean().optional(),
|
||||
labStockPath: LabPathSchema.optional(),
|
||||
labDataPath: LabPathSchema.optional(),
|
||||
modsFolder: LabPathSchema.optional(),
|
||||
});
|
||||
|
||||
export type SettingsPatch = z.output<typeof SettingsPatchSchema>;
|
||||
|
||||
@@ -11,7 +11,7 @@ const launcher = join(repository, 'apps', 'launcher');
|
||||
const modules = join(repository, 'node_modules');
|
||||
const buildFolder = join(repository, 'build');
|
||||
const output = join(buildFolder, 'windows-installer');
|
||||
const workspacePackages = ['apps/server', 'packages/blk', 'packages/exepatch', 'packages/jsonc', 'packages/patcher', 'packages/vromfs'];
|
||||
const workspacePackages = ['apps/server', 'packages/blk', 'packages/exepatch', 'packages/jsonc', 'packages/mods', 'packages/patcher', 'packages/vromfs'];
|
||||
|
||||
interface LauncherManifest {
|
||||
readonly productName: string;
|
||||
|
||||
Reference in new issue
Block a user