feat(content): add action kind and group schema
This commit is contained in:
+51
-8
@@ -25,20 +25,63 @@ export const unlockDefSchema = z.object({
|
||||
requireStoryFlags: z.array(z.string().min(1)).optional(),
|
||||
});
|
||||
|
||||
export const actionDefSchema = z.object({
|
||||
export const actionKindSchema = z.enum(['instant', 'loop', 'timed', 'story', 'context']);
|
||||
|
||||
export const actionGroupSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
durationMs: z.number().positive(),
|
||||
costs: z.array(resourceAmountSchema).default([]),
|
||||
yields: z.array(resourceAmountSchema).min(1),
|
||||
unlock: unlockDefSchema.optional(),
|
||||
storyHint: z.string().min(1).optional(),
|
||||
storyTooltip: z.string().min(1).optional(),
|
||||
label: z.string().min(1),
|
||||
});
|
||||
|
||||
export const actionDefSchema = z
|
||||
.object({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
kind: actionKindSchema.default('timed'),
|
||||
group: actionGroupSchema,
|
||||
durationMs: z.number().positive().optional(),
|
||||
loopPriority: z.number().int().nonnegative().optional(),
|
||||
costs: z.array(resourceAmountSchema).default([]),
|
||||
yields: z.array(resourceAmountSchema).default([]),
|
||||
unlock: unlockDefSchema.optional(),
|
||||
storyHint: z.string().min(1).optional(),
|
||||
storyTooltip: z.string().min(1).optional(),
|
||||
storyChoiceId: z.string().min(1).optional(),
|
||||
contextId: z.string().min(1).optional(),
|
||||
automation: z
|
||||
.object({
|
||||
unlockAfterManualCompletions: z.number().int().positive().default(1),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.superRefine((action, ctx) => {
|
||||
if ((action.kind === 'timed' || action.kind === 'loop') && action.durationMs === undefined) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: `${action.kind} actions require durationMs`,
|
||||
path: ['durationMs'],
|
||||
});
|
||||
}
|
||||
if (action.kind === 'story' && !action.storyChoiceId) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'story actions require storyChoiceId',
|
||||
path: ['storyChoiceId'],
|
||||
});
|
||||
}
|
||||
if (action.kind === 'timed' && action.yields.length === 0) {
|
||||
ctx.addIssue({
|
||||
code: 'custom',
|
||||
message: 'timed actions require at least one yield',
|
||||
path: ['yields'],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export type ResourceDef = z.infer<typeof resourceDefSchema>;
|
||||
export type ResourceAmount = z.infer<typeof resourceAmountSchema>;
|
||||
export type UnlockDef = z.infer<typeof unlockDefSchema>;
|
||||
export type ActionKind = z.infer<typeof actionKindSchema>;
|
||||
export type ActionGroup = z.infer<typeof actionGroupSchema>;
|
||||
export type ActionDef = z.infer<typeof actionDefSchema>;
|
||||
|
||||
export interface Content {
|
||||
|
||||
Reference in New Issue
Block a user