feat(content): add action costs and multi-yield schema

This commit is contained in:
ginnoir
2026-06-11 18:16:26 -05:00
parent 458a795014
commit ee3d463c9c
9 changed files with 85 additions and 18 deletions
+21 -8
View File
@@ -15,17 +15,21 @@ export const resourceDefSchema = z.object({
startAmount: z.number().nonnegative().default(0),
});
export const resourceAmountSchema = z.object({
resourceId: z.string().min(1),
amount: z.number().positive(),
});
export const actionDefSchema = z.object({
id: z.string().min(1),
name: z.string().min(1),
durationMs: z.number().positive(),
yields: z.object({
resourceId: z.string().min(1),
amount: z.number().positive(),
}),
costs: z.array(resourceAmountSchema).default([]),
yields: z.array(resourceAmountSchema).min(1),
});
export type ResourceDef = z.infer<typeof resourceDefSchema>;
export type ResourceAmount = z.infer<typeof resourceAmountSchema>;
export type ActionDef = z.infer<typeof actionDefSchema>;
export interface Content {
@@ -55,10 +59,19 @@ export function buildContent(input: { resources: unknown[]; actions: unknown[] }
const actionsById = indexById(actions, 'action');
for (const action of actions) {
if (!resourcesById[action.yields.resourceId]) {
throw new Error(
`Action "${action.id}" yields unknown resource "${action.yields.resourceId}"`,
);
for (const y of action.yields) {
if (!resourcesById[y.resourceId]) {
throw new Error(
`Action "${action.id}" yields unknown resource "${y.resourceId}"`,
);
}
}
for (const c of action.costs) {
if (!resourcesById[c.resourceId]) {
throw new Error(
`Action "${action.id}" cost references unknown resource "${c.resourceId}"`,
);
}
}
}