V1.0.0
Two Keys: co-op mystery games for couples. Eight games on four engines (story, defuse, sync, labyrinth), two-device and couch play, mobile-first UI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,229 @@
|
||||
import { z } from 'zod';
|
||||
import { CLUE_TYPES } from '@two-keys/shared';
|
||||
|
||||
const hex = z.string().regex(/^#[0-9a-fA-F]{6}$/, 'expected a #rrggbb colour');
|
||||
const roleInfo = z.object({ name: z.string().min(1), blurb: z.string() });
|
||||
|
||||
const header = {
|
||||
id: z.string().regex(/^[a-z0-9-]+$/),
|
||||
category: z.enum(['murder-mystery', 'escape-room', 'co-op']),
|
||||
title: z.string().min(1),
|
||||
tagline: z.string().min(1),
|
||||
estimatedMinutes: z.number().positive(),
|
||||
difficulty: z.number().int().min(1).max(3),
|
||||
players: z.object({ min: z.literal(2), max: z.literal(2) }),
|
||||
theme: z.object({ primary: hex, accent: hex, background: hex, headingFont: z.string().min(1) }),
|
||||
roles: z.object({ A: roleInfo, B: roleInfo }),
|
||||
intro: z.string().min(1),
|
||||
};
|
||||
|
||||
// ---------- story ----------
|
||||
|
||||
const clueSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
type: z.enum(CLUE_TYPES),
|
||||
body: z.string(),
|
||||
signal: z
|
||||
.string()
|
||||
.regex(/^[.\-/]+$/, 'signal may only contain . - /')
|
||||
.optional(),
|
||||
});
|
||||
|
||||
const optionSchema = z.object({ id: z.string().min(1), label: z.string().min(1) });
|
||||
|
||||
const lockSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
prompt: z.string().min(1),
|
||||
inputType: z.enum(['code', 'text', 'choice']),
|
||||
format: z.string().optional(),
|
||||
options: z.array(optionSchema).min(2).optional(),
|
||||
answers: z.array(z.string().min(1)).min(1),
|
||||
hints: z.array(z.string().min(1)).length(3),
|
||||
successText: z.string().optional(),
|
||||
keyName: z.string().optional(),
|
||||
});
|
||||
|
||||
const chapterSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
narrative: z.string(),
|
||||
clues: z.object({
|
||||
A: z.array(clueSchema).default([]),
|
||||
B: z.array(clueSchema).default([]),
|
||||
shared: z.array(clueSchema).default([]),
|
||||
}),
|
||||
lock: lockSchema.extend({ successText: z.string().min(1), keyName: z.string().min(1) }),
|
||||
});
|
||||
|
||||
const finaleSchema = z.discriminatedUnion('type', [
|
||||
z.object({
|
||||
type: z.literal('accusation'),
|
||||
prompt: z.string().min(1),
|
||||
questions: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string().min(1),
|
||||
label: z.string().min(1),
|
||||
options: z.array(optionSchema).min(2),
|
||||
answer: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.min(1),
|
||||
maxAttempts: z.number().int().positive(),
|
||||
successEnding: z.string().min(1),
|
||||
failEnding: z.string().min(1),
|
||||
reveal: z.string().min(1),
|
||||
}),
|
||||
z.object({
|
||||
type: z.literal('escape'),
|
||||
prompt: z.string().min(1),
|
||||
clues: z.object({ A: z.array(clueSchema).default([]), B: z.array(clueSchema).default([]) }),
|
||||
lock: lockSchema,
|
||||
successEnding: z.string().min(1),
|
||||
}),
|
||||
]);
|
||||
|
||||
const storySchema = z.object({
|
||||
...header,
|
||||
engine: z.literal('story'),
|
||||
suspects: z
|
||||
.array(z.object({ id: z.string(), name: z.string(), role: z.string(), description: z.string() }))
|
||||
.optional(),
|
||||
chapters: z.array(chapterSchema).min(1),
|
||||
finale: finaleSchema,
|
||||
});
|
||||
|
||||
// ---------- defuse ----------
|
||||
|
||||
const range = z.object({ min: z.number().int().nonnegative(), max: z.number().int().nonnegative() });
|
||||
const moduleId = z.enum(['wires', 'button', 'keypad']);
|
||||
|
||||
const defuseSchema = z.object({
|
||||
...header,
|
||||
engine: z.literal('defuse'),
|
||||
device: z.object({
|
||||
serial: z.object({ length: z.number().int().min(2), alphabet: z.string().min(2) }),
|
||||
batteries: range,
|
||||
}),
|
||||
levels: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
timeSeconds: z.number().int().positive(),
|
||||
modules: z.array(moduleId).min(1),
|
||||
keyName: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.min(1),
|
||||
strikes: z.object({ max: z.number().int().positive(), speedUpPerStrike: z.number().nonnegative() }),
|
||||
modules: z.object({
|
||||
wires: z.object({ count: range, colors: z.array(z.string()).min(2) }),
|
||||
button: z.object({
|
||||
labels: z.array(z.string()).min(1),
|
||||
colors: z.array(z.string()).min(1),
|
||||
stripColors: z.array(z.string()).min(1),
|
||||
}),
|
||||
keypad: z.object({
|
||||
symbols: z.record(z.string()),
|
||||
columns: z.array(z.array(z.string()).min(4)).min(1),
|
||||
}),
|
||||
}),
|
||||
manual: z.string().min(1),
|
||||
fixtures: z.object({
|
||||
wires: z.array(
|
||||
z.object({
|
||||
serial: z.string(),
|
||||
batteries: z.number().int(),
|
||||
wires: z.array(z.string()),
|
||||
expect: z.object({ type: z.literal('cut'), index: z.number().int() }),
|
||||
}),
|
||||
),
|
||||
button: z.array(
|
||||
z.object({
|
||||
batteries: z.number().int(),
|
||||
label: z.string(),
|
||||
color: z.string(),
|
||||
strip: z.string(),
|
||||
expect: z.union([
|
||||
z.object({ type: z.literal('tap') }),
|
||||
z.object({ type: z.literal('hold'), releaseDigit: z.number().int() }),
|
||||
]),
|
||||
}),
|
||||
),
|
||||
keypad: z.array(z.object({ symbols: z.array(z.string()), expect: z.array(z.string()) })),
|
||||
}),
|
||||
});
|
||||
|
||||
// ---------- sync ----------
|
||||
|
||||
const questionSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
q: z.string().min(1),
|
||||
options: z.array(z.coerce.string()).min(2),
|
||||
});
|
||||
|
||||
const syncSchema = z.object({
|
||||
...header,
|
||||
engine: z.literal('sync'),
|
||||
rules: z.object({
|
||||
questionsPerRound: z.number().int().positive(),
|
||||
pointsForKey: z.number().int().positive(),
|
||||
replaysPerRound: z.number().int().nonnegative(),
|
||||
}),
|
||||
rounds: z
|
||||
.array(
|
||||
z.object({
|
||||
id: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
type: z.enum(['match', 'predict']),
|
||||
subject: z.enum(['A', 'B']).optional(),
|
||||
blurb: z.string(),
|
||||
keyName: z.string().min(1),
|
||||
}),
|
||||
)
|
||||
.min(1),
|
||||
match: z.array(questionSchema),
|
||||
predict: z.array(questionSchema),
|
||||
});
|
||||
|
||||
// ---------- labyrinth ----------
|
||||
|
||||
const labyrinthSchema = z.object({
|
||||
...header,
|
||||
engine: z.literal('labyrinth'),
|
||||
grid: z.array(z.string().regex(/^[#.SEKT]+$/, 'grid may only contain # . S E K T')).min(3),
|
||||
glyphs: z.array(
|
||||
z.object({ x: z.number().int(), y: z.number().int(), glyph: z.string(), label: z.string().min(1) }),
|
||||
),
|
||||
lanterns: z.array(z.object({ x: z.number().int(), y: z.number().int(), name: z.string().min(1) })),
|
||||
explorerView: z.object({
|
||||
flavour: z.object({
|
||||
blank: z.string(),
|
||||
trap: z.string(),
|
||||
lantern: z.string(),
|
||||
exitLocked: z.string(),
|
||||
exitOpen: z.string(),
|
||||
}),
|
||||
}),
|
||||
navigatorView: z.object({ showMoveCount: z.boolean().default(true) }),
|
||||
scoring: z.object({ trapPenaltySeconds: z.number().nonnegative(), parMoves: z.number().int().positive() }),
|
||||
successEnding: z.string().min(1),
|
||||
});
|
||||
|
||||
export const gameSchema = z.discriminatedUnion('engine', [
|
||||
storySchema,
|
||||
defuseSchema,
|
||||
syncSchema,
|
||||
labyrinthSchema,
|
||||
]);
|
||||
|
||||
export type StoryGame = z.infer<typeof storySchema>;
|
||||
export type DefuseGame = z.infer<typeof defuseSchema>;
|
||||
export type SyncGame = z.infer<typeof syncSchema>;
|
||||
export type LabyrinthGame = z.infer<typeof labyrinthSchema>;
|
||||
export type Game = z.infer<typeof gameSchema>;
|
||||
export type Clue = z.infer<typeof clueSchema>;
|
||||
export type Lock = z.infer<typeof lockSchema>;
|
||||
export type SyncQuestion = z.infer<typeof questionSchema>;
|
||||
Reference in New Issue
Block a user