51 lines
2.1 KiB
TypeScript
51 lines
2.1 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// 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;
|
|
}
|
|
|
|
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 { game } = await test_game(dir);
|
|
Deno.removeSync(dir, { recursive: true });
|
|
const recipes = recipe_lookup(() => game.recipes);
|
|
const burn_time = (id: string) => recipes.find<{ burn_time: number }>("bworld:fuel", id)?.burn_time;
|
|
assertEquals(burn_time("bworld:coal"), 50);
|
|
assertEquals(burn_time("bworld:oak_log"), 50);
|
|
assertEquals(burn_time("bworld:spruce_log"), 100);
|
|
});
|
|
|
|
Deno.test("two smelting recipes for one item stop the mod loading", async () => {
|
|
const dir = kiln_mod({
|
|
iron: {
|
|
type: "bworld:smelting",
|
|
input: "bworld:iron_ore",
|
|
output: { id: "bworld:stone", count: 1 },
|
|
cook_time: 10,
|
|
},
|
|
});
|
|
await assertRejects(() => test_game(dir), Error, "there's already one for bworld:iron_ore");
|
|
Deno.removeSync(dir, { recursive: true });
|
|
});
|