Recipe viewer for crabpots
This commit is contained in:
@@ -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, type ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { type BlockRegistry, EverythingRegistry, type ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import type { ClientContext } from "bworld/client";
|
||||
import { test_game } from "./helpers.ts";
|
||||
|
||||
@@ -21,6 +21,15 @@ function client_items() {
|
||||
};
|
||||
}
|
||||
|
||||
// and of ctx.blocks and ctx.loot
|
||||
function client_blocks() {
|
||||
return {
|
||||
exists: (id: string) => EverythingRegistry.get("blocks", id) !== undefined,
|
||||
components: (id: string) => EverythingRegistry.get<BlockRegistry>("blocks", id)?.components ?? {},
|
||||
};
|
||||
}
|
||||
const client_loot = () => ({ table: (id: string) => EverythingRegistry.get("loot_tables", id) });
|
||||
|
||||
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;
|
||||
@@ -62,6 +71,8 @@ Deno.test("recipes are found by category in jei's order, and a catalyst's uses a
|
||||
recipes: { list: () => game.recipes.all },
|
||||
tags: tag_api(),
|
||||
items: client_items(),
|
||||
blocks: client_blocks(),
|
||||
loot: client_loot(),
|
||||
} as unknown as ClientContext;
|
||||
const index = new RecipeIndex(ctx);
|
||||
|
||||
@@ -85,6 +96,8 @@ Deno.test("clicking a fish shows when and where it bites, and the fishing rod's
|
||||
recipes: { list: () => [] },
|
||||
tags: tag_api(),
|
||||
items: client_items(),
|
||||
blocks: client_blocks(),
|
||||
loot: client_loot(),
|
||||
} as unknown as ClientContext;
|
||||
const index = new RecipeIndex(ctx);
|
||||
const [fishing] = index.find("bworld:red_mullet", "recipes");
|
||||
@@ -110,3 +123,44 @@ Deno.test("clicking a fish shows when and where it bites, and the fishing rod's
|
||||
// a fish isn't a use of the water it lives in
|
||||
assertEquals(index.find("bworld:water", "uses"), []);
|
||||
});
|
||||
|
||||
Deno.test("a crab pot's recipes are what each bait catches in fresh and salt water, with their chances", async () => {
|
||||
await test_game("mods");
|
||||
const ctx = {
|
||||
recipes: { list: () => [] },
|
||||
tags: tag_api(),
|
||||
items: client_items(),
|
||||
blocks: client_blocks(),
|
||||
loot: client_loot(),
|
||||
} as unknown as ClientContext;
|
||||
const index = new RecipeIndex(ctx);
|
||||
|
||||
// grubs are bait for both waters, under the crab pot's tab
|
||||
const [grubs] = index.find("bworld:grubs", "uses");
|
||||
assertEquals(grubs.category.title, "Crab Pot");
|
||||
assertEquals(grubs.category.catalysts, ["bworld:crabpot"]);
|
||||
assertEquals(grubs.recipes.map((recipe) => recipe.crabpot.water), ["freshwater", "saltwater"]);
|
||||
|
||||
// a seashroom comes from grubs in salt water, one in 16
|
||||
const [seashroom] = index.find("bworld:red_seashroom", "recipes");
|
||||
assertEquals(seashroom.recipes.length, 1);
|
||||
const recipe = seashroom.recipes[0];
|
||||
assertEquals(recipe.bait, "bworld:grubs");
|
||||
const slots: [string, string[] | undefined][] = [];
|
||||
const lines: string[] = [];
|
||||
seashroom.category.draw(recipe, {
|
||||
slot: (ingredient, _x, _y, tooltip) => slots.push([ingredient!.ids[0], tooltip]),
|
||||
texture: () => {},
|
||||
text: (text) => lines.push(text),
|
||||
});
|
||||
assertEquals(lines, ["Saltwater"]);
|
||||
assertEquals(slots[0], ["bworld:grubs", ["Bait"]]);
|
||||
assertEquals(slots.length, 1 + 16);
|
||||
assertEquals(slots.find(([id]) => id === "bworld:red_seashroom")?.[1], ["6.3% chance"]);
|
||||
|
||||
// worms in fresh water catch a third each of three things
|
||||
const worms = index.find("bworld:worms", "uses").find((found) => found.category.title === "Crab Pot")!;
|
||||
const freshwater = worms.recipes.find((r) => r.crabpot.water === "freshwater");
|
||||
assertEquals(freshwater.result.toSorted(), ["bworld:chorus_snail", "bworld:crayfish", "bworld:leech"]);
|
||||
assertEquals(freshwater.crabpot.catches.map((c: { chance: number }) => c.chance), [1 / 3, 1 / 3, 1 / 3]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user