| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { |
| 4 | isMagentaTintable, |
| 5 | magentaTintedRgb, |
| 6 | tierTintColor, |
| 7 | resolveItemTint |
| 8 | } from "../../shared/render/tint.js"; |
| 9 | import { MaterialTier, GatherMaterialId } from "../../shared/definitions/materialTiers.js"; |
| 10 | import { ItemId } from "../../shared/definitions/items.js"; |
| 11 | |
| 12 | test("magenta tintable when R==B and G < R", () => |
| 13 | { |
| 14 | assert.equal(isMagentaTintable(1, 0, 1), true); |
| 15 | assert.equal(isMagentaTintable(50 / 255, 0, 50 / 255), true); |
| 16 | assert.equal(isMagentaTintable(120 / 255, 50 / 255, 120 / 255), true); |
| 17 | assert.equal(isMagentaTintable(200 / 255, 100 / 255, 50 / 255), false); |
| 18 | assert.equal(isMagentaTintable(0.5, 0.5, 0.5), false); |
| 19 | }); |
| 20 | |
| 21 | test("magenta tint preserves lightness and desaturates with G", () => |
| 22 | { |
| 23 | const tint = { r: 0, g: 1, b: 0 }; |
| 24 | const dark = magentaTintedRgb(50 / 255, 0, 50 / 255, tint); |
| 25 | const light = magentaTintedRgb(1, 0, 1, tint); |
| 26 | assert.ok(dark.g < light.g); |
| 27 | const desat = magentaTintedRgb(120 / 255, 50 / 255, 120 / 255, tint); |
| 28 | const pure = magentaTintedRgb(120 / 255, 0, 120 / 255, tint); |
| 29 | assert.ok(desat.r > pure.r); |
| 30 | }); |
| 31 | |
| 32 | test("resolveItemTint uses potion instance color and tier tints", () => |
| 33 | { |
| 34 | const potionTint = resolveItemTint({ |
| 35 | itemId: ItemId.potion, |
| 36 | instance: { kind: "potion", color: { r: 0.25, g: 0.72, b: 0.35 } } |
| 37 | }); |
| 38 | assert.equal(potionTint.g, 0.72); |
| 39 | const bronze = tierTintColor(MaterialTier.bronze); |
| 40 | assert.ok(bronze.r > bronze.b); |
| 41 | const barTint = resolveItemTint({ itemId: ItemId.bronzeBar }); |
| 42 | assert.deepEqual(barTint, bronze); |
| 43 | const copper = tierTintColor(GatherMaterialId.copper); |
| 44 | assert.deepEqual(resolveItemTint({ itemId: ItemId.copperOre }), copper); |
| 45 | }); |