Tags for smithing recipes
This commit is contained in:
@@ -302,6 +302,25 @@ export async function load_as_player(sources: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// the base game, and a mod after it with these recipes
|
||||
export function recipes_mod(recipes: Record<string, unknown>) {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_recipes_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
const write = (path: string, json: unknown) => {
|
||||
Deno.mkdirSync(`${dir}/kiln/${path.split("/").slice(0, -1).join("/")}`, { recursive: true });
|
||||
Deno.writeTextFileSync(`${dir}/kiln/${path}`, JSON.stringify(json));
|
||||
};
|
||||
write("manifest.json", {
|
||||
format_version: 1,
|
||||
id: "kiln",
|
||||
name: "Kiln",
|
||||
version: "1.0.0",
|
||||
dependencies: [{ id: "bworld", version: "*" }],
|
||||
});
|
||||
for (const [name, recipe] of Object.entries(recipes)) write(`recipes/${name}.json`, { format_version: 1, recipe });
|
||||
return dir;
|
||||
}
|
||||
|
||||
export function copy_dir(from: string, to: string) {
|
||||
if (Deno.statSync(from).isDirectory) {
|
||||
Deno.mkdirSync(to, { recursive: true });
|
||||
|
||||
+3
-22
@@ -4,29 +4,10 @@
|
||||
// the base game's bworld:smelting and bworld:fuel recipes, as another mod adding to them sees them
|
||||
import { assertEquals, assertRejects } from "@std/assert";
|
||||
import { recipe_lookup } from "@/common/mod_loader.ts";
|
||||
import { copy_dir, test_game } from "./helpers.ts";
|
||||
|
||||
// the base game, and a mod after it with these recipes
|
||||
function kiln_mod(recipes: Record<string, unknown>) {
|
||||
const dir = Deno.makeTempDirSync({ prefix: "bworld_smelting_" });
|
||||
copy_dir("mods/bworld", `${dir}/bworld`);
|
||||
const write = (path: string, json: unknown) => {
|
||||
Deno.mkdirSync(`${dir}/kiln/${path.split("/").slice(0, -1).join("/")}`, { recursive: true });
|
||||
Deno.writeTextFileSync(`${dir}/kiln/${path}`, JSON.stringify(json));
|
||||
};
|
||||
write("manifest.json", {
|
||||
format_version: 1,
|
||||
id: "kiln",
|
||||
name: "Kiln",
|
||||
version: "1.0.0",
|
||||
dependencies: [{ id: "bworld", version: "*" }],
|
||||
});
|
||||
for (const [name, recipe] of Object.entries(recipes)) write(`recipes/${name}.json`, { format_version: 1, recipe });
|
||||
return dir;
|
||||
}
|
||||
import { recipes_mod, test_game } from "./helpers.ts";
|
||||
|
||||
Deno.test("a later fuel recipe for an item changes how long it burns, and leaves the rest of the earlier one", async () => {
|
||||
const dir = kiln_mod({ coal: { type: "bworld:fuel", item: ["bworld:coal", "bworld:oak_log"], burn_time: 50 } });
|
||||
const dir = recipes_mod({ coal: { type: "bworld:fuel", item: ["bworld:coal", "bworld:oak_log"], burn_time: 50 } });
|
||||
const { game } = await test_game(dir);
|
||||
Deno.removeSync(dir, { recursive: true });
|
||||
const recipes = recipe_lookup(() => game.recipes);
|
||||
@@ -37,7 +18,7 @@ Deno.test("a later fuel recipe for an item changes how long it burns, and leaves
|
||||
});
|
||||
|
||||
Deno.test("two smelting recipes for one item stop the mod loading", async () => {
|
||||
const dir = kiln_mod({
|
||||
const dir = recipes_mod({
|
||||
iron: {
|
||||
type: "bworld:smelting",
|
||||
input: "bworld:iron_ore",
|
||||
|
||||
@@ -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