Tags for smithing recipes
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
// the base game's bworld:smithing recipes, as another mod adding to them sees them
|
||||
import { assertEquals, assertRejects } from "@std/assert";
|
||||
import { recipe_lookup } from "@/common/mod_loader.ts";
|
||||
import { recipes_mod, test_game } from "./helpers.ts";
|
||||
|
||||
const PLANKS_PICKAXE = {
|
||||
type: "bworld:smithing",
|
||||
tool: "bworld:wood_pickaxe",
|
||||
material: { id: "#bworld:planks", count: 3 },
|
||||
result: "bworld:stick",
|
||||
};
|
||||
|
||||
Deno.test("a smithing material can be a tag, and any of its items fits with enough of it", async () => {
|
||||
const dir = recipes_mod({ planks_pickaxe: PLANKS_PICKAXE });
|
||||
const { game } = await test_game(dir);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const recipes = recipe_lookup(() => game.recipes);
|
||||
const result = (material: string, count: number) =>
|
||||
recipes.find<{ result: string }>("bworld:smithing", {
|
||||
tool: { id: "bworld:wood_pickaxe", count: 1 },
|
||||
material: { id: material, count },
|
||||
})?.result;
|
||||
assertEquals(result("bworld:oak_planks", 3), "bworld:stick");
|
||||
assertEquals(result("bworld:birch_planks", 5), "bworld:stick");
|
||||
assertEquals(result("bworld:birch_planks", 2), undefined);
|
||||
assertEquals(result("bworld:oak_log", 3), undefined);
|
||||
});
|
||||
|
||||
Deno.test("two smithing recipes that fit the same inputs stop the mod loading", async () => {
|
||||
const dir = recipes_mod({
|
||||
planks_pickaxe: PLANKS_PICKAXE,
|
||||
oak_pickaxe: { ...PLANKS_PICKAXE, material: { id: "bworld:oak_planks", count: 1 } },
|
||||
});
|
||||
await assertRejects(
|
||||
() => test_game(dir),
|
||||
Error,
|
||||
"there's already one for bworld:wood_pickaxe with bworld:oak_planks",
|
||||
);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
});
|
||||
Reference in New Issue
Block a user