Juices on the mechanical press !

This commit is contained in:
2026-10-31 00:03:03 -03:00
parent 3734f5707a
commit 23d02c5229
11 changed files with 381 additions and 62 deletions
+48 -2
View File
@@ -6,7 +6,12 @@ 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 {
COMPACTING,
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";
@@ -14,6 +19,7 @@ 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,
fluid_exists: (id: string) => EverythingRegistry.get("fluids", id) !== undefined,
});
Deno.test("create's pressing recipes are read with every item each ingredient stands for", async () => {
@@ -52,6 +58,31 @@ Deno.test("a pressing recipe that a press couldn't make says what's wrong with i
);
});
Deno.test("compacting recipes can make fluids as well as items, and pressing ones can't", async () => {
await test_game("mods");
const juice = { fluid: { id: "bworld:juice", data: { item: "bworld:carrot" } }, amount: 200 };
const parsed = parse_processing({ ingredients: ["bworld:carrot"], results: [juice] }, COMPACTING, lookup());
assertEquals(parsed, { ingredients: [["bworld:carrot"]], results: [], fluid_results: [juice] });
const problems = (json: unknown, type = COMPACTING) => {
const parsed = parse_processing(json, type, lookup());
return "problems" in parsed ? parsed.problems : [];
};
assertEquals(problems({ ingredients: ["bworld:carrot"], results: [juice] }, PRESSING).length, 1);
assertEquals(problems({ ingredients: ["bworld:carrot"], results: [juice, juice, juice] }).length, 1);
assertEquals(
problems({ ingredients: ["bworld:carrot"], results: [{ ...juice, fluid: { id: "a:none" } }] }).length,
1,
);
assertEquals(problems({ ingredients: ["bworld:carrot"], results: [{ ...juice, amount: 0 }] }).length, 1);
// fluids going in aren't supported yet
assertEquals(
problems({ ingredients: [{ fluid: "bworld:juice", amount: 10 }], results: [{ id: "bworld:carrot" }] }),
[
"fluid ingredients aren't supported yet",
],
);
});
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);
@@ -70,6 +101,21 @@ Deno.test("the recipe viewer shows pressing recipes under the press, with what t
blocks: { exists: () => false, components: () => ({}) },
loot: { table: () => undefined },
} as unknown as ClientContext;
const category = new RecipeIndex(ctx).categories.find((category) => category.type === PRESSING.id);
const index = new RecipeIndex(ctx);
const category = index.categories.find((category) => category.type === PRESSING.id);
assertEquals([category?.title, category?.catalysts], ["Pressing", ["create:mechanical_press"]]);
// juice is made by compacting too, by the press over a basin, and drawn as a fluid
const compacting = index.find({ kind: "fluid", id: "bworld:juice" }, "recipes")
.find((found) => found.category.type === COMPACTING.id)!;
assertEquals(compacting.category.catalysts, ["create:mechanical_press", "create:basin"]);
const fluids: unknown[] = [];
const ignore = () => {};
compacting.category.draw(compacting.recipes[0], {
slot: ignore,
texture: ignore,
text: ignore,
fluid: (fluid) => fluids.push(fluid),
});
assertEquals(fluids.length, 1);
});