import test from "node:test"; import assert from "node:assert/strict"; import { ItemId } from "../../shared/definitions/items.js"; import { dyeColorKey } from "../../shared/definitions/dyes.js"; import { emptySlots } from "../../shared/items/inventory.js"; import { canCraftFitInventory } from "../../shared/crafting/recipes.js"; import { listDyePickerChoices, pickEmptiestDyeSlot } from "../../shared/crafting/dye.js"; import { sweaterItemId } from "../../shared/definitions/clothItems.js"; import { ClothTier } from "../../shared/definitions/materialTiers.js"; import { yarnItemId } from "../../shared/definitions/clothItems.js"; const red = { r: 0.9, g: 0.1, b: 0.1 }; function dyeStack (color, fillLevel, quantity = 1) { return { itemId: ItemId.dye, quantity, instance: { kind: "dye", color, fillLevel } }; } test("dye picker shows one fullest bottle per colour", () => { const slots = emptySlots(); slots[0] = dyeStack(red, 1); slots[1] = dyeStack(red, 4); slots[2] = dyeStack({ r: 0.1, g: 0.2, b: 0.9 }, 3); const choices = listDyePickerChoices(slots); assert.equal(choices.length, 2); const redChoice = choices.find((entry) => entry.displayIndex === 1); assert.ok(redChoice); assert.equal(redChoice.fill, 4); }); test("tailor crafts consume the emptiest bottle of the chosen colour", () => { const slots = emptySlots(); const yarn = yarnItemId(ClothTier.cotton); slots[0] = { itemId: yarn, quantity: 3 }; slots[1] = dyeStack(red, 4); slots[2] = dyeStack(red, 1); for (let i = 3; i < slots.length; i++) { slots[i] = { itemId: ItemId.apple, quantity: 1 }; } const colorKey = dyeColorKey({ kind: "dye", color: red, fillLevel: 4 }); assert.equal(pickEmptiestDyeSlot(slots, colorKey), 2); const recipe = { output: { itemId: sweaterItemId(ClothTier.cotton), quantity: 1 }, inputs: [{ itemId: yarn, quantity: 3 }], consumeDye: true, dyeColor: red }; assert.equal(canCraftFitInventory(slots, recipe, { dyeColorKey: colorKey }), true); });