Recipe types from shared scripts and stuff

This commit is contained in:
2026-11-01 20:41:23 -03:00
parent c8b5f2a3bd
commit 65113862f7
34 changed files with 234 additions and 134 deletions
+7 -19
View File
@@ -593,31 +593,15 @@ const shaped_recipe = z.object({
}
});
// cook_time and burn_time are in ticks
const furnace_recipe = z.object({
type: z.literal("furnace"),
input: item_choice,
output: stack,
cook_time: z.int().min(1),
});
const fuel_recipe = z.object({ type: z.literal("fuel"), item: item_choice, burn_time: z.int().min(1) });
export interface ModRecipeJson {
type: `${string}:${string}`;
[field: string]: unknown;
}
export type RecipeJson =
| z.infer<typeof shaped_recipe>
| z.infer<typeof furnace_recipe>
| z.infer<typeof fuel_recipe>
| ModRecipeJson;
export type RecipeJson = z.infer<typeof shaped_recipe> | ModRecipeJson;
const engine_recipes = new Map<string, z.ZodType>([
["shaped", shaped_recipe],
["furnace", furnace_recipe],
["fuel", fuel_recipe],
]);
// a mod's own types, like "bworld:cooking" for its cooking pot, are only stored by the engine. the mod parses them,
@@ -625,10 +609,10 @@ const engine_recipes = new Map<string, z.ZodType>([
const recipe_schema = by_kind(
"type",
(type) => engine_recipes.get(type) ?? (ID_PATTERN.test(type) ? json_object : undefined),
'must be "shaped", "furnace", "fuel" or a mod\'s own type like "bworld:cooking"',
'must be "shaped" or a mod\'s own type like "bworld:cooking"',
);
// a recipe type a mod made up, as opposed to the engine's shaped, furnace and fuel
// a recipe type a mod made up, as opposed to the engine's shaped
export function is_mod_recipe(recipe: RecipeJson): recipe is ModRecipeJson {
return recipe.type.includes(":");
}
@@ -643,6 +627,10 @@ export function stack_problems(json: unknown): Problems {
return find_problems(stack, json);
}
export function choice_problems(json: unknown): Problems {
return find_problems(item_choice, json);
}
// the crafting grid's format, see server/game/crafting.ts
export interface GridRecipe {
width: number;