Fluid handler
This commit is contained in:
@@ -5,14 +5,12 @@
|
||||
// an empty hand takes the items out
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { ItemStack } from "$/common/inventory.ts";
|
||||
import type { ItemStack as Stack } from "bworld/shared";
|
||||
import type { FluidStack, ItemStack as Stack } from "bworld/shared";
|
||||
import {
|
||||
apply_basin_recipe,
|
||||
BASIN_SLOTS,
|
||||
BASIN_TANK_CAPACITY,
|
||||
BASIN_TANKS,
|
||||
type BasinTank,
|
||||
drain,
|
||||
fill,
|
||||
insert_item,
|
||||
} from "$/mods/create/scripts/processing/basin.ts";
|
||||
@@ -40,9 +38,9 @@ Deno.test("a basin keeps one stack of each kind of item, and only so many kinds"
|
||||
assertEquals(insert_item(full, { id: "a:another", count: 1 }, 64).inserted, 0);
|
||||
});
|
||||
|
||||
Deno.test("a basin keeps each fluid in a tank of its own, and drains the first", () => {
|
||||
Deno.test("a basin recipe's fluids each go in a tank of their own", () => {
|
||||
const half = BASIN_TANK_CAPACITY / 2;
|
||||
let tanks: BasinTank[] = fill([], juice("apple"), half, same)!;
|
||||
let tanks: FluidStack[] = fill([], juice("apple"), half, same)!;
|
||||
tanks = fill(tanks, juice("apple"), half, same)!;
|
||||
assertEquals(tanks, [{ fluid: juice("apple"), amount: BASIN_TANK_CAPACITY }]);
|
||||
// it doesn't overflow into another tank
|
||||
@@ -50,11 +48,6 @@ Deno.test("a basin keeps each fluid in a tank of its own, and drains the first",
|
||||
for (let i = 1; i < BASIN_TANKS; i++) tanks = fill(tanks, juice(`fruit_${i}`), half, same)!;
|
||||
assertEquals(tanks.length, BASIN_TANKS);
|
||||
assertEquals(fill(tanks, juice("another"), 1, same), undefined);
|
||||
|
||||
assertEquals(drain(tanks, BASIN_TANK_CAPACITY + 1), undefined);
|
||||
const drained = drain(tanks, BASIN_TANK_CAPACITY)!;
|
||||
assertEquals(drained.fluid, juice("apple"));
|
||||
assertEquals(drained.tanks.length, BASIN_TANKS - 1);
|
||||
});
|
||||
|
||||
Deno.test("a basin recipe takes an item for each ingredient, and puts what it makes where recipes don't take it", () => {
|
||||
@@ -91,7 +84,7 @@ async function basin() {
|
||||
const items = () =>
|
||||
(t.game.world.get_tile(0, 100, 0)?.client_data?.items as { id: string; count: number }[] | undefined ?? [])
|
||||
.map(({ id, count }) => [id, count]);
|
||||
const tanks = () => t.game.world.get_tile(0, 100, 0)?.client_data?.tanks as BasinTank[] | undefined ?? [];
|
||||
const tanks = () => t.game.world.get_tile(0, 100, 0)?.client_data?.tanks as FluidStack[] | undefined ?? [];
|
||||
const player = t.game.mods.player(t.game.players()[0]);
|
||||
const hold = (item: { id: string; count: number; data?: unknown } | undefined) => {
|
||||
player.inventory.set(0, item);
|
||||
|
||||
Reference in New Issue
Block a user