Proper cutting board

This commit is contained in:
2026-09-29 00:04:56 -03:00
parent a51adba46f
commit 445148e812
26 changed files with 549 additions and 16 deletions
+15 -6
View File
@@ -23,6 +23,7 @@ const CATALYSTS: Record<string, string> = {
fuel: "bworld:furnace",
smithing: "bworld:smithing_table",
"farmersdelight:cooking": "farmersdelight:cooking_pot",
"farmersdelight:cutting": "farmersdelight:cutting_board",
};
const CATEGORY_NAMES: Record<string, string> = {
shaped: "Crafting",
@@ -255,7 +256,7 @@ class RecipeViewer {
break;
default: {
// a mod's own type: the items in its lists in a grid, single items (like a bowl to serve in) under
// the arrow, then what it makes
// the arrow, then what it makes, one under the other
const { grid, extras } = mod_recipe_inputs(recipe);
grid.slice(0, 9).forEach((ingredient, i) =>
cell(ingredient, x + (i % 3) * CELL, top + Math.floor(i / 3) * CELL)
@@ -264,7 +265,10 @@ class RecipeViewer {
extras.slice(0, 1).forEach((ingredient) =>
cell(ingredient, x + 3.5 * CELL, top + CELL * 1.5, ["Served in"])
);
outputs(recipe).slice(0, 1).forEach((output) => cell(output, x + 5 * CELL, top + CELL / 2));
const made = outputs(recipe).slice(0, 3);
made.forEach((output, i) =>
cell(output, x + 5 * CELL, made.length > 1 ? top + i * CELL : top + CELL / 2)
);
if (typeof recipe.cook_time === "number") {
g.text(seconds(recipe.cook_time), x + 5 * CELL, top + CELL * 1.5 + (CELL - TEXT) / 2, {
color: LABEL_COLOR,
@@ -280,7 +284,9 @@ class RecipeViewer {
function card_height(recipe: Recipe): number {
let rows = 2;
if (recipe.type === "shaped") rows = 3;
else if (!(recipe.type in CATEGORY_NAMES)) rows = Math.max(2, Math.ceil(mod_recipe_inputs(recipe).grid.length / 3));
else if (!(recipe.type in CATEGORY_NAMES)) {
rows = Math.max(2, Math.ceil(mod_recipe_inputs(recipe).grid.length / 3), outputs(recipe).length);
}
return LINE + Math.min(rows, 3) * CELL + GAP;
}
@@ -317,10 +323,13 @@ export function outputs(recipe: Recipe): Ingredient[] {
case "smithing":
return [{ ids: [recipe.result], count: 1 }];
default: {
// one item or stack, or a list of them, like what a cutting board cuts something into
const output = recipe.result ?? recipe.output;
if (typeof output === "string") return [{ ids: [output], count: 1 }];
if (output && typeof output.id === "string") return [stack(output)];
return [];
return [output].flat().flatMap((output): Ingredient[] => {
if (typeof output === "string") return [{ ids: [output], count: 1 }];
if (output && typeof output.id === "string") return [stack(output)];
return [];
});
}
}
}