Recipe types from shared scripts and stuff
This commit is contained in:
+7
-19
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user