Fix tailor recipe-grid previews when switching cloth or dye.
Left-side icons now resolve the selected material (and optional dye) like the detail pane, and refresh on dye pick/clear as well as material change.
@@ -1,6 +1,5 @@
1
1
import
2
2
{
3
itemDefinition,
4
3
itemDisplayName,
5
4
itemAssetPathForStack,
6
5
formatQuantity,
@@ -130,6 +129,7 @@ export function initCrafting ({
130
129
dyeClearBtn?.addEventListener("click", () =>
131
130
{
132
131
clearDyeSelection();
132
renderRecipeGrid();
133
133
renderDetail();
134
134
});
135
135
document.getElementById("dye-picker-close")?.addEventListener("click", () => closeDyePicker());
@@ -269,6 +269,17 @@ export function initCrafting ({
269
269
function activeRecipe ()
270
270
{
271
271
const base = selectedRecipe();
272
if (!base)
273
{ return null; }
274
return resolveRecipePreview(base);
275
}
276
277
/**
278
* Concrete recipe for UI previews (tailor templates → selected cloth + optional dye).
279
* Other stations already carry the material-matched variant in the grid row.
280
*/
281
function resolveRecipePreview (base)
282
{
272
283
if (!base)
273
284
{ return null; }
274
285
if (!base.tailorTemplate)
@@ -283,6 +294,17 @@ export function initCrafting ({
283
294
return resolved.ok ? resolved.recipe : base;
284
295
}
285
296
297
function previewOutputStack (recipe)
298
{
299
if (!recipe?.output?.itemId)
300
{ return null; }
301
return {
302
itemId: recipe.output.itemId,
303
quantity: Math.max(1, recipe.output.quantity | 0 || 1),
304
...(recipe.dyeColor ? { instance: { kind: "clothing", dyeColor: recipe.dyeColor } } : {})
305
};
306
}
307
286
308
function refresh ()
287
309
{
288
310
if (!open)
@@ -432,8 +454,9 @@ export function initCrafting ({
432
454
433
455
function renderRecipeCell ({ group, recipe })
434
456
{
435
const def = itemDefinition(recipe.output.itemId);
436
const stack = { itemId: recipe.output.itemId, quantity: recipe.output.quantity | 0 || 1 };
457
const previewRecipe = resolveRecipePreview(recipe) ?? recipe;
458
const stack = previewOutputStack(previewRecipe)
459
?? { itemId: recipe.output.itemId, quantity: recipe.output.quantity | 0 || 1 };
437
460
const cell = document.createElement("button");
438
461
cell.type = "button";
439
462
cell.className = "craft-recipe-cell";
@@ -444,24 +467,30 @@ export function initCrafting ({
444
467
{ cell.classList.add("selected"); }
445
468
446
469
const skill = stationSkillLevel();
447
const minLevel = recipe.minSkillLevel | 0 || 1;
470
const minLevel = previewRecipe.minSkillLevel | 0 || 1;
448
471
if ((skill | 0) < minLevel)
449
472
{ cell.classList.add("level-locked"); }
450
else if (canStartCraft(getInventorySlots?.() ?? [], recipe, skill, dyeCraftOptions()))
473
else if (canStartCraft(getInventorySlots?.() ?? [], previewRecipe, skill, dyeCraftOptions()))
451
474
{ cell.classList.add("craftable"); }
452
475
453
476
const img = document.createElement("img");
454
img.alt = def?.displayName ?? "Item";
477
img.alt = itemDisplayName(stack);
455
478
applyItemIcon(img, stack, itemAssetPathForStack(stack));
456
479
457
480
const label = document.createElement("span");
458
481
label.className = "craft-recipe-name";
459
482
if (recipe.tailorTemplate)
460
{ label.textContent = def?.displayName?.replace(/^Cotton\s+/i, "") ?? "Garment"; }
483
{
484
const name = itemDisplayName(stack);
485
const clothPrefix = CLOTH_DISPLAY_NAME[previewRecipe.clothTier ?? selectedMaterial];
486
label.textContent = (clothPrefix && name.startsWith(`${clothPrefix} `))
487
? name.slice(clothPrefix.length + 1)
488
: name.replace(/^Cotton\s+/i, "") || name;
489
}
461
490
else if (recipe.craftGroupLabel)
462
491
{ label.textContent = recipe.craftGroupLabel; }
463
492
else
464
{ label.textContent = def?.displayName ?? "Item"; }
493
{ label.textContent = itemDisplayName(stack); }
465
494
466
495
cell.append(img, label);
467
496
cell.addEventListener("click", () =>
@@ -498,10 +527,9 @@ export function initCrafting ({
498
527
detailEmpty.hidden = true;
499
528
detailBody.hidden = false;
500
529
501
const outputStack = {
530
const outputStack = previewOutputStack(recipe) ?? {
502
531
itemId: recipe.output.itemId,
503
quantity: Math.max(1, recipe.output.quantity | 0 || 1),
504
...(recipe.dyeColor ? { instance: { kind: "clothing", dyeColor: recipe.dyeColor } } : {})
532
quantity: Math.max(1, recipe.output.quantity | 0 || 1)
505
533
};
506
534
applyItemIcon(outputImg, outputStack, itemAssetPathForStack(outputStack));
507
535
outputImg.alt = itemDisplayName(outputStack);
@@ -696,6 +724,7 @@ export function initCrafting ({
696
724
dyeColorKey = entry.colorKey;
697
725
dyeSlotIndex = entry.displayIndex;
698
726
closeDyePicker();
727
renderRecipeGrid();
699
728
renderDetail();
700
729
});
701
730
dyeGrid.append(cell);
@@ -1,6 +1,5 @@1
import1
import2
{2
{3
itemDefinition,4
itemDisplayName,3
itemDisplayName,5
itemAssetPathForStack,4
itemAssetPathForStack,6
formatQuantity,5
formatQuantity,@@ -130,6 +129,7 @@ export function initCrafting ({130
dyeClearBtn?.addEventListener("click", () =>129
dyeClearBtn?.addEventListener("click", () =>131
{130
{132
clearDyeSelection();131
clearDyeSelection();132
renderRecipeGrid();133
renderDetail();133
renderDetail();134
});134
});135
document.getElementById("dye-picker-close")?.addEventListener("click", () => closeDyePicker());135
document.getElementById("dye-picker-close")?.addEventListener("click", () => closeDyePicker());@@ -269,6 +269,17 @@ export function initCrafting ({269
function activeRecipe ()269
function activeRecipe ()270
{270
{271
const base = selectedRecipe();271
const base = selectedRecipe();272
if (!base)273
{ return null; }274
return resolveRecipePreview(base);275
}276
277
/**278
* Concrete recipe for UI previews (tailor templates → selected cloth + optional dye).279
* Other stations already carry the material-matched variant in the grid row.280
*/281
function resolveRecipePreview (base)282
{272
if (!base)283
if (!base)273
{ return null; }284
{ return null; }274
if (!base.tailorTemplate)285
if (!base.tailorTemplate)@@ -283,6 +294,17 @@ export function initCrafting ({283
return resolved.ok ? resolved.recipe : base;294
return resolved.ok ? resolved.recipe : base;284
}295
}285
296
297
function previewOutputStack (recipe)298
{299
if (!recipe?.output?.itemId)300
{ return null; }301
return {302
itemId: recipe.output.itemId,303
quantity: Math.max(1, recipe.output.quantity | 0 || 1),304
...(recipe.dyeColor ? { instance: { kind: "clothing", dyeColor: recipe.dyeColor } } : {})305
};306
}307
286
function refresh ()308
function refresh ()287
{309
{288
if (!open)310
if (!open)@@ -432,8 +454,9 @@ export function initCrafting ({432
454
433
function renderRecipeCell ({ group, recipe })455
function renderRecipeCell ({ group, recipe })434
{456
{435
const def = itemDefinition(recipe.output.itemId);457
const previewRecipe = resolveRecipePreview(recipe) ?? recipe;436
const stack = { itemId: recipe.output.itemId, quantity: recipe.output.quantity | 0 || 1 };458
const stack = previewOutputStack(previewRecipe)459
?? { itemId: recipe.output.itemId, quantity: recipe.output.quantity | 0 || 1 };437
const cell = document.createElement("button");460
const cell = document.createElement("button");438
cell.type = "button";461
cell.type = "button";439
cell.className = "craft-recipe-cell";462
cell.className = "craft-recipe-cell";@@ -444,24 +467,30 @@ export function initCrafting ({444
{ cell.classList.add("selected"); }467
{ cell.classList.add("selected"); }445
468
446
const skill = stationSkillLevel();469
const skill = stationSkillLevel();447
const minLevel = recipe.minSkillLevel | 0 || 1;470
const minLevel = previewRecipe.minSkillLevel | 0 || 1;448
if ((skill | 0) < minLevel)471
if ((skill | 0) < minLevel)449
{ cell.classList.add("level-locked"); }472
{ cell.classList.add("level-locked"); }450
else if (canStartCraft(getInventorySlots?.() ?? [], recipe, skill, dyeCraftOptions()))473
else if (canStartCraft(getInventorySlots?.() ?? [], previewRecipe, skill, dyeCraftOptions()))451
{ cell.classList.add("craftable"); }474
{ cell.classList.add("craftable"); }452
475
453
const img = document.createElement("img");476
const img = document.createElement("img");454
img.alt = def?.displayName ?? "Item";477
img.alt = itemDisplayName(stack);455
applyItemIcon(img, stack, itemAssetPathForStack(stack));478
applyItemIcon(img, stack, itemAssetPathForStack(stack));456
479
457
const label = document.createElement("span");480
const label = document.createElement("span");458
label.className = "craft-recipe-name";481
label.className = "craft-recipe-name";459
if (recipe.tailorTemplate)482
if (recipe.tailorTemplate)460
{ label.textContent = def?.displayName?.replace(/^Cotton\s+/i, "") ?? "Garment"; }483
{484
const name = itemDisplayName(stack);485
const clothPrefix = CLOTH_DISPLAY_NAME[previewRecipe.clothTier ?? selectedMaterial];486
label.textContent = (clothPrefix && name.startsWith(`${clothPrefix} `))487
? name.slice(clothPrefix.length + 1)488
: name.replace(/^Cotton\s+/i, "") || name;489
}461
else if (recipe.craftGroupLabel)490
else if (recipe.craftGroupLabel)462
{ label.textContent = recipe.craftGroupLabel; }491
{ label.textContent = recipe.craftGroupLabel; }463
else492
else464
{ label.textContent = def?.displayName ?? "Item"; }493
{ label.textContent = itemDisplayName(stack); }465
494
466
cell.append(img, label);495
cell.append(img, label);467
cell.addEventListener("click", () =>496
cell.addEventListener("click", () =>@@ -498,10 +527,9 @@ export function initCrafting ({498
detailEmpty.hidden = true;527
detailEmpty.hidden = true;499
detailBody.hidden = false;528
detailBody.hidden = false;500
529
501
const outputStack = {530
const outputStack = previewOutputStack(recipe) ?? {502
itemId: recipe.output.itemId,531
itemId: recipe.output.itemId,503
quantity: Math.max(1, recipe.output.quantity | 0 || 1),532
quantity: Math.max(1, recipe.output.quantity | 0 || 1)504
...(recipe.dyeColor ? { instance: { kind: "clothing", dyeColor: recipe.dyeColor } } : {})505
};533
};506
applyItemIcon(outputImg, outputStack, itemAssetPathForStack(outputStack));534
applyItemIcon(outputImg, outputStack, itemAssetPathForStack(outputStack));507
outputImg.alt = itemDisplayName(outputStack);535
outputImg.alt = itemDisplayName(outputStack);@@ -696,6 +724,7 @@ export function initCrafting ({696
dyeColorKey = entry.colorKey;724
dyeColorKey = entry.colorKey;697
dyeSlotIndex = entry.displayIndex;725
dyeSlotIndex = entry.displayIndex;698
closeDyePicker();726
closeDyePicker();727
renderRecipeGrid();699
renderDetail();728
renderDetail();700
});729
});701
dyeGrid.append(cell);730
dyeGrid.append(cell);