import test from "node:test"; import assert from "node:assert/strict"; import { isMagentaTintable, magentaTintedRgb, tierTintColor, resolveItemTint } from "../../shared/render/tint.js"; import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } from "../../shared/definitions/materialTiers.js"; import { ItemId } from "../../shared/definitions/items.js"; test("magenta tintable when R==B and G < R", () => { assert.equal(isMagentaTintable(1, 0, 1), true); assert.equal(isMagentaTintable(50 / 255, 0, 50 / 255), true); assert.equal(isMagentaTintable(120 / 255, 50 / 255, 120 / 255), true); // Near-magenta drift (R = B ± 2) from AA / export — still tintable. assert.equal(isMagentaTintable(173 / 255, 67 / 255, 171 / 255), true); assert.equal(isMagentaTintable(87 / 255, 60 / 255, 85 / 255), true); assert.equal(isMagentaTintable(200 / 255, 100 / 255, 50 / 255), false); assert.equal(isMagentaTintable(0.5, 0.5, 0.5), false); }); test("magenta tint preserves lightness and desaturates with G", () => { const tint = { r: 0, g: 1, b: 0 }; const dark = magentaTintedRgb(50 / 255, 0, 50 / 255, tint); const light = magentaTintedRgb(1, 0, 1, tint); assert.ok(dark.g < light.g); const desat = magentaTintedRgb(120 / 255, 50 / 255, 120 / 255, tint); const pure = magentaTintedRgb(120 / 255, 0, 120 / 255, tint); assert.ok(desat.r > pure.r); }); test("dark target tints stay dark even on high-G magenta highlights", () => { const coal = { r: 23 / 255, g: 23 / 255, b: 24 / 255 }; const pure = magentaTintedRgb(1, 0, 1, coal); const highlight = magentaTintedRgb(1, 179 / 255, 1, coal); assert.ok(pure.r < 0.12); assert.ok(highlight.r < 0.15, `highlight washed out: ${highlight.r}`); assert.ok(Math.abs(highlight.r - pure.r) < 0.05); }); test("resolveItemTint uses potion instance color and tier tints", () => { const potionTint = resolveItemTint({ itemId: ItemId.potion, instance: { kind: "potion", color: { r: 0.25, g: 0.72, b: 0.35 } } }); assert.equal(potionTint.g, 0.72); const bronze = tierTintColor(MaterialTier.bronze); assert.ok(bronze.r > bronze.b); const barTint = resolveItemTint({ itemId: ItemId.bronzeBar }); assert.deepEqual(barTint, bronze); const copper = tierTintColor(GatherMaterialId.copper); const copperOre = tierTintColor(GatherMaterialId.copper, { ore: true }); assert.notDeepEqual(copperOre, copper); assert.deepEqual(resolveItemTint({ itemId: ItemId.copperOre }), copperOre); const iron = tierTintColor(MaterialTier.iron); const ironOre = tierTintColor(MaterialTier.iron, { ore: true }); assert.notDeepEqual(ironOre, iron); assert.deepEqual(resolveItemTint({ itemId: ItemId.ironOre }), ironOre); assert.deepEqual(resolveItemTint({ itemId: ItemId.ironBar }), iron); }); test("material tint hex converts to 0-1 rgb at load", () => { assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.bronze], rgb(184, 122, 71)); assert.deepEqual(hexToRgb01(0xB87A47), { r: 184 / 255, g: 122 / 255, b: 71 / 255 }); assert.deepEqual(hexToRgb01("#B87A47"), hexToRgb01(0xB87A47)); assert.deepEqual(hexToRgb01("#abc"), hexToRgb01("#AABBCC")); assert.deepEqual(tierTintColor(MaterialTier.bronze), rgb(184, 122, 71)); assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.mithril], rgb(3, 120, 255)); assert.deepEqual(hexToRgb01("rgb(3, 120, 255)"), rgb(3, 120, 255)); });