mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
wip: game schema
This commit is contained in:
1 parent
e66598f1a7
commit
19c44fbe52
7 files changed
+70
-2
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,54 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const requirementsSchema = z.object({
|
||||
requirements: z.array(z.string()),
|
||||
})
|
||||
|
||||
export type IRequirements = z.infer<typeof requirementsSchema>
|
||||
|
||||
export const fileInputSchema = z.object({
|
||||
path: z.string(),
|
||||
type: z.enum(['file', 'folder']),
|
||||
})
|
||||
|
||||
export type IFileInput = z.infer<typeof fileInputSchema>
|
||||
|
||||
export const fileExistenceInputSchema = fileInputSchema.extend({
|
||||
exists: z.boolean(),
|
||||
})
|
||||
|
||||
export type IFileExistenceInput = z.infer<typeof fileExistenceInputSchema>
|
||||
|
||||
const baseConditionSchema = z.object({
|
||||
command: z.string().optional(),
|
||||
output: z.string().optional(),
|
||||
error: z.string().optional(),
|
||||
pwd: z.string().optional(),
|
||||
files: z.array(fileExistenceInputSchema).optional(),
|
||||
})
|
||||
|
||||
export type ICondition = z.infer<typeof baseConditionSchema> & {
|
||||
or?: ICondition[]
|
||||
not?: ICondition
|
||||
}
|
||||
|
||||
export const conditionSchema: z.ZodType<ICondition> =
|
||||
baseConditionSchema.extend({
|
||||
or: z.lazy(() => z.array(conditionSchema)).optional(),
|
||||
not: z.lazy(() => conditionSchema).optional(),
|
||||
})
|
||||
|
||||
export const responseSchema = z.object({
|
||||
type: z.enum(['narrative', 'dialogue']),
|
||||
content: z.string(),
|
||||
})
|
||||
|
||||
export const stageSchema = z.object({
|
||||
id: z.string().regex(/^[a-zA-Z0-9_-]+$/),
|
||||
name: z.string().optional(),
|
||||
requirements: z.array(z.string()),
|
||||
condition: conditionSchema,
|
||||
response: responseSchema,
|
||||
})
|
||||
|
||||
export type IStage = z.infer<typeof stageSchema>
|
||||
Whitespace-only changes.
Whitespace-only changes.
Reference in new issue
Block a user