In the launcher's Saves -> Vehicles & Research page, "Research all" only filled vehicle RP without purchasing them, requiring players to buy each vehicle manually in-game while a separate "Grant regular vehicles" button already added them to the hangar. Merge the two actions into a single "Research and buy all" (`purchase`) action alongside "Unlock modifications" (`equipment`), and switch bulk modification unlocking in save-research.ts to ProfileEquipmentIndex so large saves stay O(N) and write cleanly across chunked modification blocks. Verified with root and launcher npm run typecheck, launcher electron-vite build, and en/zh-CN locale key parity (631 keys).
120 lines
5.2 KiB
TypeScript
120 lines
5.2 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 LocalizedNameSchema = z.object({ en: z.string(), zh: z.string() });
|
|
export const SaveAvatarIdSchema = z.string().regex(/^cardicon_[a-z0-9_]+$/);
|
|
export const SaveAvatarChoicesSchema = z.array(z.object({
|
|
id: SaveAvatarIdSchema,
|
|
name: LocalizedNameSchema,
|
|
}));
|
|
export type SaveAvatarChoices = z.output<typeof SaveAvatarChoicesSchema>;
|
|
|
|
export const AccountEditsSchema = z.object({
|
|
nick: z.string().optional(),
|
|
premiumDays: z.number().int().nonnegative().optional(),
|
|
avatar: SaveAvatarIdSchema.optional(),
|
|
level: z.number().int().nonnegative().optional(),
|
|
});
|
|
export type AccountEdits = z.output<typeof AccountEditsSchema>;
|
|
|
|
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(),
|
|
avatar: z.string(),
|
|
level: z.number().int().nonnegative().nullable(),
|
|
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,
|
|
maxLevel: z.number().int().positive().nullable(),
|
|
battles: z.array(z.object({
|
|
id: z.string(), time: z.number(), won: z.boolean().nullable(), mission: z.string(),
|
|
missionName: LocalizedNameSchema, mode: z.string(),
|
|
vehicles: z.array(z.string()), vehicleNames: z.array(LocalizedNameSchema),
|
|
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 OnlineDataFileNameSchema = z.enum(['global.blk', 'machine.blk', 'storage.blk']);
|
|
export const OnlineDataSourceSchema = z.object({
|
|
accountId: z.string().regex(/^\d+$/),
|
|
folder: z.string().min(1),
|
|
files: z.array(OnlineDataFileNameSchema).min(1),
|
|
updatedAt: z.string(),
|
|
});
|
|
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(),
|
|
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()),
|
|
vehicleNames: z.record(z.string(), LocalizedNameSchema),
|
|
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(['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 OnlineDataSource = z.output<typeof OnlineDataSourceSchema>;
|
|
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>;
|