Recipe viewer for fishing

This commit is contained in:
2026-10-11 22:58:28 -03:00
parent 3c80938e91
commit 935c0df7af
7 changed files with 113 additions and 5 deletions
+43 -2
View File
@@ -4,7 +4,7 @@ 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 { EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
import type { ClientContext } from "bworld/client";
import { test_game } from "./helpers.ts";
@@ -12,6 +12,15 @@ const ids = (ingredients: { ids: string[] }[]) => ingredients.map((i) => i.ids.j
// deno-lint-ignore no-explicit-any
const inputs = (recipe: any) => recipe_inputs(recipe, tag_api());
// what the recipe viewer reads of ctx.items, from the registry like the client's
function client_items() {
return {
exists: (id: string) => EverythingRegistry.get("items", id) !== undefined,
ids: () => EverythingRegistry.entries("items").map(([id]) => id),
components: (id: string) => EverythingRegistry.get<ItemRegistry>("items", id)?.components ?? {},
};
}
Deno.test("the recipe viewer finds what makes and uses an item, in any recipe type", async () => {
const { game } = await test_game("mods");
const all = game.recipes.all;
@@ -52,7 +61,7 @@ Deno.test("recipes are found by category in jei's order, and a catalyst's uses a
const ctx = {
recipes: { list: () => game.recipes.all },
tags: tag_api(),
items: { exists: (id: string) => EverythingRegistry.get("items", id) !== undefined },
items: client_items(),
} as unknown as ClientContext;
const index = new RecipeIndex(ctx);
@@ -69,3 +78,35 @@ Deno.test("recipes are found by category in jei's order, and a catalyst's uses a
assertEquals(furnace_uses.find(([type]) => type === "fuel")?.[1], all.filter((r) => r.type === "fuel"));
assertEquals(index.find("bworld:air", "recipes"), []);
});
Deno.test("clicking a fish shows when and where it bites, and the fishing rod's uses are every fish", async () => {
await test_game("mods");
const ctx = {
recipes: { list: () => [] },
tags: tag_api(),
items: client_items(),
} as unknown as ClientContext;
const index = new RecipeIndex(ctx);
const [fishing] = index.find("bworld:red_mullet", "recipes");
assertEquals(fishing.category.title, "Fishing");
assertEquals(fishing.category.catalysts, ["bworld:fishing_rod"]);
const lines: string[] = [];
const slots: string[] = [];
fishing.category.draw(fishing.recipes[0], {
slot: (ingredient) => slots.push(ingredient!.ids[0]),
texture: () => {},
text: (text) => lines.push(text),
});
assertEquals(slots, ["bworld:red_mullet"]);
assertEquals(lines, ["Seasons: Summer, Winter", "Biomes: Ocean", "Time: 6:00 to 19:00", "In: Water"]);
// a lava fish without limits, and every fish under the rod
const lava_lines: string[] = [];
const [lava] = index.find("bworld:prismfish", "recipes");
lava.category.draw(lava.recipes[0], { slot: () => {}, texture: () => {}, text: (text) => lava_lines.push(text) });
assertEquals(lava_lines, ["Seasons: all", "Biomes: all", "Time: all day", "In: Lava"]);
const fish = index.find("bworld:fishing_rod", "uses")[0].recipes.map((recipe) => recipe.result);
assert(fish.includes("bworld:cod") && fish.includes("bworld:prismfish"));
// a fish isn't a use of the water it lives in
assertEquals(index.find("bworld:water", "uses"), []);
});