Allow tailor dyes on wizard robes, tinting cloth channel only.
Wizard pieces are dyeable at the bench; dual-tint art keeps leather on red and applies instance dye colour to the blue cloth channel on equip and icons.
@@ -27,7 +27,7 @@ export async function paintCharacterPreview (canvas, {
27
27
if (!url)
28
28
{ continue; }
29
29
const img = await loadHtmlImage(url);
30
images.push({ img, tint: layer.tint ?? null });
30
images.push({ img, tint: layer.tint ?? null, dualTint: layer.dualTint ?? null });
31
31
}
32
32
if (!images.length)
33
33
{ return; }
@@ -50,7 +50,9 @@ export async function paintCharacterPreview (canvas, {
50
50
const pivotY = maxH - PIVOT_FROM_BOTTOM_PX;
51
51
for (const entry of images)
52
52
{
53
const source = entry.tint ? tintedCanvas(entry.img, entry.tint) : entry.img;
53
const source = entry.dualTint
54
? dualTintedCanvas(entry.img, entry.dualTint)
55
: (entry.tint ? tintedCanvas(entry.img, entry.tint) : entry.img);
54
56
const sw = source.naturalWidth || source.width || 1;
55
57
const sh = source.naturalHeight || source.height || 1;
56
58
const ox = (pivotX - sw * 0.5) * scale;
@@ -83,7 +85,7 @@ export function paintAppearanceSnapshot (canvas, layers, {
83
85
const entry = resolveImage?.(name);
84
86
if (!entry)
85
87
{ continue; }
86
draws.push({ entry, tint: layer.tint ?? null, frame });
88
draws.push({ entry, tint: layer.tint ?? null, dualTint: layer.dualTint ?? null, frame });
87
89
}
88
90
return paintDrawListSnapshot(canvas, draws, { size });
89
91
}
@@ -143,7 +145,7 @@ export async function paintLayersFromUrls (canvas, layers, {
143
145
try
144
146
{
145
147
const img = await loadHtmlImage(url);
146
draws.push({ entry: img, tint: layer.tint ?? null, frame: 0 });
148
draws.push({ entry: img, tint: layer.tint ?? null, dualTint: layer.dualTint ?? null, frame: 0 });
147
149
}
148
150
catch
149
151
{ /* skip missing art */ }
@@ -239,6 +241,20 @@ function loadHtmlImage (url)
239
241
});
240
242
}
241
243
244
function dualTintedCanvas (sourceImg, dualTint)
245
{
246
const canvas = document.createElement("canvas");
247
canvas.width = sourceImg.naturalWidth || sourceImg.width;
248
canvas.height = sourceImg.naturalHeight || sourceImg.height;
249
const ctx = canvas.getContext("2d");
250
ctx.imageSmoothingEnabled = false;
251
ctx.drawImage(sourceImg, 0, 0);
252
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
253
applyDualChannelTintToImageData(imageData, dualTint);
254
ctx.putImageData(imageData, 0, 0);
255
return canvas;
256
}
257
242
258
function tintedCanvas (sourceImg, tintRgb)
243
259
{
244
260
const canvas = document.createElement("canvas");
@@ -27,7 +27,7 @@ export async function paintCharacterPreview (canvas, {27
if (!url)27
if (!url)28
{ continue; }28
{ continue; }29
const img = await loadHtmlImage(url);29
const img = await loadHtmlImage(url);30
images.push({ img, tint: layer.tint ?? null });30
images.push({ img, tint: layer.tint ?? null, dualTint: layer.dualTint ?? null });31
}31
}32
if (!images.length)32
if (!images.length)33
{ return; }33
{ return; }@@ -50,7 +50,9 @@ export async function paintCharacterPreview (canvas, {50
const pivotY = maxH - PIVOT_FROM_BOTTOM_PX;50
const pivotY = maxH - PIVOT_FROM_BOTTOM_PX;51
for (const entry of images)51
for (const entry of images)52
{52
{53
const source = entry.tint ? tintedCanvas(entry.img, entry.tint) : entry.img;53
const source = entry.dualTint54
? dualTintedCanvas(entry.img, entry.dualTint)55
: (entry.tint ? tintedCanvas(entry.img, entry.tint) : entry.img);54
const sw = source.naturalWidth || source.width || 1;56
const sw = source.naturalWidth || source.width || 1;55
const sh = source.naturalHeight || source.height || 1;57
const sh = source.naturalHeight || source.height || 1;56
const ox = (pivotX - sw * 0.5) * scale;58
const ox = (pivotX - sw * 0.5) * scale;@@ -83,7 +85,7 @@ export function paintAppearanceSnapshot (canvas, layers, {83
const entry = resolveImage?.(name);85
const entry = resolveImage?.(name);84
if (!entry)86
if (!entry)85
{ continue; }87
{ continue; }86
draws.push({ entry, tint: layer.tint ?? null, frame });88
draws.push({ entry, tint: layer.tint ?? null, dualTint: layer.dualTint ?? null, frame });87
}89
}88
return paintDrawListSnapshot(canvas, draws, { size });90
return paintDrawListSnapshot(canvas, draws, { size });89
}91
}@@ -143,7 +145,7 @@ export async function paintLayersFromUrls (canvas, layers, {143
try145
try144
{146
{145
const img = await loadHtmlImage(url);147
const img = await loadHtmlImage(url);146
draws.push({ entry: img, tint: layer.tint ?? null, frame: 0 });148
draws.push({ entry: img, tint: layer.tint ?? null, dualTint: layer.dualTint ?? null, frame: 0 });147
}149
}148
catch150
catch149
{ /* skip missing art */ }151
{ /* skip missing art */ }@@ -239,6 +241,20 @@ function loadHtmlImage (url)239
});241
});240
}242
}241
243
244
function dualTintedCanvas (sourceImg, dualTint)245
{246
const canvas = document.createElement("canvas");247
canvas.width = sourceImg.naturalWidth || sourceImg.width;248
canvas.height = sourceImg.naturalHeight || sourceImg.height;249
const ctx = canvas.getContext("2d");250
ctx.imageSmoothingEnabled = false;251
ctx.drawImage(sourceImg, 0, 0);252
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);253
applyDualChannelTintToImageData(imageData, dualTint);254
ctx.putImageData(imageData, 0, 0);255
return canvas;256
}257
242
function tintedCanvas (sourceImg, tintRgb)258
function tintedCanvas (sourceImg, tintRgb)243
{259
{244
const canvas = document.createElement("canvas");260
const canvas = document.createElement("canvas");@@ -2473,9 +2473,17 @@ export class WorldView
2473
2473
entity.overlays.push(object);
2474
2474
const layerDef = layer.itemId != null ? itemDefinition(layer.itemId) : null;
2475
2475
entity.overlayTightFit.push(!!layerDef?.tightFit);
2476
const dualTint = layer.itemId != null
2477
? resolveEquipDualTint({ itemId: layer.itemId }, layerDef)
2478
: null;
2476
const dualTint = layer.dualTint
2477
? {
2478
shaft: normalizeRgb(layer.dualTint.shaft),
2479
tip: normalizeRgb(layer.dualTint.tip),
2480
...(layer.dualTint.coat
2481
? { coat: normalizeRgb(layer.dualTint.coat) }
2482
: {})
2483
}
2484
: (layer.itemId != null
2485
? resolveEquipDualTint({ itemId: layer.itemId }, layerDef)
2486
: null);
2479
2487
entity.overlayDualTints.push(dualTint);
2480
2488
entity.overlayTints.push(
2481
2489
dualTint
@@ -2473,9 +2473,17 @@ export class WorldView2473
entity.overlays.push(object);2473
entity.overlays.push(object);2474
const layerDef = layer.itemId != null ? itemDefinition(layer.itemId) : null;2474
const layerDef = layer.itemId != null ? itemDefinition(layer.itemId) : null;2475
entity.overlayTightFit.push(!!layerDef?.tightFit);2475
entity.overlayTightFit.push(!!layerDef?.tightFit);2476
const dualTint = layer.itemId != null2476
const dualTint = layer.dualTint2477
? resolveEquipDualTint({ itemId: layer.itemId }, layerDef)2477
? {2478
: null;2478
shaft: normalizeRgb(layer.dualTint.shaft),2479
tip: normalizeRgb(layer.dualTint.tip),2480
...(layer.dualTint.coat2481
? { coat: normalizeRgb(layer.dualTint.coat) }2482
: {})2483
}2484
: (layer.itemId != null2485
? resolveEquipDualTint({ itemId: layer.itemId }, layerDef)2486
: null);2479
entity.overlayDualTints.push(dualTint);2487
entity.overlayDualTints.push(dualTint);2480
entity.overlayTints.push(2488
entity.overlayTints.push(2481
dualTint2489
dualTint@@ -542,4 +542,16 @@ test("tailor wizard robe recipes resolve cloth and leather inputs", () =>
542
542
assert.equal(bottoms.ok, true);
543
543
assert.equal(bottoms.recipe.output.itemId, WizardItemId.cottonRobeBottoms);
544
544
assert.deepEqual(bottoms.recipe.inputs, [{ itemId: ClothItemId.cottonCloth, quantity: 4 }]);
545
const dyed = resolveTailorCraft({
546
templateId: "wizard-hat",
547
clothTier: "cotton",
548
dyeStack: {
549
itemId: ItemId.dye,
550
instance: { kind: "dye", color: { r: 0.2, g: 0.5, b: 0.9 }, fillLevel: 5 }
551
}
552
});
553
assert.equal(dyed.ok, true);
554
assert.equal(dyed.recipe.consumeDye, true);
555
assert.deepEqual(dyed.recipe.dyeColor, { r: 0.2, g: 0.5, b: 0.9 });
556
assert.equal(dyed.recipe.output.itemId, WizardItemId.cottonHat);
545
557
});
@@ -542,4 +542,16 @@ test("tailor wizard robe recipes resolve cloth and leather inputs", () =>542
assert.equal(bottoms.ok, true);542
assert.equal(bottoms.ok, true);543
assert.equal(bottoms.recipe.output.itemId, WizardItemId.cottonRobeBottoms);543
assert.equal(bottoms.recipe.output.itemId, WizardItemId.cottonRobeBottoms);544
assert.deepEqual(bottoms.recipe.inputs, [{ itemId: ClothItemId.cottonCloth, quantity: 4 }]);544
assert.deepEqual(bottoms.recipe.inputs, [{ itemId: ClothItemId.cottonCloth, quantity: 4 }]);545
const dyed = resolveTailorCraft({546
templateId: "wizard-hat",547
clothTier: "cotton",548
dyeStack: {549
itemId: ItemId.dye,550
instance: { kind: "dye", color: { r: 0.2, g: 0.5, b: 0.9 }, fillLevel: 5 }551
}552
});553
assert.equal(dyed.ok, true);554
assert.equal(dyed.recipe.consumeDye, true);555
assert.deepEqual(dyed.recipe.dyeColor, { r: 0.2, g: 0.5, b: 0.9 });556
assert.equal(dyed.recipe.output.itemId, WizardItemId.cottonHat);545
});557
});@@ -15,6 +15,9 @@ import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } fr
15
15
import { ItemId } from "../../shared/definitions/items.js";
16
16
import { RangedItemId } from "../../shared/definitions/rangedItems.js";
17
17
import { GemItemId } from "../../shared/definitions/gemItems.js";
18
import { WizardItemId } from "../../shared/definitions/wizardItems.js";
19
import { LeatherTier } from "../../shared/definitions/materialTiers.js";
20
import { normalizeRgb } from "../../shared/render/tint.js";
18
21
19
22
test("magenta tintable when R==B and G < R", () =>
20
23
{
@@ -154,3 +157,24 @@ test("material tint hex converts to 0-1 rgb at load", () =>
154
157
assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.mithril], rgb(3, 120, 255));
155
158
assert.deepEqual(hexToRgb01("rgb(3, 120, 255)"), rgb(3, 120, 255));
156
159
});
160
161
test("wizard robe dye tints cloth channel only on dual-tint pieces", () =>
162
{
163
const dye = { r: 0.85, g: 0.15, b: 0.35 };
164
const stack = {
165
itemId: WizardItemId.cottonHat,
166
instance: { kind: "clothing", dyeColor: dye }
167
};
168
const dual = resolveItemDualTint(stack);
169
assert.deepEqual(dual.shaft, tierTintColor(LeatherTier.softLeather));
170
assert.deepEqual(dual.tip, normalizeRgb(dye));
171
assert.equal(resolveEquipTint(WizardItemId.cottonHat, stack.instance), null);
172
assert.equal(resolveItemTint(stack), null);
173
174
const bottoms = {
175
itemId: WizardItemId.cottonRobeBottoms,
176
instance: { kind: "clothing", dyeColor: dye }
177
};
178
assert.deepEqual(resolveEquipTint(WizardItemId.cottonRobeBottoms, bottoms.instance), normalizeRgb(dye));
179
assert.equal(resolveEquipDualTint(bottoms), null);
180
});
@@ -15,6 +15,9 @@ import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } fr15
import { ItemId } from "../../shared/definitions/items.js";15
import { ItemId } from "../../shared/definitions/items.js";16
import { RangedItemId } from "../../shared/definitions/rangedItems.js";16
import { RangedItemId } from "../../shared/definitions/rangedItems.js";17
import { GemItemId } from "../../shared/definitions/gemItems.js";17
import { GemItemId } from "../../shared/definitions/gemItems.js";18
import { WizardItemId } from "../../shared/definitions/wizardItems.js";19
import { LeatherTier } from "../../shared/definitions/materialTiers.js";20
import { normalizeRgb } from "../../shared/render/tint.js";18
21
19
test("magenta tintable when R==B and G < R", () =>22
test("magenta tintable when R==B and G < R", () =>20
{23
{@@ -154,3 +157,24 @@ test("material tint hex converts to 0-1 rgb at load", () =>154
assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.mithril], rgb(3, 120, 255));157
assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.mithril], rgb(3, 120, 255));155
assert.deepEqual(hexToRgb01("rgb(3, 120, 255)"), rgb(3, 120, 255));158
assert.deepEqual(hexToRgb01("rgb(3, 120, 255)"), rgb(3, 120, 255));156
});159
});160
161
test("wizard robe dye tints cloth channel only on dual-tint pieces", () =>162
{163
const dye = { r: 0.85, g: 0.15, b: 0.35 };164
const stack = {165
itemId: WizardItemId.cottonHat,166
instance: { kind: "clothing", dyeColor: dye }167
};168
const dual = resolveItemDualTint(stack);169
assert.deepEqual(dual.shaft, tierTintColor(LeatherTier.softLeather));170
assert.deepEqual(dual.tip, normalizeRgb(dye));171
assert.equal(resolveEquipTint(WizardItemId.cottonHat, stack.instance), null);172
assert.equal(resolveItemTint(stack), null);173
174
const bottoms = {175
itemId: WizardItemId.cottonRobeBottoms,176
instance: { kind: "clothing", dyeColor: dye }177
};178
assert.deepEqual(resolveEquipTint(WizardItemId.cottonRobeBottoms, bottoms.instance), normalizeRgb(dye));179
assert.equal(resolveEquipDualTint(bottoms), null);180
});