| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { ItemId } from "../../shared/definitions/items.js"; |
| 4 | import { dyeColorKey } from "../../shared/definitions/dyes.js"; |
| 5 | import { emptySlots } from "../../shared/items/inventory.js"; |
| 6 | import { canCraftFitInventory } from "../../shared/crafting/recipes.js"; |
| 7 | import { |
| 8 | listDyePickerChoices, |
| 9 | pickEmptiestDyeSlot |
| 10 | } from "../../shared/crafting/dye.js"; |
| 11 | import { sweaterItemId } from "../../shared/definitions/clothItems.js"; |
| 12 | import { ClothTier } from "../../shared/definitions/materialTiers.js"; |
| 13 | import { yarnItemId } from "../../shared/definitions/clothItems.js"; |
| 14 | |
| 15 | const red = { r: 0.9, g: 0.1, b: 0.1 }; |
| 16 | |
| 17 | function dyeStack (color, fillLevel, quantity = 1) |
| 18 | { |
| 19 | return { |
| 20 | itemId: ItemId.dye, |
| 21 | quantity, |
| 22 | instance: { kind: "dye", color, fillLevel } |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | test("dye picker shows one fullest bottle per colour", () => |
| 27 | { |
| 28 | const slots = emptySlots(); |
| 29 | slots[0] = dyeStack(red, 1); |
| 30 | slots[1] = dyeStack(red, 4); |
| 31 | slots[2] = dyeStack({ r: 0.1, g: 0.2, b: 0.9 }, 3); |
| 32 | const choices = listDyePickerChoices(slots); |
| 33 | assert.equal(choices.length, 2); |
| 34 | const redChoice = choices.find((entry) => entry.displayIndex === 1); |
| 35 | assert.ok(redChoice); |
| 36 | assert.equal(redChoice.fill, 4); |
| 37 | }); |
| 38 | |
| 39 | test("tailor crafts consume the emptiest bottle of the chosen colour", () => |
| 40 | { |
| 41 | const slots = emptySlots(); |
| 42 | const yarn = yarnItemId(ClothTier.cotton); |
| 43 | slots[0] = { itemId: yarn, quantity: 3 }; |
| 44 | slots[1] = dyeStack(red, 4); |
| 45 | slots[2] = dyeStack(red, 1); |
| 46 | for (let i = 3; i < slots.length; i++) |
| 47 | { slots[i] = { itemId: ItemId.apple, quantity: 1 }; } |
| 48 | const colorKey = dyeColorKey({ kind: "dye", color: red, fillLevel: 4 }); |
| 49 | assert.equal(pickEmptiestDyeSlot(slots, colorKey), 2); |
| 50 | const recipe = { |
| 51 | output: { itemId: sweaterItemId(ClothTier.cotton), quantity: 1 }, |
| 52 | inputs: [{ itemId: yarn, quantity: 3 }], |
| 53 | consumeDye: true, |
| 54 | dyeColor: red |
| 55 | }; |
| 56 | assert.equal(canCraftFitInventory(slots, recipe, { dyeColorKey: colorKey }), true); |
| 57 | }); |