Files
WT-Offline/apps/launcher/src/shared/schemas/settings.ts
T

73 lines
3.4 KiB
TypeScript

import { z } from 'zod';
import { LANGUAGE_CHOICES } from '../languages.ts';
import { parseLaunchArguments } from '../launch-arguments.ts';
import { releaseRepositoryUrl } from '../update-source.ts';
import { BACKGROUND_RANDOM, BackgroundChoiceSchema } from './background.ts';
const LanguageChoiceSchema = z.enum(LANGUAGE_CHOICES);
const WindowCloseSchema = z.enum(['quit', 'tray']);
const AfterGameStartsSchema = z.enum(['minimize', 'keep']);
const LabPathSchema = z.string().min(1).nullable();
const PortModeSchema = z.enum(['auto', 'fixed']);
const PortSchema = z.number().int().min(1).max(65535);
export const LAUNCH_ARGUMENTS_LIMIT = 4000;
const LaunchArgumentsSchema = z.string().max(LAUNCH_ARGUMENTS_LIMIT).refine((value) => parseLaunchArguments(value) !== null);
export const UpdateMirrorUrlSchema = z.string().trim().refine((value) => value === '' || releaseRepositoryUrl(value) !== null);
/** The launcher's own settings (not the game's, not the local service's tuning). */
export const SettingsSchema = z.object({
language: LanguageChoiceSchema.default('system'),
/** A new picture on every start, or one picture by its key (schemas/background.ts). */
background: BackgroundChoiceSchema.default(BACKGROUND_RANDOM),
/** Fetch wallpapers from the game website's public gallery. */
officialWallpapers: z.boolean().default(true),
/** Check for a newer adaptation pack when the launcher starts. */
checkPatchPacksOnStart: z.boolean().default(true),
checkLauncherUpdatesOnStart: z.boolean().default(true),
updateMirrorUrl: UpdateMirrorUrlSchema.default(''),
windowClose: WindowCloseSchema.default('quit'),
afterGameStarts: AfterGameStartsSchema.default('minimize'),
autoSaveBackups: z.boolean().default(true),
/** Write launcher, local server traffic, and wto_ws.log files; does not affect game .game_logs. */
loggingEnabled: z.boolean().default(true),
launchPortMode: PortModeSchema.default('auto'),
launchPort: PortSchema.default(27015),
closeServerOnGameExit: z.boolean().default(true),
launchArguments: LaunchArgumentsSchema.default(''),
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>;
/** A change to some settings; the merged result is validated again before it is saved. */
export const SettingsPatchSchema = z.object({
language: LanguageChoiceSchema.optional(),
background: BackgroundChoiceSchema.optional(),
officialWallpapers: z.boolean().optional(),
checkPatchPacksOnStart: z.boolean().optional(),
checkLauncherUpdatesOnStart: z.boolean().optional(),
updateMirrorUrl: UpdateMirrorUrlSchema.optional(),
windowClose: WindowCloseSchema.optional(),
afterGameStarts: AfterGameStartsSchema.optional(),
autoSaveBackups: z.boolean().optional(),
loggingEnabled: z.boolean().optional(),
launchPortMode: PortModeSchema.optional(),
launchPort: PortSchema.optional(),
closeServerOnGameExit: z.boolean().optional(),
launchArguments: LaunchArgumentsSchema.optional(),
developerMode: z.boolean().optional(),
labStockPath: LabPathSchema.optional(),
labDataPath: LabPathSchema.optional(),
modsFolder: LabPathSchema.optional(),
});
export type SettingsPatch = z.output<typeof SettingsPatchSchema>;
export function defaultSettings(): Settings {
return SettingsSchema.parse({});
}