add zod validation

This commit is contained in:
Viktor Rådberg
2023-12-27 20:35:10 +01:00
parent e8528f46ae
commit 9812c6737c
4 changed files with 40 additions and 5 deletions

View File

@@ -1,9 +1,17 @@
import { z } from 'zod';
export enum Orientation {
OppositeLandscape = 'opposite-landscape',
Landscape = 'landscape',
Portrait = 'portrait',
}
export enum GameFormat {
Commander = 'commander',
Standard = 'standard',
TwoHeadedGiant = 'two-headed-giant',
}
export type Settings = {
keepAwake: boolean;
showStartingPlayer: boolean;
@@ -18,4 +26,10 @@ export type InitialGameSettings = {
orientation: Orientation;
};
type GameFormat = 'commander' | 'standard' | 'two-headed-giant';
export const InitialGameSettingsSchema = z.object({
startingLifeTotal: z.number().min(1).max(200).default(20),
useCommanderDamage: z.boolean().default(false),
gameFormat: z.nativeEnum(GameFormat).optional(),
numberOfPlayers: z.number().min(1).max(6).default(2),
orientation: z.nativeEnum(Orientation).default(Orientation.Landscape),
});