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

90 lines
4.0 KiB
TypeScript

import { z } from 'zod';
import { CopyIdSchema } from './install.ts';
export const LocalUserIdSchema = z.string().regex(/^\d+$/);
export const SaveKeysSchema = z.object({ copyId: CopyIdSchema, userId: LocalUserIdSchema });
export const CurrencyEditsSchema = z.object({
silverLions: z.number().int().nonnegative().optional(),
goldenEagles: z.number().int().min(0).max(0x7fffffff).optional(),
gjnCents: z.number().int().nonnegative().optional(),
freeRp: z.number().int().nonnegative().optional(),
});
const SaveSummarySchema = z.object({
userId: LocalUserIdSchema,
login: z.string(),
nick: z.string(),
created: z.string(),
currencies: z.object({
silverLions: z.number(),
goldenEagles: z.number(),
gjnCents: z.number(),
freeRp: z.number(),
}).nullable(),
vehicleCount: z.number().int().nonnegative(),
battleCount: z.number().int().nonnegative(),
lastBattle: z.number().nullable(),
premiumDays: z.number(),
});
export const SaveListSchema = z.object({ saves: z.array(SaveSummarySchema), current: LocalUserIdSchema.nullable() });
export const SaveDetailsSchema = z.object({
save: SaveSummarySchema,
battles: z.array(z.object({
id: z.string(), time: z.number(), won: z.boolean().nullable(), mission: z.string(), mode: z.string(),
vehicles: z.array(z.string()), silverLions: z.number(), researchPoints: z.number(),
})),
owned: z.array(z.string()),
research: z.array(z.object({ name: z.string(), points: z.number() })),
});
export const SaveRegistrationSchema = z.object({
copyId: CopyIdSchema, login: z.string(), password: z.string(), nick: z.string(),
});
export const SaveTransferSchema = SaveRegistrationSchema.extend({
source: z.discriminatedUnion('kind', [
z.object({ kind: z.literal('save'), copyId: CopyIdSchema, userId: LocalUserIdSchema }),
z.object({ kind: z.literal('file'), path: z.string().min(1) }),
]),
});
export const SaveBackupNameSchema = z.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z\.(manual|launch|restore|import)\.[0-9a-f-]{36}\.zip$/);
export const SaveBackupSchema = z.object({
name: SaveBackupNameSchema, createdAt: z.string(), type: z.enum(['manual', 'launch', 'restore', 'import']), size: z.number().int().nonnegative(),
});
export const SaveOfficialRequestSchema = SaveKeysSchema.extend({
paths: z.array(z.string().min(1)).min(1).max(3),
});
export const OfficialImportOptionsSchema = z.object({
importSettings: z.boolean(), unlockVehicles: z.boolean(), includeUsedVehicles: z.boolean(),
equipment: z.enum(['full', 'basic', 'stock']),
});
export const OfficialPreviewSchema = z.object({
files: z.array(z.object({ name: z.string(), version: z.number().int() })),
presets: z.array(z.object({ country: z.string(), title: z.string(), vehicles: z.array(z.string()) })),
vehicles: z.array(z.string()),
omitted: z.array(z.string()),
});
export const ResearchBranchSchema = z.object({ country: z.string().min(1), type: z.string().min(1) });
export const ResearchOperationSchema = z.enum(['research', 'purchase', 'equipment']);
export const SaveResearchSchema = z.object({
branches: z.array(ResearchBranchSchema),
selected: ResearchBranchSchema.nullable(),
vehicles: z.array(z.object({
name: z.string(), rank: z.number(), owned: z.boolean(), points: z.number(), needed: z.number(),
})),
});
export type ResearchBranch = z.output<typeof ResearchBranchSchema>;
export type ResearchOperation = z.output<typeof ResearchOperationSchema>;
export type SaveResearch = z.output<typeof SaveResearchSchema>;
export type OfficialPreview = z.output<typeof OfficialPreviewSchema>;
export type OfficialImportOptions = z.output<typeof OfficialImportOptionsSchema>;
export type SaveTransfer = z.output<typeof SaveTransferSchema>;
export type SaveBackup = z.output<typeof SaveBackupSchema>;
export type SaveList = z.output<typeof SaveListSchema>;
export type SaveDetails = z.output<typeof SaveDetailsSchema>;
export type CurrencyEdits = z.output<typeof CurrencyEditsSchema>;
export type SaveRegistration = z.output<typeof SaveRegistrationSchema>;