Juice sell price

This commit is contained in:
2026-10-26 19:32:46 -03:00
parent e729b92d20
commit e5221ba681
17 changed files with 182 additions and 47 deletions
+25 -5
View File
@@ -1,18 +1,20 @@
// SPDX-FileCopyrightText: 2026 Paula Wisnievski
// SPDX-License-Identifier: AGPL-3.0-or-later
// items that hold one fluid, full or empty: how many stack, what they look like, and turning the held one into another
// items that hold one fluid, full or empty: how many stack, what they look like, what they sell for, and turning the
// held one into another
import { assertEquals } from "@std/assert";
import { item_tooltip } from "$/client/gui/tooltip.ts";
import { item_layers } from "$/client/rendering/item_renderer.ts";
import { ItemStack } from "$/common/inventory.ts";
import { ItemStack, sell_value } from "$/common/inventory.ts";
import { copy_dir, test_game } from "./helpers.ts";
const JAR = "testjars:jar";
const FLASK = "testjars:flask";
const FULL = { fluid: { id: "testjars:syrup", data: { tree: "maple" } } };
// mods/bworld, and testjars: syrup, and a jar of 250 mB that stacks to 16 empty and 4 full, drawn with the syrup in it
// and a red label
// mods/bworld, and testjars: syrup worth 10 a bucket, a jar of 250 mB that stacks to 16 empty and 4 full, drawn with
// the syrup in it and a red label, and a flask of 1000 mB worth 2 on its own
async function setup() {
const dir = Deno.makeTempDirSync({ prefix: "bworld_jars_" });
copy_dir("mods/bworld", `${dir}/bworld`);
@@ -21,7 +23,10 @@ async function setup() {
Deno.writeTextFileSync(`${dir}/testjars/${path}`, JSON.stringify(json));
};
write("manifest.json", { format_version: 1, id: "testjars", name: "Test Jars", version: "1.0.0" });
write("fluids/syrup.json", { format_version: 1, fluid: { id: "testjars:syrup", color: "#a0522d" } });
write("fluids/syrup.json", {
format_version: 1,
fluid: { id: "testjars:syrup", color: "#a0522d", base_sell_value: 10 },
});
write("items/jar.json", {
format_version: 1,
item: {
@@ -32,6 +37,10 @@ async function setup() {
layers: [{ texture: "engine:break_0", tint: "fluid" }, { texture: "engine:break_1", tint: "#ff0000" }],
},
});
write("items/flask.json", {
format_version: 1,
item: { id: FLASK, texture: "engine:missing", base_sell_value: 2, fluid_container: { capacity: 1000 } },
});
const t = await test_game(dir);
Deno.removeSync(dir, { recursive: true });
t.join(1, "alice");
@@ -65,6 +74,17 @@ Deno.test("a layer tinted fluid is drawn in the fluid's color while there's one,
assertEquals(jar(FULL), [{ texture: "engine:break_0", color: [0xa0 / 255, 0x52 / 255, 0x2d / 255] }, red]);
});
Deno.test("a full fluid container sells for its own value and its fluid's, rounded up", async () => {
const t = await setup();
const value = (id: string, data?: unknown) => sell_value(id, data, t.game.mods.fluid_rules);
// a jar of syrup is 2.5, and a flask of it is the flask's 2 and the syrup's 10
assertEquals([value(JAR), value(JAR, FULL)], [undefined, 3]);
assertEquals([value(FLASK), value(FLASK, FULL)], [2, 12]);
const jar = new ItemStack(JAR);
jar.data = FULL;
assertEquals(item_tooltip(jar).map((line) => line.text), ["Jar", "Syrup, 250 mB", "3"]);
});
Deno.test("exchange_held puts the result in the hand from a stack of one, and in the inventory from more", async () => {
const t = await setup();
t.api.give_item(JAR, 3);