Improve recipe viewer

This commit is contained in:
2026-10-03 13:41:01 -03:00
parent 50d47cedef
commit ecc0295f6d
12 changed files with 666 additions and 452 deletions
+28 -1
View File
@@ -1,7 +1,11 @@
// the recipe viewer mod reads every mod's recipes, its own types included
import { assert, assertEquals } from "@std/assert";
import { category_name, inputs as recipe_inputs, outputs } from "../mods/recipe_viewer/scripts/client.ts";
import { category_name } from "../mods/recipe_viewer/scripts/categories.ts";
import { inputs as recipe_inputs, outputs } from "../mods/recipe_viewer/scripts/recipes.ts";
import { RecipeIndex } from "../mods/recipe_viewer/scripts/recipes_screen.ts";
import { tag_api } from "$/common/tags.ts";
import { EverythingRegistry } from "$/common/everything_registry.ts";
import type { ClientContext } from "bworld/client";
import { test_game } from "./helpers.ts";
const ids = (ingredients: { ids: string[] }[]) => ingredients.map((i) => i.ids.join("|"));
@@ -42,3 +46,26 @@ Deno.test("the recipe viewer finds what makes and uses an item, in any recipe ty
assertEquals(ids(inputs(making("bworld:stone_pickaxe")[0])), ["bworld:wood_pickaxe", "bworld:stone"]);
assertEquals(category_name("smithing"), "Smithing");
});
Deno.test("recipes are found by category in jei's order, and a catalyst's uses are everything made in it", async () => {
const { game } = await test_game("mods");
const ctx = {
recipes: { list: () => game.recipes.all },
tags: tag_api(),
items: { exists: (id: string) => EverythingRegistry.get("items", id) !== undefined },
} as unknown as ClientContext;
const index = new RecipeIndex(ctx);
const titles = index.categories.map((category) => category.title);
assertEquals(titles.slice(0, 4), ["Crafting", "Smelting", "Fuel", "Smithing"]);
assert(titles.includes("Cooking"));
assertEquals(index.categories.find((c) => c.type === "farmersdelight:cooking")?.catalysts, [
"farmersdelight:cooking_pot",
]);
const furnace_uses = index.find("bworld:furnace", "uses").map(({ category, recipes }) => [category.type, recipes]);
const all = game.recipes.all;
assertEquals(furnace_uses.find(([type]) => type === "furnace")?.[1], all.filter((r) => r.type === "furnace"));
assertEquals(furnace_uses.find(([type]) => type === "fuel")?.[1], all.filter((r) => r.type === "fuel"));
assertEquals(index.find("bworld:air", "recipes"), []);
});