76 lines
3.7 KiB
TypeScript
76 lines
3.7 KiB
TypeScript
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
// create's recipe types: read and checked when the server starts, and shown by the recipe viewer
|
|
import { assert, assertEquals, assertThrows } from "@std/assert";
|
|
import { EverythingRegistry } from "$/common/everything_registry.ts";
|
|
import { tag_api } from "$/common/tags.ts";
|
|
import type { ClientContext } from "$/common/mod_api/client.ts";
|
|
import { parse_processing, PRESSING, processing_recipes } from "$/mods/create/scripts/recipes/processing.ts";
|
|
import { inputs, outputs } from "$/mods/recipe_viewer/scripts/recipes.ts";
|
|
import { RecipeIndex } from "$/mods/recipe_viewer/scripts/recipes_screen.ts";
|
|
import { test_game } from "../helpers.ts";
|
|
|
|
const lookup = () => ({
|
|
expand: (choice: string | string[]) => tag_api().expand(choice),
|
|
item_exists: (id: string) => EverythingRegistry.get("items", id) !== undefined,
|
|
});
|
|
|
|
Deno.test("create's pressing recipes are read with every item each ingredient stands for", async () => {
|
|
const { game } = await test_game("mods");
|
|
const recipes = processing_recipes(game.recipes.by_type.get(PRESSING.id) ?? [], PRESSING, lookup());
|
|
const sheet = recipes.find((recipe) => recipe.results[0].id === "create:iron_sheet");
|
|
assert(sheet, "iron is pressed into sheets");
|
|
assert(sheet.ingredients[0].includes("bworld:iron_ingot"));
|
|
assertEquals(sheet.results, [{ id: "create:iron_sheet", count: 1, chance: 1 }]);
|
|
});
|
|
|
|
Deno.test("a pressing recipe that a press couldn't make says what's wrong with it", async () => {
|
|
await test_game("mods");
|
|
const problems = (json: unknown) => {
|
|
const parsed = parse_processing(json, PRESSING, lookup());
|
|
return "problems" in parsed ? parsed.problems : [];
|
|
};
|
|
const sheet = { id: "create:iron_sheet" };
|
|
assertEquals(problems({ ingredients: ["bworld:iron_ingot"], results: [sheet] }), []);
|
|
// a press takes one item, and makes up to two
|
|
assertEquals(problems({ ingredients: ["bworld:iron_ingot", "bworld:gold_ingot"], results: [sheet] }).length, 1);
|
|
assertEquals(problems({ ingredients: ["bworld:iron_ingot"], results: [sheet, sheet, sheet] }).length, 1);
|
|
assertEquals(problems({ ingredients: ["bworld:no_such_ingot"], results: [sheet] }).length, 1);
|
|
assertEquals(
|
|
problems({ ingredients: ["bworld:iron_ingot"], results: [{ id: "create:iron_sheet", chance: 2 }] }).length,
|
|
1,
|
|
);
|
|
assertEquals(problems({ ingredients: ["bworld:iron_ingot"], results: [sheet], processing_time: 100 }).length, 1);
|
|
assertEquals(problems({ results: [sheet] }).length, 1);
|
|
|
|
// the server doesn't start with one, and says which
|
|
assertThrows(
|
|
() => processing_recipes([{ ingredients: ["bworld:no_such_ingot"], results: [sheet] }], PRESSING, lookup()),
|
|
Error,
|
|
"bworld:no_such_ingot",
|
|
);
|
|
});
|
|
|
|
Deno.test("the recipe viewer shows pressing recipes under the press, with what they take and make", async () => {
|
|
const { game } = await test_game("mods");
|
|
const pressing = game.recipes.all.filter((recipe) => recipe.type === PRESSING.id);
|
|
const sheet = pressing.find((recipe) => outputs(recipe)[0]?.ids[0] === "create:iron_sheet");
|
|
assert(sheet);
|
|
assert(inputs(sheet, tag_api())[0].ids.includes("bworld:iron_ingot"));
|
|
|
|
const ctx = {
|
|
recipes: { list: () => game.recipes.all },
|
|
tags: tag_api(),
|
|
items: {
|
|
exists: (id: string) => EverythingRegistry.get("items", id) !== undefined,
|
|
ids: () => EverythingRegistry.entries("items").map(([id]) => id),
|
|
components: () => ({}),
|
|
},
|
|
blocks: { exists: () => false, components: () => ({}) },
|
|
loot: { table: () => undefined },
|
|
} as unknown as ClientContext;
|
|
const category = new RecipeIndex(ctx).categories.find((category) => category.type === PRESSING.id);
|
|
assertEquals([category?.title, category?.catalysts], ["Pressing", ["create:mechanical_press"]]);
|
|
});
|